Notes

Word Embedding

Ask a program what king means and it has nothing to work with: a word is just an entry in a list, and in that list every entry sits equally far from every other. A word embedding replaces the entry with a few hundred numbers, placed so that words used in similar ways end up close together.

Meaning as a position
The numbers are learned from the company a word keeps. Read a large corpus, notice which words share neighbours, and nudge each word's coordinates until words appearing in similar contexts land in similar places — the distributional hypothesis turned into geometry. The result is dense and compact, typically 100 to 300 values per word, where a count vector needs tens of thousands of mostly-zero columns. Cosine similarity between two vectors then tracks how related the words are, and directions carry relationships: arithmetic on the vectors for Paris, France and Italy lands near Rome.

What it buys you
Embeddings let a model generalise to wording it never saw labelled:

  • a search box matches running shoes against a page that says trainers;
  • a sentiment classifier trained on reviews saying excellent copes with one saying superb;
  • documents cluster by topic without sharing a single exact keyword.

Pretrained vectors from Word2Vec, GloVe and FastText load straight out of gensim or spaCy.

Where it breaks
Each word gets exactly one vector, so the river and the finance senses of bank collapse into a blurred average. A word missing from training has no vector at all unless the scheme can fall back on subword pieces. And the geometry faithfully reproduces whatever associations the corpus held, prejudices included — which is the reason contextual embeddings followed.

A word embedding represents a word as a dense vector of real numbers, typically 100 to 300 dimensions, learned so that words appearing in similar contexts occupy nearby positions. It replaces sparse one-hot or count columns, in which every word is equally distant from every other, with a space where cosine similarity is a usable measure of relatedness. Downstream models can then generalise across synonyms and related terms they never saw in labelled data.

Imagine laying every word of a language out on an enormous map, where words used in the same sorts of sentences are placed near each other. Tea and coffee would be neighbours. Tea and bulldozer would be nowhere near.

A word embedding is that map, written as numbers so software can use it. Nobody draws it by hand. A program reads an enormous amount of text and works out where each word belongs from the company it keeps.

It matters because a computer handling plain words has no idea that trainers and running shoes are the same thing. Given the map, it can see the two sitting side by side, and treat them as the near-identical things they are.