AI / NLP
GloVe from Scratch
Word Embeddings Trained on WikiText-2

About this project
GloVe word embeddings built from first principles: sparse co-occurrence matrix (120x smaller than dense), hand-derived gradients verified against autograd, and manual AdaGrad, with no autograd or torch.optim. Trained on WikiText-2 in 26 s on a 4 GB laptop GPU, with analogy tests, ablations and a comparison against official GloVe vectors.
The problem
Word embeddings are usually taken off the shelf. Building GloVe from first principles shows what the model actually optimises.
Approach
GloVe implemented by hand on WikiText-2: the co-occurrence matrix, the weighted least-squares objective, explicit gradients and AdaGrad. PyTorch is used only as a tensor and CUDA library, with no autograd and no pretrained vectors during training.
Results
Final training loss 0.0115 over 30 epochs in 26 seconds. The co-occurrence matrix is 99.72% sparse and 120 times smaller in memory. The GPU ran 4.93 times faster than CPU. On 16 word analogies, the custom model scored 18.75%, against 81.25% for the official glove.6B.100d vectors. I report that gap as measured.
- Category
- AI / NLP
- Built by
- Jeyadev R
- Source code
- github.com/jeyadev-jd/glove-wikitext2


