Bag-of-Words: Turn Word Counts into Document Vectors
How BoW represents text, what order it loses, and how to use it as a baseline.
Bag-of-Words (BoW) represents each document by token counts from a learned vocabulary: terms are feature columns and documents are rows. scikit-learn CountVectorizer handles tokenization, vocabulary fitting, and counting; its default analyzer lowercases and selects words of at least two characters. Unigram BoW preserves word presence and frequency but discards order, so a question and statement with the same words can share a vector. It is a simple, interpretable baseline when counts suffice; use n-grams when local order matters. The matrix is sparse because documents use only part of the vocabulary, and later transform ignores terms absent from training vocabulary. Fit on training data only, then reuse the same fitted vocabulary and preprocessing.