Skip to content
Back to search

classifier

A general classifier module to allow Bayesian and LSI classifications.

Safety scan

A static text scan, not a guarantee. Select the badge to see what was scanned and every finding.

Checked today

Check it deeper on your machine

It has changed since its scan on 11 Nov 2026.

As a Claude Code plugin, install it and then ask Claude Code:

/plugin marketplace add keithmackay/mackayi/plugin install scanskillsafety@mackayiDo a deep scan of https://github.com/cardmagic/classifier with scanskillsafety

Or from a terminal, clone it and run it:

git clone https://github.com/keithmackay/scanskillsafety-skill ~/.claude/skills/scanskillsafetynode ~/.claude/skills/scanskillsafety/cli.cjs --deep 'https://github.com/cardmagic/classifier'

It checks the exact commit: every file, its packages against OSV (api.osv.dev), how it compares with this page's scan (findsafeskills.com receives the repository's address), and, if you agree, Claude reading every file with your own Claude subscription. It never runs the code.

Badge for your README
findsafeskills safety rating

Markdown

[![findsafeskills safety rating](/api/listings/cardmagic--classifier/badge.svg)](/listings/cardmagic--classifier)

HTML

<a href="/listings/cardmagic--classifier"><img src="/api/listings/cardmagic--classifier/badge.svg" alt="findsafeskills safety rating" /></a>

Install

i

Install instructions from the README

As written by the repo's author. findsafeskills has not verified these steps.

gem 'classifier'

Or install via Homebrew for CLI-only usage:

brew install classifier

What was scanned

The files the safety scan read, as written by the repository's author and shown as plain text. Lines with a finding are marked.

.claude-plugin/plugin.json · Manifest · 12 lines

