US AI Academy

Before the five ideas

Words become numbers

A language model (the kind of AI you chat with) can’t read. Before any math can happen, a sentence has to turn into numbers: first into pieces called tokens, then into a long list of numbers for each piece. Everything the model does after this step is arithmetic on those lists.

In this lesson

  • How a real model chops one sentence into 10 tokens
  • What a 1,024-number vector is, and why it’s an arrow
  • Why Paris points closer to France than to banana
The blueprint catThe blueprint dog

The sentence we’ll follow

From here on, the course follows one sentence through a real AI model: “The Eiffel Tower is in the city of”. The model’s job is to guess the next word.

The model is Qwen3-0.6B-Base, a small open model made by Alibaba’s Qwen team in 2025. I rewrote its math in plain numpy, a basic math toolkit for the Python language. That way I can stop it at any step and print the numbers. I checked my version against the standard code from Hugging Face, the site that hosts the model.

Its top guess for the next word is Paris: it gives Paris a 63.3% chance. By the end of the course you’ll be able to follow that guess from start to finish.

Step 1: chop the text into tokens

Our sentence, exactly as Qwen3 sees it.

The785
·E468
iff3,092
el301
·Tower21,938
·is374
·in304
·the279
·city3,283
·of315
? 
Blue number: the token’s id number (more on that below). The dashed ? is the next token, the one the model has to guess.· marks a leading space

Qwen3 never sees letters. It sees tokens: pieces of text from a fixed list. A program called the tokenizer chose that list before the model was trained. Common words get a token of their own, usually with the space in front glued on (the little dot marks that space). Rarer words are built from smaller pieces. “Eiffel” isn’t common enough to earn its own token, so it becomes ·E iff el .

So our 8 words become 10 tokens, and each token is really just a number: its row in a big table inside the model, one row per token. ·Tower is row 21,938. From this point until it writes its answer, the model never touches text again.

The model we’re using

FactQwen3-0.6B-Base
Made byAlibaba’s Qwen team, 2025
Weights (learned numbers)596,049,920
Layers (stages the numbers pass through, one after another)28
Numbers per token1,024
Rows in the token table151,936
Trained on (its first, general training)36 trillion tokens, 119 languages
From the model’s official description page (its model card) and its settings file on Hugging Face. I counted the weights myself, from the model file. “Base” means it’s the raw text predictor, before any chat training.

Why such a small model? Because it runs on my laptop in plain numpy, where I can stop it at any step and print the numbers. Its giant cousins use the same five ideas, with more and bigger layers and a few extra tricks.

For the experts (skip it on a first read)

Qwen’s tokenizer is byte-level byte-pair encoding: it starts from raw bytes and glues neighbors into bigger pieces by a list of merges learned from the most frequent pairs in its training text, so any text in any language can be written with it.

The table has 151,936 rows; the tokenizer uses 151,665 of them. The rest are spare.

10 tokens in. One token out. In between, ideas 1 to 3 (the dot product, matrix multiplication, and softmax with attention) do the work; ideas 4 and 5 (surprise in bits, and the chain rule) are how it learned to.

Step 2: each token becomes a vector

A list of 1,024 numbers, and why it’s really an arrow.

·Tower, row 21,938
0.0376
−0.0018
0.0078
0.0723
−0.0248
−0.0278
0.0396
0.0130
⋮
the first 8 of 1,024

Row 21,938 of Qwen3’s table is a list of 1,024 numbers. A list like that is called a vector.

With two numbers you can draw a vector as an arrow on paper: “go 3 right and 2 up.” With 1,024 numbers it’s still an arrow, just in a space with 1,024 separate axes to step along, where paper has only 2 (across and up). Nobody can picture that, me included. The good news: the math doesn’t care. The rules for lengths, angles and dot products (the next lesson) work the same way with any number of axes.

Nobody chose these numbers. They started out random, and training nudged them over and over until tokens that get used in similar ways ended up pointing in similar directions.

ParisFranceLondonBerlinRomeTokyobananaapplepizzacheesecatdogplacesfoodsanimals
Twelve words from Qwen3’s real table. I made every arrow the same length (1), so only the direction it points matters. Then I squashed each one from 1,024 numbers down to 2, so it fits on the page as one dot. The squash keeps 35% of how the words differ from each other, so read it as a sketch.

The map shows it: places huddle on one side, foods on another, and cat and dog sit together, apart from both. The map is only a sketch, so below is the check with the real vectors: how closely each word points the same way as Paris, using all 1,024 numbers.

Even France is far from 1. What matters is the gap: every place name scores between 0.32 and 0.47 with Paris, and every food scores 0.13 or less. The score is called cosine similarity: 1 means the two arrows point exactly the same way, and 0 means they’re at a right angle. It’s built from the dot product, the subject of the next lesson, where you’ll compute one yourself.

For the experts (skip it on a first read)

These are input embeddings (Qwen3-0.6B-Base ties them to the output layer). The 2D map is a principal component projection of the 12 vectors, each scaled to length 1; the first two components keep 35% of their variance. The cosines use all 1,024 dimensions.