Notes

Count Vectorization

Before a classifier can do anything with a product review, the review has to become a row of numbers. Count vectorization is the most literal answer available: fix a vocabulary, then describe each document by how many times each vocabulary word occurs in it.

How the matrix is built
The process runs in two passes over the collection:

  • Fit — scan every document, collect the distinct tokens, and assign each one a column index. That is the vocabulary.
  • Transform — for each document, emit a vector whose entries are the raw occurrence counts for those columns.

Stacked, those vectors form the document-term matrix. It is overwhelmingly zeros, so libraries store it sparse — scikit-learn's CountVectorizer returns a SciPy sparse matrix and exposes the knobs you would otherwise hand-roll: lowercasing, stop-word lists, n-gram ranges, minimum document frequency.

Why it survives
Counts remain a strong baseline wherever the presence of particular words carries most of the signal — spam filtering, support-ticket routing, language identification. The representation is transparent: you can read a model coefficient, name the word behind it, and explain the decision to someone. Training is fast and needs no GPU.

What it throws away
Word order and syntax vanish, so “the dog bit the man” and “the man bit the dog” produce identical vectors. Raw counts reward length and common words, which is why TF-IDF reweighting usually follows. Anything outside the fitted vocabulary is silently dropped at transform time, so a newly launched product name is invisible to the model until you refit.

Count vectorization turns a document into a vector of raw term counts over a fixed vocabulary, producing the sparse document-term matrix that classical text models consume. It is the simplest bag-of-words encoding and the baseline that TF-IDF reweights. It matters because it makes text usable by any numeric learner at almost no computational cost, while discarding word order and ignoring every token outside the fitted vocabulary.

Imagine summarising a novel by tallying how often each word appears in it — 140 whale, 12 harpoon, 3 coffee — and writing the tallies on an index card. You lose the story completely, yet the card still tells you a great deal about what the book is about.

Count vectorization is software doing exactly that to a piece of text. It keeps a fixed list of words and records how many times each one shows up, turning the text into a row of numbers that a computer can compare, sort and learn from. It is how a spam filter notices that certain words keep turning up in junk mail, without understanding a single sentence it reads.