Cadmium comes with two classifiers so far, a Classic Bayes classifier and a Viterbi classifier.
Those are probabalistic classifiers that, when trained with a data set, can classify words (or other tokens) according to categories.
-
Add the dependency to your
shard.yml
:dependencies: cadmium_classifier: github: cadmiumcr/classifier
-
Run
shards install
require "cadmium_classifier"
classifier = Cadmium::Classifier::Bayes.new
classifier.train("crystal is an awesome programming language", "programming")
classifier.train("ruby is nice, but not as fast as crystal", "programming")
classifier.train("my wife and I went to the beach", "off-topic")
classifier.train("my dog likes to go outside and play", "off-topic")
classifier.classify("Crystal is my favorite!")
# => "programming"
You can save the classifier as JSON as well
require "json"
json = classifier.to_json
File.write("classifier.json", json)
And load it again later
require "json"
json = File.open("classifier.json")
classifier = classifier.from_json(json)
- Fork it (https://github.com/cadmiumcr/classifier/fork)
- Create your feature branch (
git checkout -b my-new-feature
) - Commit your changes (
git commit -am 'Add some feature'
) - Push to the branch (
git push origin my-new-feature
) - Create a new Pull Request
- Chris Watson - creator and maintainer