Lexical & Vector Semantics: TF-IDF, BM25, Word2Vec (Skip-Gram / CBOW) & GloVe
Sparse Bag-of-Words vs TF-IDF & Okapi BM25 saturation, Cosine Similarity invariance, Word2Vec CBOW vs Skip-Gram with Negative Sampling (SGNS), and vector analogy arithmetic.
1. Sparse Representations: BoW, TF-IDF & Okapi BM25
- Bag-of-Words (BoW): Document vector in ; loses word order, high-dimensional (), orthogonal one-hot word vectors ( even for "hotel" and "motel"!).
- TF-IDF: Multiplies local Term Frequency (often sublinear ) by global Inverse Document Frequency so rare discriminative terms outweigh ubiquitous words.
- Okapi BM25 (Modern IR & RAG Lexical Baseline): Adds term-frequency saturation (: seeing a query word times isn't more relevant than times) and document-length normalization ().
2. Dense Static Word Embeddings: Word2Vec & GloVe
Grounded in the Distributional Hypothesis ("You shall know a word by the company it keeps" β Firth, 1957), Word2Vec learns dense low-dimensional embeddings via self-supervised sliding windows:
| Model Variant | Prediction Task | Speed & Strengths |
|---|---|---|
| CBOW (Continuous Bag-of-Words) | Predicts center word from averaged surrounding window | Faster to train; slightly better on frequent words |
| Skip-Gram | Predicts each context word () given center word | Superior representations for rare words & morphological analogies |
| FastText | Represents each word as sum of character -grams (e.g. <wh, whe, her, ere, re>) | Handles Out-of-Vocabulary (OOV) words & rich morphology! |
| GloVe | Factorizes log global word-word co-occurrence matrix | Combines global matrix statistics + local context geometry |
Static vs Contextual Embeddings (Polysemy Limitation): Word2Vec and GloVe assign one single static vector per word type β "river bank" and "savings bank" receive the exact same vector! Contextual encoders (ELMo, BERT, GPT) compute dynamic token vectors conditioned on the entire sentence.
Practice Questions on This Chapter (2)
In a collection of documents, the word "the" appears at least once in every single document (). Using standard without smoothing, what is the TF-IDF weight of "the" in document ?
Which embedding architecture represents each word as a bag of character -grams, enabling it to generate meaningful vectors for unseen Out-of-Vocabulary (OOV) words at inference time?