Localist (One-Hot) vs. Distributed Semantic Representations β’ Vector Space Models (VSM) β’ Term-Document & Term-Context Co-occurrence Matrices β’ Pointwise Mutual Information (PMI) & Positive PMI (PPMI) β’ TF-IDF Weighting Mechanics β’ Cosine Semantic Proximity Metric β’ Word2Vec Architectures: Continuous Bag of Words (CBOW) & Skip-Gram with Negative Sampling (SGNS) β’ Mathematical Derivation of Negative Sampling Objective β’ Hierarchical Softmax & Huffman Coding Trees β’ GloVe (Global Vectors for Word Representation) Log-Bilinear Least Squares Objective β’ FastText Subword Character N-gram Architecture β’ Intrinsic Evaluation (WordSim-353, SimLex-999, Word Vector Arithmetic Analogies) vs. Extrinsic Downstream Task Evaluation β’ 15 Solved University Examination Questions.
The foundational axiom of modern statistical semantics is Firth's (1957) Distributional Hypothesis: "You shall know a word by the company it keeps." Words occurring in identical linguistic contexts share similar semantic properties.
| Representation | Dimensionality & Geometry | Key Computational Limitation |
|---|---|---|
| One-Hot Encoding | Sparse $|V|$-dimensional binary vector with single 1 at word index (e.g., $[0, 0, 1, 0, \dots]^T$). | Orthogonal vectors: $\mathbf{x}_{\text{cat}}^T \mathbf{x}_{\text{dog}} = 0$. Zero inherent semantic similarity; massive curse of dimensionality. |
| Count-Based VSM (TF-IDF / PPMI) | Sparse, high-dimensional co-occurrence matrix transformed via statistical association metrics. | Requires SVD dimensionality reduction; computationally expensive $O(|V|^2)$ scaling. |
| Distributed Dense Embeddings (Word2Vec, GloVe) | Dense, low-dimensional real-valued vectors $\mathbb{R}^d$ ($d \in [100, 300]$). | Learned via self-supervised continuous neural optimization; captures geometric analogies ($\mathbf{v}_{\text{King}} - \mathbf{v}_{\text{Man}} + \mathbf{v}_{\text{Woman}} \approx \mathbf{v}_{\text{Queen}}$). |
Given word $w$ and context word $c$, Pointwise Mutual Information measures how much more often they co-occur than expected under random chance:
$$\mathbf{\text{PMI}(w, c) = \log_2 \frac{P(w, c)}{P(w)P(c)} = \log_2 \frac{C(w, c) \cdot N}{\sum_{c'} C(w, c') \sum_{w'} C(w', c)}}$$ $$\mathbf{\text{Positive PMI (PPMI): } \text{PPMI}(w, c) = \max(0, \text{PMI}(w, c))}$$Mikolov et al. (2013) proposed two complementary shallow two-layer neural architectures for learning dense word embeddings from large unannotated corpora:
Standard softmax requires computing $\sum_{w=1}^{|V|} \exp(\mathbf{v}'_w \cdot \mathbf{v}_c)$ across millions of vocabulary wordsβa prohibitive computational bottleneck. Negative Sampling re-frames multi-class classification as binary logistic regression:
$$\mathbf{\mathcal{L}_{\text{SGNS}}(\mathbf{\theta}) = \sum_{t=1}^T \sum_{-c \le j \le c, j \neq 0} \left[ \log \sigma(\mathbf{v}'_{w_{t+j}} \cdot \mathbf{v}_{w_t}) + \sum_{k=1}^K \mathbb{E}_{w_{n_k} \sim P_n(w)} \left[ \log \sigma(-\mathbf{v}'_{w_{n_k}} \cdot \mathbf{v}_{w_t}) \right] \right]}$$ $$\text{where } \sigma(z) = \frac{1}{1 + e^{-z}}, \quad \text{Noise Distribution: } P_n(w) = \frac{U(w)^{3/4}}{\sum_{w'} U(w')^{3/4}}$$The unigram exponent $3/4$ raises the relative sampling probability of rare words relative to ubiquitous stop words.
Pennington et al. (2014) combined the advantages of global matrix factorization and local context window methods. GloVe observes that semantic ratios of co-occurrence probabilities encode linguistic properties:
$$\mathbf{J = \sum_{i=1}^{|V|} \sum_{j=1}^{|V|} f(X_{ij}) \left( \mathbf{w}_i^T \mathbf{\tilde{w}}_j + b_i + \tilde{b}_j - \log X_{ij} \right)^2}$$ $$\text{Weighting Function: } f(x) = \begin{cases} (x / x_{\text{max}})^\alpha & \text{if } x < x_{\text{max}} \quad (\alpha = 0.75, x_{\text{max}} = 100) \\ 1 & \text{otherwise} \end{cases}$$Bojanowski et al. (2017) extended Skip-Gram by representing each word $w$ as a set of character n-grams bounded by `<` and `>`:
$$\text{For word } \text{"where"} \ (n=3): \ \{\text{This enables FastText to compute robust vector representations for Out-Of-Vocabulary (OOV) words (e.g., misspelled words or rare biomedical terms) by summing the learned vectors of their constituent subword n-grams!
For a single center word $c$ and true context word $o$ with $K$ negative samples $\{n_1, \dots, n_K\}$ drawn from $P_n(w)$:
$$\mathbf{\mathcal{L} = \log \sigma(\mathbf{u}_o^T \mathbf{v}_c) + \sum_{k=1}^K \log \sigma(-\mathbf{u}_{n_k}^T \mathbf{v}_c)}$$Recall that $\sigma'(z) = \sigma(z)(1 - \sigma(z))$ and $\frac{d}{dz}\log \sigma(z) = 1 - \sigma(z)$, while $\frac{d}{dz}\log \sigma(-z) = -\sigma(z)$.
1. Gradient with respect to true context vector $\mathbf{u}_o$:
$$\mathbf{\frac{\partial \mathcal{L}}{\partial \mathbf{u}_o} = (1 - \sigma(\mathbf{u}_o^T \mathbf{v}_c)) \mathbf{v}_c}$$2. Gradient with respect to negative context vector $\mathbf{u}_{n_k}$:
$$\mathbf{\frac{\partial \mathcal{L}}{\partial \mathbf{u}_{n_k}} = -\sigma(\mathbf{u}_{n_k}^T \mathbf{v}_c) \mathbf{v}_c}$$3. Gradient with respect to center word vector $\mathbf{v}_c$:
$$\mathbf{\frac{\partial \mathcal{L}}{\partial \mathbf{v}_c} = (1 - \sigma(\mathbf{u}_o^T \mathbf{v}_c)) \mathbf{u}_o - \sum_{k=1}^K \sigma(\mathbf{u}_{n_k}^T \mathbf{v}_c) \mathbf{u}_{n_k}}$$Interpretation: Gradient descent pushes the center vector $\mathbf{v}_c$ towards the true context vector $\mathbf{u}_o$ while repelling it away from all $K$ negative samples simultaneously!
LSA (Deerwester et al. 1990) factorizes a Term-Document co-occurrence matrix $\mathbf{X} \in \mathbb{R}^{|V| \times |D|}$ using Singular Value Decomposition:
$$\mathbf{\mathbf{X} \approx \mathbf{U}_k \mathbf{\Sigma}_k \mathbf{V}_k^T}$$Consider a 3x3 word-context co-occurrence matrix from a mini-corpus ($N = 100$ total co-occurrences):
| Target \ Context | `computer` | `data` | `pie` | Row Sum $C(w)$ |
|---|---|---|---|---|
| `digital` | 20 | 15 | 0 | 35 |
| `cherry` | 0 | 0 | 25 | 25 |
| `information` | 10 | 30 | 0 | 40 |
| Col Sum $C(c)$ | 30 | 45 | 25 | $\mathbf{N = 100}$ |
1. Compute PMI(`digital`, `computer`):
$$P(\text{digital}, \text{computer}) = \frac{20}{100} = 0.20 \qquad P(\text{digital}) = \frac{35}{100} = 0.35 \qquad P(\text{computer}) = \frac{30}{100} = 0.30$$ $$\mathbf{\text{PMI} = \log_2 \left( \frac{0.20}{0.35 \times 0.30} \right) = \log_2 \left( \frac{0.20}{0.105} \right) = \log_2(1.9048) = \mathbf{+0.9296}}$$2. Compute PMI(`digital`, `pie`) with Zero Count:
$$\text{PMI} = \log_2(0) = -\infty \implies \mathbf{\text{PPMI}(\text{digital}, \text{pie}) = \max(0, -\infty) = \mathbf{0.0000}}$$In CBOW, let context words be $\{w_1, \dots, w_{2C}\}$ and true target center word be $w_t$ ($j^*$).
| Dimension | Static Embeddings (Word2Vec / GloVe) | Contextualized Embeddings (ELMo / BERT) |
|---|---|---|
| Polysemy | Single fixed vector per word; `bank` in "river bank" and "financial bank" have identical representations. | Dynamic vector computed as a function of the entire sentence; `bank` has distinct embeddings in different contexts. |
| Lookup | Fast static matrix row lookup $O(1)$. | Requires deep multi-layer transformer forward pass. |
| Syntax Integration | Captures only local bag-of-words co-occurrence. | Encodes deep syntactic hierarchical dependency structures and semantic roles. |
Let $P_{ik} = P(k \mid i) = \frac{X_{ik}}{X_i}$ be the conditional probability of context word $k$ given word $i$. Consider probe word $k = \text{"solid"}$ with $i = \text{"ice"}$ and $j = \text{"steam"}$:
Prove why the unigram distribution raised to the $3/4$ power ($P_n(w) \propto U(w)^{0.75}$) balances frequent and rare negative word sampling:
Given 5 word pairs with human similarity rankings $H = [1, 2, 3, 4, 5]$ and model cosine similarity rankings $M = [1, 3, 2, 5, 4]$:
For training corpus of $T$ words, vocabulary size $|V|$, embedding dimension $d$, and context window size $C$:
Levy & Goldberg (2014) proved that Word2Vec Skip-Gram with Negative Sampling (SGNS) is implicitly factorizing a shifted Pointwise Mutual Information matrix:
$$\mathbf{\mathbf{W} \mathbf{C}^T = \mathbf{M}^{\text{PMI}} - \log(K) \quad \text{where } M_{ij}^{\text{PMI}} = \text{PMI}(w_i, c_j) = \log \frac{P(w_i, c_j)}{P(w_i)P(c_j)}}$$Where $K$ is the number of negative samples! Bridges neural embeddings directly with classical distributional co-occurrence matrices!
The weighting function $f(X_{ij}) = (X_{ij} / 100)^{0.75}$ ensures that extremely frequent stopwords do not dominate the weighted least squares objective while rare co-occurrences are not completely neglected.
Given word $w = \text{"cat"}$ ($n=3$): Subwords = $\{\text{
In a collection of $N = 10,000$ scientific documents, term $t = \text{"transformer"}$ appears $15$ times in a 300-word document $D_1$, and occurs in $100$ total documents across the corpus:
$$\text{TF}(t, D_1) = \frac{15}{300} = \mathbf{0.05} \qquad \text{IDF}(t) = \log_{10}\left( \frac{10,000}{100} \right) = \log_{10}(100) = \mathbf{2.0}$$ $$\mathbf{\text{TF-IDF}(t, D_1) = 0.05 \times 2.0 = \mathbf{0.1000}}$$In a 4-word vocabulary $V = \{\text{the}, \text{cat}, \text{sat}, \text{mat}\}$ structured as a balanced binary tree:
Word Mover's Distance (Kusner et al. 2015) measures the minimum cumulative semantic distance required to transport the embedded word vectors of sentence $S_1$ to sentence $S_2$ via optimal transport linear programming!
Prove that computing binary logistic loss on $K=5$ negative samples reduces GPU gradient backpropagation time by $\mathbf{99.995\%}$ compared to full vocabulary softmax ($|V| = 100,000$)!
In sentence $S_1 = \text{"The bank riverbed was eroded"}$ vs $S_2 = \text{"The bank approved the loan"}$, trace how self-attention dynamically projects the token `bank` into divergent subspace coordinates!
CBOW averages context embeddings, smoothing out stochastic noise and converging in $3\times$ fewer epochs on large dense corpora. Skip-Gram treats each (target, context) pair independently, giving rare words repeated training updates!
Show that when $X_{ij} \ge x_{\text{max}} = 100$, $f(X_{ij}) = 1.0$ caps the loss contribution, preventing extremely frequent pairs like `(of, the)` from warping semantic distances!
Show that averaging context words $\mathbf{h} = \frac{1}{2C}\sum \mathbf{v}_{w_{t+j}}$ distributes the output error gradient equally across all active context window representations $\frac{\partial \mathcal{L}}{\partial \mathbf{v}_c} = \frac{1}{2C}\mathbf{e}_{\text{output}}$!
Prove that in a well-trained 300D GloVe embedding space, the gender direction $\mathbf{g} = \mathbf{v}_{\text{woman}} - \mathbf{v}_{\text{man}}$ is approximately orthogonal to the grammatical tense direction $\mathbf{t} = \mathbf{v}_{\text{walked}} - \mathbf{v}_{\text{walk}}$: $\mathbf{g}^T \mathbf{t} \approx 0.012$, proving modular disentanglement of semantic and syntactic features!
Angular distance $d_\theta(\mathbf{u}, \mathbf{v}) = \frac{\arccos(\cos(\mathbf{u}, \mathbf{v}))}{\pi}$ satisfies all metric space axioms (including the Triangle Inequality), unlike raw cosine distance ($1 - \cos(\mathbf{u}, \mathbf{v})$) which is a semi-metric!
Show that subtracting $\mathbf{v}_{\text{man}}$ removes gender attributes from the masculine subspace while retaining royalty features: $\mathbf{v}_{\text{king}} - \mathbf{v}_{\text{man}} \approx \mathbf{v}_{\text{royalty}}$, which upon adding $\mathbf{v}_{\text{woman}}$ lands precisely in the feminine royal semantic neighborhood of $\mathbf{v}_{\text{queen}}$!
For unseen neologism "biocomputational": Word2Vec assigns random `
On the Google Analogy Test Set (19,544 questions across syntactic and semantic categories), Skip-Gram with Negative Sampling ($d=300$) achieves $\mathbf{74.2\%}$ accuracy, outperforming classical LSA by over $45\%$!
The gradient of GloVe loss $J$ with respect to target word vector $\mathbf{w}_i$ is: $\frac{\partial J}{\partial \mathbf{w}_i} = 2 \sum_{j=1}^{|V|} f(X_{ij}) (\mathbf{w}_i^T \mathbf{\tilde{w}}_j + b_i + \tilde{b}_j - \ln X_{ij}) \mathbf{\tilde{w}}_j$.
Show that with bucket size $B = 2 \times 10^6$ and $N = 3 \times 10^5$ distinct n-grams, the expected collision rate $\frac{N(N-1)}{2B} \approx 0.0225$ has near-zero impact on semantic retrieval accuracy!
Standard PMI is heavily biased towards low-frequency words. Positive PMI with frequency exponent $\alpha = 0.75$ ($\text{PPMI}_\alpha(w, c) = \max(0, \log_2 \frac{P(w, c)}{P(w)P_\alpha(c)})$) raises context distribution to $0.75$, mitigating rare word inflation!
In LSA, singular values $\sigma_1, \dots, \sigma_k$ exhibit exponential power-law decay ($\sigma_i \propto i^{-\alpha}$), proving that retaining top $k=300$ singular vectors captures $> 90\%$ of semantic information variance!
Calculating full softmax denominator $\sum_{w=1}^{|V|} \exp(\mathbf{u}_w^T \mathbf{v}_c)$ requires iterating over all 100,000 words per training token, demanding billions of GPU floating point operations per sentence!
Show that cosine similarity between two unit-normalized word vectors equals their inner product $\cos(\mathbf{u}, \mathbf{v}) = \langle \mathbf{u}, \mathbf{v} \rangle$, converting vector search into blazing-fast matrix-vector multiplication!
For unseen medical neologism "neurocomputational": FastText decomposes into subwords $\{\text{