A word is just a label
How could a computer ever know that chai is like coffee?
A new shopkeeper opens a stock register. He gives every item a code number: 1 is chai, 2 is coffee, 3 is a cricket bat.
Is 2 "closer" to 1 than 3 is? No. The numbers are just labels. They say nothing about what the items are. Chai and coffee are both hot drinks, but the register cannot know that.
A computer sees words the same way. To a computer, "chai" is just a label. Our job in this unit is to turn every word into numbers that carry its meaning.
First, what counts as a word? Before a computer can count anything, it cuts the text into pieces called tokens. Often everything is lower-cased first, so that "Chai" and "chai" count as one word. Punctuation becomes a token of its own. And we add two markers to every sentence: at the start and at the end. They mean "a sentence starts here" and "a sentence stops here", and §2 will need them. So I drink chai. becomes
<s> I drink chai . </s>
(We keep "I" as a capital so the examples read naturally.) Modern language models go one step further and cut rare words into smaller pieces; §16 shows how.
Now the simplest way to turn a word into numbers: give each word its own slot. Take a tiny vocabulary of three words — chai, coffee, cricket. Each word becomes a list of three numbers with a single 1 in its own slot:
A list of zeros with a single 1 is called a one-hot vector. With a real vocabulary of 50 000 words, each list is 50 000 numbers long: one 1 and 49 999 zeros.
Now measure how alike two words are, the way Unit 3 taught us: with the dot product. Multiply slot by slot and add:
Chai with cricket? Also 0. Every pair of different one-hot words has dot product 0: they all stand at right angles to each other. And every pair is the same distance apart: . In one-hot land, chai is exactly as far from coffee as it is from cricket.
A phone directory gives every person a line of their own. It tells you who exists, but not who lives near whom. One-hot lists are a directory: every word on its own line, every pair equally far apart, no neighbourhoods.
A city map is different. People who live near each other are drawn near each other, and a neighbourhood has a character — the market, the stadium, the station. We want a map of words: tea words in one neighbourhood, cricket words in another, so that on the map close means similar. This whole unit is about turning the directory into the map.
Why not just number the words 1, 2, 3, like the shopkeeper? Because that is worse than one-hot: it invents an order that isn't there. The computer would believe coffee (2) sits halfway between chai (1) and cricket (3), and that chai + cricket = 2 × coffee. One-hot at least tells no lies — it just tells nothing.
One-hot lists put every word at right angles to every other word, all the same distance apart. They tell words apart, but they cannot say "these two are alike". We want short lists where close means similar. The rest of this unit is about finding them.
With a vocabulary of 10 000 words written one-hot, what is the dot product of "chai" and "coffee", and how far apart are they?
The shopkeeper adds a fourth word, "tea", to the one-hot vocabulary. Which of the old words does tea land closest to?
If you want the algebra · 1 proof, step by step
Claim. For one-hot vectors and with : and , whatever the vocabulary size .
The road ahead. The unit has five acts.
- A word is just a label (§1) — the directory we start from.
- Guessing the next word by counting (§2–§4): a sentence as a chain of guesses, what to do about words never seen, and how to score a guesser by its surprise — its perplexity.
- Meaning from the company a word keeps (§5–§7): count the company, weigh it (TF-IDF and PMI), and squeeze it with the SVD from Unit 5.
- Stop counting, start predicting (§8–§14): word2vec's two games, CBOW and skip-gram; how to make them cheap; why counting and predicting arrive at the same answer; and a small neural language model.
- The geometry of meaning, and its limits (§15–§17): king − man + woman, words with two meanings, words cut into pieces, and the road to Units 17 and 18.
In one sentence: A one-hot list is a phone directory — every word on its own line, every pair at right angles and apart — so it names words but carries no meaning; we want a city map, where close means similar.
That was section 1. The rest of the unit opens when you unlock it.
16 more sections and the practice arena — 23 widgets, 43 checks and 16 solved problems in the whole unit (this preview had 1 widget and 2 checks).
- 2
A sentence is a chain of guesses
- 3
Never seen is not impossible: smoothing
- 4
How surprised is the model? Perplexity
- 5
You shall know a word by the company it keeps
- 6
Not all company counts: TF-IDF and PMI
- 7
Squeeze the table: the SVD finds friends of friends
- 8
From counting to predicting: the word2vec idea
- 9
CBOW: the committee fills in the blank
- 10
Skip-gram: one word guesses its neighbours
- 11
CBOW or skip-gram? Race them
- 12
Making it cheap: negative sampling, hierarchical softmax, subsampling
- 13
Why it works: counting and predicting meet
- 14
A neural language model
- 15
The geometry of meaning
- 16
What one vector per word gets wrong — and how pieces help
- 17
What to carry forward
- 18
Practice arena — sixteen problems, solved in full
Unlock this unit for ₹299, or all seven paid units for ₹999 — one-time payment, full refund within 7 days. See pricing.