Document-Term Matrix
Spread a thousand customer reviews out as a spreadsheet: one row per review, one column for every distinct word anybody used, and in each cell a count. That grid is a document-term matrix, and it is the oldest trick for getting text into a form a numerical model will accept.
What the grid actually holds
Rows are documents, columns are vocabulary entries, and cells hold whatever weighting you chose — raw term frequency, a binary present/absent flag, or TF-IDF values. Two properties dominate everything you do with it:
- It is enormous and almost empty. Fifty thousand columns is ordinary, and a single review touches perhaps thirty of them, so the matrix is held in a sparse structure — what sits under scikit-learn's CountVectorizer.
- Word order is gone. “the dog bit the man” and “the man bit the dog” produce identical rows, which is the bag-of-words assumption stated as a data structure.
Where it is used
Classical text pipelines run directly on it: Naive Bayes spam filters, logistic-regression sentiment models, keyword search scored with BM25, and the topic models and LSA factorisations that decompose the matrix to expose latent structure. It remains a strong baseline — on a modest review corpus, a TF-IDF matrix plus a linear classifier is hard to beat and trains in seconds.
Why it matters
It is the hinge between text and linear algebra. Every choice made during tokenisation and normalisation shows up here as a column, so a leaky cleaning step becomes thousands of near-duplicate columns, and a vocabulary pruned too hard throws away the only evidence the classifier had.
A document-term matrix is a table with one row per document and one column per vocabulary term, each cell holding that term's weight in that document — a raw count, a binary flag, or a TF-IDF value. It is the standard numerical form of a text collection and the input to classical classifiers, keyword retrieval and topic models. Being sparse and order-free, it discards word sequence entirely.
Think of a library where someone has made one huge checklist. Every book gets a row, every word in the language gets a column, and each box says how many times that word appears in that book.
That checklist is a document-term matrix. It is how software turns a pile of writing into numbers, because numbers are the only thing a program can compare, sort and add up. Most of the boxes are zeros — a short review uses a few dozen words out of tens of thousands — so computers store only the boxes that are filled. The catch is that the order of the words is lost. “Dog bites man” and “man bites dog” end up looking the same.