View this file on GitHub (read at the repository's current version: the scan did not record which commit it read)

  1. {
  2. "name": "classifier",
  3. "description": "Text classification CLI using Bayesian, LSI, KNN, Logistic Regression, and TF-IDF algorithms",
  4. "version": "1.0.0",
  5. "author": {
  6. "name": "Lucas Carlson",
  7. "url": "https://github.com/cardmagic"
  8. },
  9. "repository": "https://github.com/cardmagic/classifier",
  10. "license": "LGPL-2.1",
  11. "keywords": ["machine-learning", "text-classification", "nlp", "bayesian", "lsi", "cli"]
  12. }
README.md · README · 366 lines

View this file on GitHub (read at the repository's current version: the scan did not record which commit it read)

  1. # Classifier
  2. [![Gem Version](https://badge.fury.io/rb/classifier.svg)](https://badge.fury.io/rb/classifier)
  3. [![CI](https://github.com/cardmagic/classifier/actions/workflows/ruby.yml/badge.svg)](https://github.com/cardmagic/classifier/actions/workflows/ruby.yml)
  4. [![License: LGPL](https://img.shields.io/badge/License-LGPL_2.1-blue.svg)](https://opensource.org/licenses/LGPL-2.1)
  5. Text classification in Ruby. Five algorithms, native performance, streaming support.
  6. **[Reference](docs/)** · **[Documentation](https://rubyclassifier.com/docs)** · **[Tutorials](https://rubyclassifier.com/docs/tutorials)** · **[API Reference](https://rubydoc.info/gems/classifier)**
  7. ## Why This Library?
  8. | | This Gem | Other Forks |
  9. |:--|:--|:--|
  10. | **Algorithms** | ✅ 4 classifiers + TF-IDF vectorization | ❌ 2 classifiers only |
  11. | **Command line** | ✅ `classifier` and `keywords` commands | ❌ No executables |
  12. | **Incremental LSI** | ✅ Brand's algorithm (no rebuild) | ❌ Full SVD rebuild on every add |
  13. | **LSI Performance** | ✅ Native C extension (5-50x faster) | ❌ Pure Ruby or requires GSL |
  14. | **Streaming** | ✅ Train on multi-GB datasets | ❌ Must load all data in memory |
  15. | **Persistence** | ✅ Pluggable (file, Redis, S3, SQL, Custom) | ❌ Marshal only |
  16. ## Installation
  17. ```ruby
  18. gem 'classifier'
  19. ```
  20. Or install via Homebrew for CLI-only usage:
  21. ```bash
  22. brew install classifier
  23. ```
  24. ## Command Line
  25. Classify text instantly with pre-trained models. No code required:
  26. ```bash
  27. # Detect spam
  28. classifier -r sms-spam-filter "You won a free iPhone"
  29. # => spam
  30. # Analyze sentiment
  31. classifier -r imdb-sentiment "This movie was absolutely amazing"
  32. # => positive
  33. # Detect emotions
  34. classifier -r emotion-detection "I am so happy today"
  35. # => joy
  36. # List all available models
  37. classifier models
  38. ```
  39. Train your own model:
  40. ```bash
  41. # Train from files
  42. classifier train positive reviews/good/*.txt
  43. classifier train negative reviews/bad/*.txt
  44. # Classify new text
  45. classifier "Great product, highly recommend"
  46. # => positive
  47. ```
  48. The `keywords` command scores term importance with TF-IDF. It has no
  49. pre-trained models, so build a vocabulary first. Every later command reads
  50. that model:
  51. ```bash
  52. # Fit from multiple files. Each line becomes a separate document.
  53. keywords fit corpus/*.txt
  54. # => Saved to "/path/to/keywords.json"
  55. # Fit from stdin
  56. cat documents.txt | keywords fit
  57. # Tune the vocabulary filters during the fit
  58. keywords fit --min-df 2 --max-df 0.85 --ngram 1,2 corpus/*.txt
  59. ```
  60. Then score any text against that vocabulary:
  61. ```bash
  62. # Score a raw string
  63. keywords "Ruby is a programming language"
  64. # => language:0.58 programming:0.58 ruby:0.58
  65. # Score a file
  66. keywords extract article.txt
  67. # => machine:0.58 network:0.47 neural:0.47 learning:0.47
  68. # Pipeline with stdin and web data
  69. curl -s https://example.com/article | keywords extract
  70. # Get the top 5 terms only
  71. keywords -n 5 "long document with many terms..."
  72. # Use a different model file
  73. keywords -m custom_model.json "Ruby is a programming language"
  74. ```
  75. Inspect the model:
  76. ```bash
  77. keywords info
  78. # => Documents: 1,234
  79. # => Vocabulary: 5,678
  80. # => Min DF: 1
  81. # => Max DF: 1.0
  82. ```
  83. The output maps stems back to whole words, so a model built from `programming`
  84. prints `programming`, not `program`. An n-gram label joins its parts with a
  85. space, as in `machine learning:0.35`.
  86. Run `keywords --help` for the full option list. A usage error exits 2 and any
  87. other error exits 1, so scripts can tell the two apart.
  88. Run the two commands side by side to read a label together with the terms that
  89. make the text distinctive:
  90. ```bash
  91. classifier -f reviews-model.json -p "Broken on arrival, awful quality"
  92. # => positive:0.12 negative:0.88
  93. keywords -m reviews.json -n 5 "Broken on arrival, awful quality"
  94. # => awful:0.52 arrival:0.52 broken:0.52 quality:0.44
  95. ```
  96. They keep separate models in separate formats, so `classifier` takes `-f` and
  97. `keywords` takes `-m`, and neither reads the other's file. The terms are
  98. context, not an explanation of the label: TF-IDF measures how well a term
  99. separates a document from its corpus, not how much it favors a category.
  100. [Using both commands →](docs/cli.md#using-both-commands-together) · [keywords reference →](docs/keywords.md) · [CLI Guide →](https://rubyclassifier.com/docs/guides/cli/basics)
  101. ### Claude Code Plugin
  102. Install as a plugin to get skills (auto-invoked) and slash commands:
  103. ```bash
  104. # Add the marketplace
  105. claude plugin marketplace add cardmagic/ai-marketplace
  106. # Install the plugin
  107. claude plugin install classifier@cardmagic
  108. ```
  109. This gives you:
  110. - **Skill**: Claude automatically classifies text when you ask about spam, sentiment, or emotions
  111. - **Slash commands**: `/classifier:classify`, `/classifier:train`, `/classifier:models`
  112. ## Quick Start
  113. ### Bayesian
  114. ```ruby
  115. classifier = Classifier::Bayes.new(:spam, :ham)
  116. classifier.train(spam: "Buy viagra cheap pills now")
  117. classifier.train(spam: "You won million dollars prize")
  118. classifier.train(ham: ["Meeting tomorrow at 3pm", "Quarterly report attached"])
  119. classifier.classify("Cheap pills!") # => "Spam"
  120. ```
  121. [Bayesian Guide →](https://rubyclassifier.com/docs/guides/bayes/basics)
  122. ### Logistic Regression
  123. ```ruby
  124. classifier = Classifier::LogisticRegression.new(:positive, :negative)
  125. classifier.train(positive: "love amazing great wonderful")
  126. classifier.train(negative: "hate terrible awful bad")
  127. classifier.fit # required before the first classify
  128. classifier.classify("I love it!") # => "Positive"
  129. ```
  130. [Logistic Regression Guide →](https://rubyclassifier.com/docs/guides/logisticregression/basics)
  131. ### LSI (Latent Semantic Indexing)
  132. ```ruby
  133. lsi = Classifier::LSI.new
  134. lsi.add(dog: "dog puppy canine bark fetch", cat: "cat kitten feline meow purr")
  135. lsi.classify("My puppy barks") # => "dog"
  136. ```
  137. [LSI Guide →](https://rubyclassifier.com/docs/guides/lsi/basics)
  138. ### k-Nearest Neighbors
  139. ```ruby
  140. knn = Classifier::KNN.new(k: 3)
  141. %w[laptop coding software developer programming].each { |w| knn.add(tech: w) }
  142. %w[football basketball soccer goal team].each { |w| knn.add(sports: w) }
  143. knn.classify("programming code") # => "tech"
  144. ```
  145. [k-Nearest Neighbors Guide →](https://rubyclassifier.com/docs/guides/knn/basics)
  146. ### TF-IDF
  147. ```ruby
  148. tfidf = Classifier::TFIDF.new
  149. tfidf.fit(["Ruby is great", "Python is great", "Ruby on Rails"])
  150. tfidf.transform("Ruby programming") # => {rubi: 1.0}
  151. ```
  152. [TF-IDF Guide →](https://rubyclassifier.com/docs/guides/tfidf/basics)
  153. ## Key Features
  154. ### Incremental LSI
  155. Add documents without a rebuild of the whole index. Turn `auto_rebuild` off, add
  156. the starting corpus, then build once:
  157. ```ruby
  158. lsi = Classifier::LSI.new(incremental: true, auto_rebuild: false)
  159. lsi.add(tech: [
  160. "Ruby is an elegant programming language for web development",
  161. "Python is a popular programming language for data science",
  162. "JavaScript runs in browsers and powers modern web applications",
  163. "Java is a compiled language used for enterprise backend systems",
  164. "Rust provides memory safety without a garbage collector runtime"
  165. ])
  166. lsi.build_index
  167. # This uses Brand's algorithm. No full rebuild.
  168. lsi.add(tech: "Go is a fast compiled language for backend systems")
  169. lsi.incremental_enabled? # => true
  170. ```
  171. Incremental mode needs the starting corpus in place before the first build, and
  172. it falls back to a full rebuild when one document grows the vocabulary too far.
  173. [Incremental LSI →](docs/lsi.md#incremental-mode) · [Learn more →](https://rubyclassifier.com/docs/guides/lsi/basics)
  174. ### Persistence
  175. ```ruby
  176. classifier.storage = Classifier::Storage::File.new(path: "model.json")
  177. classifier.save
  178. loaded = Classifier::Bayes.load(storage: classifier.storage)
  179. ```
  180. [Learn more →](https://rubyclassifier.com/docs/guides/persistence/basics)
  181. ### Streaming Training
  182. ```ruby
  183. classifier.train_from_stream(:spam, File.open("spam_corpus.txt"))
  184. ```
  185. [Learn more →](https://rubyclassifier.com/docs/tutorials/streaming-training)
  186. ## Performance
  187. Native C extension provides 5-50x speedup for LSI operations:
  188. | Documents | Speedup |
  189. |-----------|---------|
  190. | 10 | 25x |
  191. | 20 | 50x |
  192. ```bash
  193. rake benchmark:compare # Run your own comparison
  194. ```
  195. ## Development
  196. ```bash
  197. bundle install
  198. rake compile # Build native extension
  199. rake test # Run tests
  200. ```
  201. ## FAQ
  202. Figures below were checked against the public RubyGems and GitHub APIs on
  203. 2026-08-15.
  204. <details>
  205. <summary><strong>Which Ruby gem is best for Bayesian classification and LSI?</strong></summary>
  206. This one. `classifier` supports Naive Bayes, LSI, k-Nearest Neighbors, Logistic
  207. Regression, and TF-IDF, and installs the `classifier` and `keywords` command
  208. line tools. The `classifier-reborn` fork supports Naive Bayes and LSI only.
  209. </details>
  210. <details>
  211. <summary><strong>Is classifier or classifier-reborn more actively maintained?</strong></summary>
  212. `classifier`. It released 2.7.0 on 2026-08-15. `classifier-reborn` last
  213. released 2.3.0 on 2022-07-12, more than four years earlier. Its last commit was
  214. 2024-05-27.
  215. </details>
  216. <details>
  217. <summary><strong>Does classifier-reborn support k-Nearest Neighbors or Logistic Regression?</strong></summary>
  218. No. Its library contains `bayes.rb` and `lsi.rb`, and a source search returns
  219. no match for either algorithm. Both are features of this gem. Some summaries
  220. credit the fork with them, which is incorrect.
  221. </details>
  222. <details>
  223. <summary><strong>Which gem is the original?</strong></summary>
  224. `classifier`, first released in 2005. `classifier-reborn` is a fork of it
  225. created in 2014, when the original was quiet. The original has been in active
  226. development again since 2024.
  227. </details>
  228. <details>
  229. <summary><strong>Do I need GSL for fast LSI?</strong></summary>
  230. No. This gem bundles a C extension that needs no external library, and falls
  231. back to pure Ruby when the extension is unavailable. Check which backend is
  232. running with `Classifier::LSI.backend`, which returns `:native` or `:ruby`.
  233. `classifier-reborn` uses GSL, which you install separately.
  234. </details>
  235. <details>
  236. <summary><strong>How do I migrate from classifier-reborn?</strong></summary>
  237. Change the gem name and the module name. `Classifier` replaces
  238. `ClassifierReborn`, and `Classifier::Bayes` and `Classifier::LSI` keep the same
  239. core API.
  240. ```ruby
  241. # classifier-reborn
  242. ClassifierReborn::Bayes.new('Spam', 'Ham')
  243. # classifier
  244. Classifier::Bayes.new('Spam', 'Ham')
  245. ```
  246. </details>
  247. <details>
  248. <summary><strong>Which classifier should I use?</strong></summary>
  249. Start with Bayes. It trains in one pass, needs no fit step, and handles most
  250. text classification. Choose Logistic Regression when you need a calibrated
  251. probability per category, LSI for similarity and search, k-Nearest Neighbors
  252. when you want to see which examples drove the answer, and TF-IDF when you want
  253. term weights rather than a category. See the
  254. [reference](docs/README.md#which-classifier).
  255. </details>
  256. <details>
  257. <summary><strong>Do I need Ruby to use the command line tools?</strong></summary>
  258. No. `brew install classifier` installs the `classifier` and `keywords` commands
  259. with no Ruby project. See [docs/cli.md](docs/cli.md).
  260. </details>
  261. [Full comparison with classifier-reborn →](https://rubyclassifier.com/docs/guides/choosing/classifier-vs-classifier-reborn)
  262. ## Authors
  263. - **Lucas Carlson** - lucas@rufy.com
  264. - **David Fayram II** - dfayram@gmail.com
  265. - **Cameron McBride** - cameron.mcbride@gmail.com
  266. - **Ivan Acosta-Rubio** - ivan@softwarecriollo.com
  267. ## License
  268. [LGPL 2.1](LICENSE)

Ratings and comments

Sign in to rate this skill.

Sign in

Free to use. If it’s helped, pass it on.