Level 0: Foundation
★☆☆☆☆ Introductory⏱ 5 minGeneral audience. No mathematics required.Two improvements on word vectors
GloVe builds word vectors from one big table of how often each pair of words appears together, fitting the vectors so that their dot products match the log counts. fastText builds a word’s vector from the vectors of its pieces: “rockets” is made of “roc”, “ock”, “cke” and so on. So it can make a sensible vector even for a word it has never seen, like a new inflection or a typo. The demo shows how vector directions can capture relationships.
Technical vocabularies are full of rare compounds, abbreviations and misspellings (“hydraulik”, “actr”). fastText-style subword vectors handle them gracefully, which matters for searching and classifying field reports.
- 1. GloVe fits vectors to…
- 2. fastText builds a word vector from…
- 3. For a never-seen word, fastText…
Level 1: Beginner
★★☆☆☆ Basic⏱ 20 minSecondary-school mathematics: arithmetic and elementary algebra.By hand
- GloVe objective: J = Σ_(X_ij > 0) f(X_ij) (w_i·c_j + b_i + b̃_j − log X_ij)², with f(x) = min((x/x_max)^0.75, 1), x_max = 100. Only non-zero cells are used; the final vector is often w + c.
- Motivation: ratios of co-occurrence probabilities (P(ice | solid)/P(steam | solid)) carry meaning, and a log-bilinear model turns ratios into vector differences.
- fastText: a word is represented by its character n-grams (n = 3–6) with boundary markers plus the whole word: for “where”,
<wh,whe,her,ere,re>and<where>. The word vector is the sum (or mean) of these, trained with skip-gram negative sampling. - Hashing: n-grams are hashed into about 2 million buckets to bound memory.
- OOV words: a vector is the combination of the word’s known n-gram vectors, useful for rare words, inflections and typos.
- 1. GloVe weight of a pair with count ≥ x_max:
- 2. Trigrams of `<where>`:
- 3. fastText limits memory by…
Level 2: Intermediate
★★★☆☆ Intermediate⏱ 25 minUndergraduate students and practising engineers.GloVe and fastText in code
Exercise 1.
- Implement GloVe’s weighting function and loss over non-zero counts.
- Extract fastText character n-grams with boundary markers.
Practice.
- Pretrained GloVe vectors (6B, 42B, 840B tokens) and fastText vectors for 157 languages are freely available.
fasttext.train_unsupervised(or Gensim’sFastText) trains subword embeddings;get_word_vectorworks for any string.- Prefer fastText for morphologically rich languages, noisy text and domains with many rare or compound terms.
- Contextual models have replaced static vectors in most tasks, but static vectors remain cheap, fast and robust baselines.
import fasttext
model = fasttext.train_unsupervised("logs.txt", model="skipgram", dim=100, minn=3, maxn=6)
print(model.get_word_vector("hydraulikpump")[:5]) # works for unseen or misspelt words
print(model.get_nearest_neighbors("actuatr"))- 1. A fastText method for vectors of any string:
- 2. fastText suits…
- 3. Pretrained GloVe vectors are…
Level 3: Advanced
★★★★☆ Advanced⏱ 25 minGraduate level, with full derivations and proofs.Theory
GloVe and zeros. GloVe’s loss includes only observed co-occurrences. Unlike skip-gram with negative sampling, it never learns explicitly that a word does not occur with some contexts. With large corpora the observed counts are informative enough; with sparse data they are noisy small integers, and GloVe can fail to separate meanings.
Relation to word2vec. Both approximate log co-occurrence statistics with dot products. GloVe uses global counts and weighted least squares; skip-gram streams over local windows. With tuned hyperparameters they perform similarly on standard benchmarks (Levy, Goldberg and Dagan, 2015).
Why subwords generalise. Forms sharing a stem share n-grams, so evidence from “launched” and “launching” flows into the n-grams of “launches”, even if it never appeared. This is parameter sharing across the vocabulary, the same idea as subword tokenisation (F2).
- 1. GloVe ignores…
- 2. Skip-gram learns from zeros via…
- 3. fastText generalises because related forms share…
Level 4: Expert
★★★★★ Expert⏱ 30 minResearchers: original papers and open problems.What do global counts and character n-grams add to word vectors?
History.
- J. Pennington, R. Socher and C. D. Manning, “GloVe: global vectors for word representation” (EMNLP 2014).
- P. Bojanowski, E. Grave, A. Joulin and T. Mikolov, “Enriching word vectors with subword information” (TACL 2017).
Exercise 2.
- World: 60 stems in 4 semantic classes, each with 6 forms (−, s, ed, ing, er, ly). 25% of the 360 forms (93 in seed 0) are held out of the corpus entirely.
- Corpus: 4000 sentences of a word form plus 4 context words (from its class’s pool with probability 0.6).
- Embeddings (16 dimensions):
- GloVe (AdaGrad, 200 epochs);
- word-level skip-gram with negative sampling;
- fastText-style skip-gram over character 3–5-grams.
- Task: a ridge classifier predicts the semantic class: of half the seen forms (trained on the other half), and of the held-out forms (trained on all seen forms).
| embedding | seen forms | held-out forms |
|---|---|---|
| GloVe | 0.694 | no vector |
| word-level skip-gram | 1.000 | no vector |
| fastText | 1.000 | 1.000 |
- Subwords solve OOV: word-level models have no vector for the 93 unseen forms, while fastText assembles one from n-grams shared with other forms of the same stem, and classifies all of them correctly.
- GloVe struggled on this small corpus: each form occurs about 15 times, so the non-zero counts GloVe fits are noisy, and it never sees the zeros that skip-gram’s negative samples exploit.
- Training GloVe longer made it worse (0.45 after 1000 epochs): it fits noise.
- A separate run with 20,000 sentences and no held-out forms gave GloVe 1.00. Its weakness here is sparsity, not the method.
- Seeds: seeds 1 and 2 gave GloVe 0.654/0.696 on seen forms; skip-gram and fastText were perfect, and fastText again classified every held-out form correctly.
GloVe and fastText in AI, robotics and aerospace
- Field reports: subword vectors match misspelt or abbreviated component names to the right concepts.
- Multilingual ground operations: fastText’s 157-language vectors give quick baselines.
- Design lesson: share parameters across related forms, and make sure the objective also learns from what does not co-occur.
References
- J. Pennington, R. Socher and C. D. Manning (2014). “GloVe: global vectors for word representation.” Proc. EMNLP.
- P. Bojanowski, E. Grave, A. Joulin and T. Mikolov (2017). “Enriching word vectors with subword information.” TACL 5.
- O. Levy, Y. Goldberg and I. Dagan (2015). “Improving distributional similarity with lessons learned from word embeddings.” TACL 3.