Command Line

Pre-trained models

Classify text with models from the classifier-models registry. First use downloads and caches; later runs are local.

Pre-trained models

Models are not bundled with the gem. The classifier command downloads them from a registry, caches them, and classifies text locally. The default registry is classifier-models. The live catalog, including each model’s license, is models.json.

The examples on this page were run against published classifier 2.7.0. For the rest of the CLI, see CLI Basics.

Classify with a registry model

classifier -r sms-spam-filter "You won a free iPhone"

On first use the command downloads the model, writes it to the cache, and then prints the label. With the default cache the Saved to path is $HOME/.classifier/models/sms-spam-filter.json:

Downloading sms-spam-filter from cardmagic/classifier-models...
Saved to $HOME/.classifier/models/sms-spam-filter.json
spam

A later run, when that file is already present, does not download again and prints only the label:

spam

Two other commands measured on the same 2.7.0 install:

classifier -r imdb-sentiment "This movie was absolutely amazing"
# => positive

classifier -r emotion-detection "I am so happy today"
# => joy

Those names are keys in the default registry. spam-filter is not a key; the spam model is sms-spam-filter.

List the registry

classifier models lists every model in the default registry. The descriptions are truncated by the CLI. The full descriptions, licenses, and dataset URLs are in models.json.

sms-spam-filter      SMS spam detection trained on UCI SMS Sp (bayes, 98KB)
imdb-sentiment       Movie review sentiment analysis (positiv (bayes, 2.1MB)
bbc-news             News article topic classification (5 cat (bayes, 492KB)
language-detection   Detect language of text (20 languages) (bayes, 4.2MB)
imdb-sentiment-lr    Movie review sentiment using Logistic Re (logistic_regression, 2.6MB)
imdb-sentiment-lsi   Movie review sentiment using LSI (semant (lsi, 778KB)
imdb-sentiment-knn   Movie review sentiment using kNN (interp (knn, 487KB)
ag-news              News topic classification (World, Sports (bayes, 1.5MB)
emotion-detection    Emotion classification (joy, love, sadne (bayes, 491KB)
toxic-comments       Toxic/offensive content detection (bayes, 260KB)
sms-spam-filter-lr   SMS spam detection using Logistic Regres (logistic_regression, 217KB)
bbc-news-lr          News topic classification using Logistic (logistic_regression, 1.4MB)
ag-news-lr           News topic classification using Logistic (logistic_regression, 683KB)
emotion-detection-lr Emotion classification using Logistic Re (logistic_regression, 604KB)
toxic-comments-lr    Toxic/offensive content detection using  (logistic_regression, 205KB)

classifier models --local lists models already in the cache.

To download a model without classifying text:

classifier pull sms-spam-filter

That command always fetches the model and prints the same Downloading / Saved to lines, even when a cached copy is already present.

Cache and registry

The default cache directory is ~/.classifier. Set CLASSIFIER_CACHE to use a different directory. Cached default-registry models are stored as $CLASSIFIER_CACHE/models/<name>.json, or $HOME/.classifier/models/<name>.json when CLASSIFIER_CACHE is unset.

The default registry is cardmagic/classifier-models. Set CLASSIFIER_REGISTRY to point the CLI at a different GitHub repo of the form owner/name. The -r option also accepts @owner/repo:name for a model in another public GitHub repo that has a models.json catalog.

Licenses

License and dataset information come from the catalog, not from the gem package. Check models.json before you use or redistribute a model.

For example, sms-spam-filter is listed there as CC BY 4.0, with its dataset URL pointing at the UCI SMS Spam Collection.

Next steps