★ FOUR BRAND-NEW COURSES ANNOUNCED! ★ Machine Learning End To End  •  Hands-On Deep Learning with Python  •  Generative AI & LLMs with Python  •  AI Agents and Agentic AI with Python  ★  Open the “Educational” menu above to explore them ★  ★  NEW! 5. JOB ASSISTANCE: JD Report • Resume customization • AI Mock Interviews — FREE with course bundles, or just ₹499 / US$5. Single Payment. No Subscription. ★★ FOUR BRAND-NEW COURSES ANNOUNCED! ★ Machine Learning End To End  •  Hands-On Deep Learning with Python  •  Generative AI & LLMs with Python  •  AI Agents and Agentic AI with Python  ★  Open the “Educational” menu above to explore them ★  ★  NEW! 5. JOB ASSISTANCE: JD Report • Resume customization • AI Mock Interviews — FREE with course bundles, or just ₹499 / US$5. Single Payment. No Subscription. ★★ FOUR BRAND-NEW COURSES ANNOUNCED! ★ Machine Learning End To End  •  Hands-On Deep Learning with Python  •  Generative AI & LLMs with Python  •  AI Agents and Agentic AI with Python  ★  Open the “Educational” menu above to explore them ★  ★  NEW! 5. JOB ASSISTANCE: JD Report • Resume customization • AI Mock Interviews — FREE with course bundles, or just ₹499 / US$5. Single Payment. No Subscription. ★★ FOUR BRAND-NEW COURSES ANNOUNCED! ★ Machine Learning End To End  •  Hands-On Deep Learning with Python  •  Generative AI & LLMs with Python  •  AI Agents and Agentic AI with Python  ★  Open the “Educational” menu above to explore them ★  ★  NEW! 5. JOB ASSISTANCE: JD Report • Resume customization • AI Mock Interviews — FREE with course bundles, or just ₹499 / US$5. Single Payment. No Subscription. ★

From words to numbers: how tokens become vectors

From words to numbers: how tokens become vectors
12-10-2026  |  By Tejas Desai, Ecube Analytics  |  Generative AI: Transformer on-ramp (Chapter 1)  |  3 min read
READ 2ND OF 8 IN THIS SERIES

From words to numbers: how tokens become vectors

Transformer on-ramp · Part 2 of 8

A language model cannot read the word “bank”. All it can do is arithmetic. So the very first job in any LLM is to turn text into numbers, and to do it in a way that keeps meaning.

Step 1: cut the text into tokens

The text is first chopped into tokens: small pieces that are often whole words and sometimes parts of words. Each token has a fixed whole-number ID in the model’s vocabulary. (How the cutting is decided is the subject of the next chapter of the course.) An ID is only a label: token 5 is not “more” or “closer to” token 6 in any sense.

Step 2: look up a vector

Labels cannot carry meaning, so each ID is swapped for a list of numbers. The model keeps an embedding table: one row per vocabulary item, with the same number of columns for every row. The token ID is simply the row number, and the row is that token’s vector. There is no calculation here, just a lookup.

Tokens become vectorsThree tokens are mapped to integer IDs; each ID selects one row of the embedding table, and that row is the token's vector.TokensToken IDsEmbedding table (learned)Vectors…………0…………1+0.2-0.5+0.9+0.12…………3…………4+0.7+0.4-0.3+0.65…………6-0.4+0.8+0.2-0.77TheID 2vector of “The”catID 5vector of “cat”satID 7vector of “sat”IDs and numbers are illustrative: a real table has tens of thousands of rows.
Three tokens, three IDs, three rows of the embedding table. The rows are the vectors the rest of the model works with.

Where do the numbers come from?

They start out random and are learned together with everything else. If two tokens tend to appear in similar contexts, training nudges their rows closer together, because that helps the model predict text. Nobody hand-designs the numbers; whatever similarity the model finds falls out of training.

Why numbers that live in space are useful

Once a token is a point in space, the model can reason with distance and direction instead of arbitrary labels. Layers after the table are ordinary neural-network layers, and they can only work on numbers like these.

How big is the table? It is just another block of weights, with vocabulary size × vector width numbers. For an illustrative 50,000-token vocabulary and 768-wide vectors, that is 38.4 million numbers, all of them trained.

The whole idea in four lines

import torch

emb = torch.nn.Embedding(num_embeddings=8, embedding_dim=4)   # 8 tokens, 4 numbers each
ids = torch.tensor([[2, 5, 7]])         # "The cat sat" as token IDs
vectors = emb(ids)                      # look up three rows
print(vectors.shape)                    # torch.Size([1, 3, 4]): batch, tokens, numbers

Three token IDs went in; three 4-number vectors came out. A real model does exactly this with a much larger table.

Takeaways

  • Text is cut into tokens, and each token has an integer ID.
  • An embedding table is a lookup: ID in, vector out.
  • The table’s numbers are learned during training, not designed by hand.
  • Vectors let the model use distance and direction instead of labels.

Next in the series (Part 3): Why recurrence isn't enough: reading a sentence all at once

This blog is from chapter 1, course-2-generative-ai of 4 world-class courses on aibits.ecubeanalytics.com
← Previous Article 2 of 8 in this series Next →