XP: 0
Part B · Module 4

Words as Numbers

A network only understands vectors. We turned images into vectors — now how do we turn words into them? The answer, word2vec, places every word on a giant map of meaning, where you can literally do math with words.
The problem

How do you turn a word into numbers?

NLP (Natural Language Processing) is the field of AI that lets computers understand and generate human language — chatbots, translation, sentiment analysis. But there's a catch we already know: a neural network only works on vectors. An image was easy (pixels are already numbers). A word like "king" isn't. So how?

The same trick as images

Recall Module 1: we flattened a picture into a vector. Words need the same treatment — each word must become a fixed-length, multi-dimensional vector. The breakthrough method was word2vec: it uses a neural network to learn a vector for every word that captures its meaning (its "sentiment" / semantics).

The core idea

Each number captures a property of meaning

Here's the intuition (simplified). Imagine each slot in a word's vector stands for some property. For the word "king," one dimension might mean Royalness, another Masculine/Feminine, another Plural. The values say how much of each property the word has.

Layman example — a dating profile

Think of each word's vector as a personality profile made of sliders: how royal, how masculine, how young, how powerful… "King" scores high on royalty and masculinity; "Queen" high on royalty but feminine; "Boy" low royalty, masculine, young. Words with similar profiles end up as neighbours on the map — just like people with similar profiles get matched. The computer learns these sliders automatically from reading tons of text.

Honest caveat

In reality the dimensions are not human-readable — a real word2vec vector has hundreds of dimensions, and you usually can't tell which one means "royalness." We label them here only to build intuition. The network discovers whatever properties are useful, even if we can't name them.

🎮 Playground 1

Inspect a word's meaning-vector

Click a word and see its (illustrative) property vector. Notice how King and Queen share high "Royalness" but flip on "Gender" — that shared structure is exactly what makes word-math work.

Word → property vector
Pick a word to reveal its meaning across dimensions.
The famous result

King − Man + Woman = Queen

Because words are points on a map of meaning, you can do arithmetic with them. Take the vector for King, subtract Man (this removes the "maleness" from the concept of royalty), then add Woman. The point you land on is closest to… Queen.

KingMan + WomanQueen
remove "male", add "female" — royalty stays, gender flips
Layman example — the recipe swap

It's like adjusting a recipe. Start with a beef burger, remove the beef, add chicken → you get a chicken burger. Everything else (the bun, the "burger-ness") stays; you only swapped one ingredient. Word-math does the same with meaning: keep "royalty," swap "male" for "female," and King becomes Queen. The direction from Man→Woman is the same as King→Queen — that parallel is what the network learned.

🎮 Playground 2

Do word-math on the meaning map

Pick a classic analogy, press Compute, and watch two arrows appear on the map. The orange arrow is the "difference" you're applying (e.g. Man→Woman = "make it female"). The teal arrow applies that same movement to the other word — landing you on the answer. When both arrows are parallel, the analogy holds.

Vector arithmetic, visualised
answer = C + (A − B)  ·  "take C, and apply the A-minus-B direction"
choose an analogy:

This is a simplified 2D map (real vectors have hundreds of dimensions), but the principle is exactly right: meaning is direction and distance in vector space, and analogies are parallel arrows.

🎯 Check your understanding

Quick challenge

1. What does word2vec produce for each word?
2. In "King − Man + Woman = Queen", what does subtracting "Man" do?
3. Why do "King" and "Queen" end up near each other on the map?
4. True or false: in a real word2vec model, you can always read what each dimension means.
Takeaway

What you learned

To feed language to a network, every word becomes a vector (an embedding) via methods like word2vec. Each vector places the word on a giant map of meaning, where similar words are neighbours and each dimension captures some property. Because meaning is direction and distance in this space, you can do arithmetic: King − Man + Woman ≈ Queen. (Real dimensions have hundreds of slots and aren't human-readable.)

Next up → Module 5: Predicting the next word. Now that words are vectors, how did early models actually generate text? We'll meet bigrams and trigrams — the first language models — and see exactly why they break.