AI::Ca...lector(3pm)
π AI::Categorizer::FeatureSelector π
okay bestie, so this is a page from the perl manual (the User Contributed Perl Documentation corner of the internet, specifically) and it's giving deeply abstract vibes, so buckle up π¦
β¨ NAME β¨
AI::Categorizer::FeatureSelector β the Abstract Feature Selection class. that's it, that's the name, it's abstract, it's a vibe, no cap.
β¨ SYNOPSIS β¨
...
yeah. that's literally the whole synopsis. it's abstract, babes. the ... is doing all the heavy lifting π
β¨ DESCRIPTION β¨
so the KnowledgeSet class is the one that gives you an interface to a set of documents, a set of categories, and the mapping between the two. and like, a ton of the parameters that control how documents get processed? all managed by KnowledgeSet. it's the main character fr fr π
β¨ METHODS β¨
new()β makes you a brand newKnowledgeSetand hands it over π it accepts these parameters:loadβ if there's aloadparameter hanging around, theload()method gets invoked immediately, no waiting. if thatloadparameter is a string, it gets passed as thepathparameter toload(). if it's a hash reference, then it represents all the parameters to hand toload().categoriesβ optional, a reference to an array of Category objects representing the complete set of categories in aKnowledgeSet. if you use it, you should also specify thedocumentsparameter (they're a package deal, bestie π«Ά).documentsβ optional, a reference to an array of Document objects representing the complete set of documents in aKnowledgeSet. if you use it, you should also specify thecategoriesparameter.features_keptβ a number telling us how many features (aka words) to consider when training the Learner or categorizing new documents. it can be:- a positive integer (like
2000) = the absolute number of features to keep - a decimal between 0 and 1 (like
0.2) = the fraction of the total number of features to keep - or
0= do no feature selection at all, just use the entire set of features
- a positive integer (like
the default is 0.2. slay.
feature_selectionβ a string saying what type of feature selection to do. rn the only option is also the default option:"document_frequency". iconic behaviour tbh.tfidf_weightingβ specifies how document word counts get converted into vector values β¨ it uses the three-character specification strings from Salton & Buckley's paper "Term-weighting approaches in automatic text retrieval". those three characters represent the three factors that get multiplied for each feature to find that feature's final vector value. the default weighting is"xxx".- the first character = the "term frequency" component. it can be:
bβ Binary weighting β1for terms present in a document,0for terms absent.tβ Raw term frequency β equal to the number of times a feature occurs in the document.xβ a synonym for't'.nβ Normalized term frequency β0.5 + 0.5 * t/max(t). same as the't'specification, but with term frequency normalized so it lies between0.5and1.
- the second character = the "collection frequency" component. it can be:
fβ Inverse document frequency β multiply term"t"'s value bylog(N/n), where"N"is the total number of documents in the collection, and"n"is the number of documents in which term"t"is found.pβ Probabilistic inverse document frequency β multiply term"t"'s value by"log((N-n)/n)"(same variable meanings as above).xβ No change β multiply by1.
- the third character = the "normalization" component. it can be:
cβ Apply cosine normalization β multiply by1/length(document_vector).xβ No change β multiply by1.
- the first character = the "term frequency" component. it can be:
and bestie, you can alternatively specify those three components with the term_weighting, collection_weighting, and normalize_weighting parameters respectively π
verboseβ if you set it to a true value, some status/debugging info gets output onSTDOUT. eyes on the screen, girlie π
categories()β in a list context it returns a list of all the Category objects in thisKnowledgeSet. in a scalar context it returns the number of such objects. context is everything, periodt.documents()β in a list context it returns a list of all the Document objects in thisKnowledgeSet. in a scalar context it returns the number of such objects.document()β give it a document name and it returns the Document object with that name, orundefif no such Document object exists in thisKnowledgeSet. (not me crying overundefπ)features()β returns a FeatureSet object representing the features of all the documents in thisKnowledgeSet.verbose()β returns theverboseparameter of thisKnowledgeSet, or sets it if you pass an optional argument. flexible queen πscan_stats()β scans all the documents of a Collection and returns a hash reference containing several statistics about the Collection. (XXX need to describe statsβ yeah, that's a note-to-self that lives in the original, so it lives here too, i don't make the rules π)scan_features()β this one scans through a Collection object and figures out the"best"features (words) to use when loading documents and training the Learner. this whole process is called "feature selection" and it's a very important part of categorization. like, genuinely central.
the Collection object should be specified as a collection parameter, or by just giving the arguments to pass to the Collection's new() method.
the whole feature selection process is governed by the feature_selection and features_kept parameters you gave to the KnowledgeSet's new() method.
this method returns the features as a FeatureVector whose values are the "quality" of each feature, by whatever measure the feature_selection parameter specifies. normally you won't need to use the return value, because this FeatureVector becomes the use_features parameter of any Document objects created by this KnowledgeSet. it's giving behind-the-scenes icon πΈ
save_features()β give it the name of a file and this method writes the features (as determined by thescan_featuresmethod) to that file. save it, don't lose it πrestore_features()β give it the name of a file written bysave_features, and it loads the features from that file and passes them as theuse_featuresparameter for any Document objects created in the future by thisKnowledgeSet. the comeback era πread()β iterates through a Collection of documents and adds them to theKnowledgeSet. the Collection can be specified with acollectionparameter β otherwise, just specify the arguments to pass to thenew()method of the Collection class.load()β this method can do feature selection and load a Collection in one step (though it currently uses two steps internally, sneaky little two-stepper π§).add_document()β give it a Document object as an argument and it adds that document, plus any categories it belongs to, to theKnowledgeSet.make_document()β this creates a Document object with the given data and then callsadd_document()to add it to theKnowledgeSet. acategoriesparameter should specify an array reference containing a list of categories by name β those are the categories the document belongs to. any other parameters get passed along to the Document class'snew()method.finish()β this gets called prior to training the Learner. its whole purpose is to perform any operations (like feature vector weighting) that might need to examine the entireKnowledgeSet. it's the "look at the big picture before we go" moment πweigh_features()β called duringfinish()to adjust the weights of the features according to thetfidf_weightingparameter. it's giving math with drama βdocument_frequency()β give it a single feature (word) as an argument and it returns the number of documents in theKnowledgeSetthat contain that feature.partition()β divides theKnowledgeSetinto several subsets. super useful for cross-validation, ngl. the relative sizes of the subsets get passed as arguments. for example, to split theKnowledgeSetinto fourKnowledgeSets of equal size, pass the arguments.25,.25,.25(the final size is1minus the sum of the other sizes). the partitions come back as a list. divide and conquer, bestie β¨
β¨ AUTHOR β¨
Ken Williams, ken@mathforum.org β shoutout to Ken, the og π«Ά
β¨ COPYRIGHT β¨
Copyright 2000-2003 Ken Williams. All rights reserved.
This library is free software; you can redistribute it and/or modify it under the same terms as Perl itself.
β¨ SEE ALSO β¨
and that's the whole page, bestie!! π this was AI::Ca...lector(3pm), living inside perl v5.42.0, dated 2025-07-25. go forth and select your features wisely π¦ππΈ
π¦ where this page comes from
- fedora 43: perl-AI-Categorizer 0.09-38.fc43 Β· GPL-1.0-or-later OR Artistic-1.0-Perl
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash on : a language model's rewrite of the original, under its terms