Pranav Srivastava
Learning tracks
publishedBeginner to Advanced6 chapters

Embeddings, in Depth: Turning Words into Numbers

The single idea underneath every modern AI — turning words into numbers you can measure and do maths on. From an eight-year-old's picture to the billions of numbers inside ChatGPT and Claude, with a spinnable 3D model and the real facts on scale, compute, and cost.

EmbeddingsLLMsVectorsTransformersScale

There is one idea hiding underneath ChatGPT, Claude, Google search, Spotify recommendations, and almost every "smart" thing a computer does today. It is not complicated — an eight-year-old can get it in a minute — but it is so powerful it took decades to fully exploit. The idea is this: turn words into numbers, arranged so that the numbers carry the meaning. Those numbers are called embeddings, and this course goes from the picture a child can grasp all the way to the billions of numbers inside a frontier model.

What you will learn
  • Understand embeddings from scratch — words as points that cluster by meaning
  • Feel "many dimensions" by spinning a 3D map, and do arithmetic on meaning
  • See how machines learn the map from raw text
  • Understand how embeddings power LLMs like ChatGPT and Claude — and the staggering numbers behind them

The big idea, the simple way

Some different words mean nearly the same thing — cat, kitten, feline — and so do car, vehicle, automobile. A computer that understood meaning should treat the words in each group as basically the same thing. Press the button and watch it do exactly that:

Sorted by spelling
one meaningone meaning
cat
kitten
feline
car
vehicle
automobile
Sorted by letters, 🐱 cat ends up right next to 🚗 car — even though they have nothing in common. Spelling is blind to meaning. Now press Group by meaning and watch what happens.

Sorted by letters, "cat" lands next to "car" — useless. Sorted by meaning, words that mean the same thing snap into the same place. That "same place" is the whole idea. Do it for every word at once and you get a giant map where similar meanings are neighbours:

A map of meaning — tap a word to find its closest friends
🐱cat🐶dog🐯tiger🐘elephant🍕pizza🍔burger🍎apple🍦ice cream🚗car🚌bus🚲bike✈️plane☀️sun🌙moonstar🌳tree
Every word is a dot. Similar things sit close together — so “search by meaning” just means “find the nearest dots.” Tap one to see.

The computer was never handed a dictionary. It read a mountain of text, noticed which words get used in similar ways, and placed them close together. That map of meaning is what embeddings are.

Chapter summary
  • An embedding places each word at a spot so that similar meanings are close together
  • Different words for the same thing land in nearly the same place
  • The machine learns this from how words are used, not from any dictionary

A space you can spin — what 'dimensions' means

On paper we draw the map flat, with two directions: left-right and up-down. That is 2 dimensions. Add depth — a direction into the page — and you have 3 dimensions, a real space you can spin. Grab this one and give it a whirl; tap a word to see its nearest neighbours:

a 3D map of meaning — drag to spin, tap a word3 of ~hundreds of dimensions
✦ spinning live — grab it
Every word is a point. Spin it around; similar words huddle together in 3D — just like they do in the model's hundreds of dimensions.

