liveBook · Manning

GloVe

As explained in Natural Language Processing in Action, Second Edition

GloVe is a word-embedding model that learns vector representations from global word co-occurrence statistics.

GloVe learns word vectors by directly optimizing global word co-occurrence statistics. It targets broadly shared word meanings, so the training corpus and intended users shape what the vectors represent. section 6.3.2 section 6.4

Instead of relying on neural-network backpropagation, GloVe counts co-occurrences in a square matrix and applies mature matrix-optimization methods related to singular value decomposition. This can reach useful representations efficiently, including with smaller corpora. section 6.4 section 6.4.1

Practical strengths include:

  • Faster training and better RAM/CPU efficiency for larger documents. section 6.4.1
  • More efficient use of data, helping models trained on smaller corpora. section 6.4.1
  • Higher accuracy for the same amount of training, according to the stated comparison. section 6.4.1

Initializing a CNN embedding layer

A text-classification pipeline can load pretrained 50-dimensional GloVe vectors, align them with its vocabulary, assign zero vectors to missing tokens, and initialize a PyTorch nn.Embedding layer. Setting freeze=False allows the vectors to adapt to the target corpus. section 7.4.3

>>> import spacy
>>>
>>> nlp = spacy.load("en_core_web_sm")
>>> text = "This is an example sentence."
>>> doc = nlp(text)
>>>
>>> for token in doc:
...    print(token.text, token.vector)

Inspect token vectors produced through spaCy, where the loaded language pipeline uses GloVe embeddings under the hood. section 6.4.1

How Natural Language Processing in Action, Second Edition covers it

How deep it goes
Explains global co-occurrence optimization, efficiency tradeoffs, and embedding initialization, but does not detail the full training algorithm.
Examples
Uses spaCy token vectors and a PyTorch CNN pipeline aligned to a 4,000-token vocabulary with 50-dimensional pretrained vectors.
What it assumes
Assumes basic word-embedding and NLP vocabulary knowledge while introducing corpus selection, co-occurrence statistics, and pretrained-vector alignment.
What you can do after
Apply it via spaCy or PyTorch by loading pretrained vectors, aligning vocabulary entries, and initializing an embedding layer.
How it connects
Connects word embeddings with Word2Vec, fastText, singular value decomposition, LSA, spaCy, PyTorch, and transfer learning.

Also explained in

Compare how 2 books explain GloVe →

Related concepts

This explainer was generated by Manning's knowledge graph from the text of Natural Language Processing in Action, Second Edition. The section links point to the parts of the book it draws on.