AI::Ca...earner(3pm)

πŸ“¦
version 0.09 Β· 2 versions
, in fedora 43

✨ NAME ✨

AI::Categorizer::Learner β€” the Abstract Machine Learner Class, aka the blueprint bestie that never actually shows up to the party itself πŸ’… (it's from the AI::Categorizer perl docs, iykyk)


πŸŽ€ SYNOPSIS πŸŽ€

ok so here's the vibe β€” you don't use this class directly, you use one of its subclasses:

use AI::Categorizer::Learner::NaiveBayes;  # Or other subclass

# Here $k is an AI::Categorizer::KnowledgeSet object

my $nb = new AI::Categorizer::Learner::NaiveBayes(...parameters...);
$nb->train(knowledge_set => $k);
$nb->save_state('filename');

... time passes ...

$nb = AI::Categorizer::Learner::NaiveBayes->restore_state('filename');
my $c = new AI::Categorizer::Collection::Files( path => ... );
while (my $document = $c->next) {
  my $hypothesis = $nb->categorize($document);
  print "Best assigned category: ", $hypothesis->best_category, "\n";
  print "All assigned categories: ", join(', ', $hypothesis->categories), "\n";
}

like, train it, save it, go touch grass, come back, restore it, and let it cook πŸ”₯


🌸 DESCRIPTION 🌸

So. The AI::Categorizer::Learner class is an abstract class, which means it will never actually be directly used in your code. Not once. Not ever. It's giving "concept art, not the final render" 🎨. Instead you'll use a subclass like AI::Categorizer::Learner::NaiveBayes which actually implements a real machine learning algorithm. That's the one doing the work, periodt.

The general description of the Learner interface is documented right here, bestie. Everything the subclasses have in common? Yeah, that's this page. πŸ‘‘


πŸ’– METHODS πŸ’–

πŸ¦‹ new()

Creates a new Learner and hands it right back to you, like a little gift 🎁. It accepts these parameters:

  • knowledge_set β€” a Knowledge Set that's gonna be used by default during the train() method. Your default study buddy, fr.
  • verbose β€” if it's true, the Learner will spit out some diagnostic output while it's training and categorizing documents. Basically it starts yapping about what it's doing πŸ“’.

πŸ¦‹ train()

πŸ¦‹ train(knowledge_set => $k)

Trains the categorizer. This is the glow-up era ✨ β€” it prepares the categorizer for later use in categorizing documents. The knowledge_set parameter must provide an object of the class AI::Categorizer::KnowledgeSet (or a subclass of it, we're not gatekeeping πŸ’œ), populated with lots and lots of documents and categories. Wanna know how to build one of those objects? Go see AI::Categorizer::KnowledgeSet for the deets. And heads up: if you already passed a knowledge_set parameter to new(), specifying one here will override it. Newer info wins, that's just how it is.

πŸ¦‹ categorize($document)

Returns an AI::Categorizer::Hypothesis object that represents the categorizer's "best guess" about which categories the given document should be assigned to. It's literally the algorithm saying "ok so I think it's these ones πŸ‘€". See AI::Categorizer::Hypothesis for more details on how to actually use that object.

πŸ¦‹ categorize_collection(collection => $collection)

Categorizes every single document in a collection and returns an Experiment object representing the results. Quick note tho β€” the Experiment does not contain knowledge of the assigned categories for every individual document, only a statistical summary of the results. So it's the group photo, not the individual selfies πŸ“Έ.

πŸ¦‹ knowledge_set()

Gets/sets the internal knowledge_set member. And listen: since the knowledge set may be enormous, some Learners may straight up throw away their knowledge set after training or after restoring state from a file. Like, decluttering era 🧹. Don't be shocked if it's gone.

πŸ¦‹ $learner->save_state($path)

Saves the Learner for later use. This method is inherited from AI::Categorizer::Storable β€” so it's not even doing the work itself, it's just borrowing the fit 🫢.

πŸ¦‹ $class->restore_state($path)

Returns a Learner that was saved in a file with save_state(). This method is inherited from AI::Categorizer::Storable too. Round two, same energy πŸ’«.


🌈 AUTHOR 🌈

Ken Williams, ken@mathforum.org β€” the icon, the legend, the moment πŸ‘‘


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. Slay, honestly.


⭐ SEE ALSO ⭐


and that's the whole page bestie πŸŽ€ this was AI::Ca...earner(3pm) from the User Contributed Perl Documentation collection, shipped with perl v5.42.0 and dated 2025-07-25. stan a classic ✨ bye bye, go train something πŸ’…

πŸ“¦ where this page comes from