Here is the mind-bender: a real embedding does not use 2 or 3 directions. It uses hundreds or thousands of them at once. You cannot picture a 768-dimensional space — nobody can — but the maths works exactly the same as this 3D toy: every word is a point, and "similar meaning" means "close together," just in far more directions. Each extra dimension is another subtle question the model can use to tell meanings apart ("is it alive?", "is it hot?", "is it formal?" — though the real ones aren't labelled so neatly).

Chapter summary
  • 2D and 3D are just how many directions a space has; you can spin a 3D one
  • Real embeddings use hundreds to thousands of dimensions at once
  • More dimensions give the model room to hold many shades of meaning apart

Doing maths on meaning

Because every word is now a point, the relationships between meanings become directions you can add and subtract. The famous example: take "king", apply the same step that turns "man" into "woman", and you land on "queen." Build your own and watch the two arrows stay parallel:

Doing maths on meaning — build an analogy
is to as is to queen
manwomankingqueenprinceprincess

The amber arrow is the relationship (manwoman). Apply the same arrow to king — the green arrow — and you land on queen. Nobody taught the model that. It falls out of the geometry.

This result — man is to woman as king is to queen, falling out of pure geometry — was the moment, back in 2013, that convinced researchers embeddings had captured real meaning and not just word-counting. It came from a Google system called word2vec (Mikolov et al., 2013), and it is still the clearest proof that "distance means similarity, direction means relationship."

Chapter summary
  • Relationships between meanings become directions in the space
  • king − man + woman ≈ queen — analogies solved by vector arithmetic
  • This 2013 word2vec result showed embeddings capture genuine meaning

How a machine learns the map

Nobody places the words by hand. The machine learns the whole map from raw text, using one deceptively simple principle, stated by the linguist J.R. Firth back in 1957: "You shall know a word by the company it keeps."

The training trick is a fill-in-the-blank game, played billions of times:

Learning by filling the blank
  "The ___ chased the mouse."     → the model guesses: cat? dog? kitten?
        │
        ▼
  It was "cat". Nudge the numbers so 'cat' fits this context better.
        │  (repeat over billions of sentences)
        ▼
  Words that appear in similar blanks drift close together — automatically.
Guess the missing word; nudge the numbers; repeat billions of times

Because "cat" and "kitten" show up in the same kinds of sentences, the nudges keep pushing them together, and they end up neighbours — no human ever told the machine they were related. Do this over billions of sentences and the entire map of meaning organises itself. That is self-supervised learning, and it is the engine behind every large model.

Chapter summary
  • The map is learned, not hand-built: "know a word by the company it keeps"
  • Training is a fill-in-the-blank game repeated over billions of sentences
  • Words used in similar contexts drift together automatically — no labels needed

Embeddings inside ChatGPT and Claude

A large language model is, at its front door, a giant embedding table. Here is the journey your words take:

From your text to the model's numbers
  "hello there"  ──split──►  tokens: [hello] [ there]
                                │  look each up in the embedding table
                                ▼
                    each token → a vector of thousands of numbers
                                │  fed through dozens of transformer layers
                                ▼
                    the model predicts the next token — and writes
Text becomes tokens, tokens become embedding vectors, then the layers do their work

Two numbers make the scale real. A model has a vocabulary of tokens (word-pieces) — tens of thousands of them — and each token's embedding is a vector whose length is the model's hidden dimension. For GPT-3, that was a vocabulary of about 50,000 tokens and a hidden dimension of 12,288. Multiply them and the input embedding table alone is roughly 617 million numbers — before the model does a single bit of thinking.

That table is only the entrance. Above it sit dozens of transformer layers (from the 2017 paper "Attention Is All You Need"), and all of those numbers together are the model's parameters — the knobs learned during training. Every version you have heard of is mostly a story about how many of those knobs there are.

Chapter summary
  • An LLM turns your text into tokens, then looks each up in a huge embedding table
  • GPT-3's input embedding table alone was ~617 million numbers (50k tokens × 12,288)
  • Those vectors flow through dozens of transformer layers; all the numbers are the model's parameters

The staggering scale — the real numbers

Now the facts, because the growth is genuinely hard to believe. In a few years, models went from millions of parameters to hundreds of billions, trained on more text than any human could read in a thousand lifetimes.

ModelYearParametersTraining dataEst. training cost
word2vec2013~a few hundred dimsbillions of wordstrivial
GPT-12018117 million~5 GB of bookssmall
GPT-220191.5 billion~40 GB of web text~tens of thousands
GPT-32020175 billion~300 billion tokens~$4.6M (compute)
GPT-42023not disclosed (much larger)not disclosed>$100M (per OpenAI)
Llama 3.12024405 billion~15 trillion tokenstens of millions

A few facts to sit with:

  • Compute. Training GPT-3 took an estimated 3.14 × 10²³ operations — the equivalent of running a fast laptop for thousands of years, compressed onto thousands of GPUs running for weeks.
  • Cost. Independent estimates put GPT-3's training compute around $4.6 million; OpenAI's CEO said GPT-4 cost "more than $100 million"; the 2024 Stanford AI Index estimated frontier training runs (GPT-4, Gemini Ultra) in the $78M–$191M range. Frontier costs are still climbing.
  • Data. GPT-3 read about 300 billion tokens; modern models train on 10–15 trillion. The 2022 Chinchilla result (Hoffmann et al., DeepMind) showed that, for a given compute budget, you often want more data per parameter — roughly 20 tokens for every parameter — reshaping how everyone trains.
Chapter summary
  • In ~a decade, models grew from millions to hundreds of billions of parameters
  • GPT-3: 175B parameters, ~300B training tokens, ~$4.6M compute; GPT-4: >$100M
  • Chinchilla (2022) showed more data-per-parameter is often compute-optimal
  • The scale brings a real-world cost — energy, water, hardware — worth reckoning with
Check your understanding
  1. In your own words, what is an embedding — and why does "cat" end up near "kitten"?
  2. A real embedding uses hundreds of dimensions. What does one extra dimension buy the model?
  3. Roughly how many numbers were in GPT-3's input embedding table, and how did we get that figure?

Sources: Mikolov et al., “Efficient Estimation of Word Representations,” 2013 (word2vec); J.R. Firth (1957), the distributional hypothesis; Vaswani et al., “Attention Is All You Need,” 2017; Brown et al., “Language Models are Few-Shot Learners,” 2020 (GPT-3: 175B params, 12,288 hidden dim); Hoffmann et al., “Training Compute-Optimal LLMs” (Chinchilla), 2022; the Stanford AI Index 2024 (training-cost estimates). Parameter/cost figures for GPT-4 and later are estimates; exact numbers are undisclosed. This course underpins Folders vs Vectors and RAG in Production.

All tracksQuestions? Get in touch →