I use LLMs. I know how LLMs work.
Each lesson gives you one SDK call of an LLM (large language model).Write what it does, yourself.
- No ML experience
- No GPU
- No installs
Choose a language
Start in PythonEach case runs the SDK call and your loop on the same input, and compares their outputs.
In training, each number moved a little to make guesses of the next text less wrong.
Loads the model and the runtime, one time.
Turn on JavaScript to run the model here.
What you will understand
No machine learning experience. If you can read a loop and call a function, you can follow each lesson.
How does it write?
It guesses the next piece of text, and does it again and again.
How does it read?
Text is cut into tokens, the pieces of text that it guesses. Each token becomes a row of numbers.
How does a word use its context?
Attention: each token looks at itself and at the tokens before it.
Where is the knowledge?
In 5.6 million learned numbers, the parameters. Stage after stage, the model multiplies each row of numbers by some of them.
How does it learn?
It sees how wrong its guess was, and each number moves a little toward a better guess.
How does it get better at a task?
The reward is a score from a program: 1 when the answer follows a rule, 0 when not. The model learns to get 1 more often.
At the end, the model runs on code that you wrote.
How it works
The images are screenshots, and the code in them is Python. After you start, you do these steps in the lessons of the workshop, in the programming language that you select.
See it
A figure plays each part with the real numbers of the model. In a lesson, you scroll the page, and the figure moves.

Screenshot of the workshop. Each row is a candidate for the next token (a piece of text). It shows the token's ID, its text (␣ is a space) and a bar for its chance. k: only the k likeliest tokens stay candidates. t (temperature): a lower t favors the likeliest tokens, and a higher t evens out the chances. u: a random number. The same bars fill the line from 0 to 1, and sampling picks the token at the mark u (thick outline). Write it
In the editor, you write what one call of the SDK does, in your own code.

Screenshot of the workshop with Python code. The blue bar marks where to replace model.sample. The k, t and u of the first image are top_k, temperature and draw here. scores: the model's score for each token ID. For had␣ in the first image, it is scores[360]. The 5 rows' scores to 3 decimals, from the top: 13.070, 12.980, 12.426 (had␣), 12.351, 12.088. temperature: model.sample divides the top k scores by t. For had␣, 12.426 ÷ 0.8 = 15.5325. softmax: the 5 rows share 100% in proportion to exp(x), 2.7182818 to the power of the result x. In millions, exp(15.5325) ≈ 5.57, and 5.57 ÷ (12.45 + 11.13 + 5.57 + 5.07 + 3.65) ≈ 14.7%. Test and run it
The tests compare your output with the reference answer. Then your code runs the model.

Screenshot of the workshop. In the lesson Sampling, your code replaced model.sample of the second image. This is the result after you press Test. Case 1 gives the program the t, k and u of the first image, with the scores of its prompt. The program prints 360, the ID of had␣: the same token that sampling picks in the first image. A green check marks each case that passed. The text beside the green bars also counts cases 5 and 6, which the image does not show. Read the answer
Select Answer in the editor to compare the reference answer with your code. The panel beside it explains the answer one step at a time.

Screenshot of the workshop with Python code. Answer shows the reference code for model.sample of the second image. The blue bar marks its third step, which a panel explains in a lesson. ranked: all the token IDs, with the highest score first. kept: the first top_k of them. In case 1: 617, 603, 360, 1707 and 888, as in the first image. total: the running sum of chances, which softmax makes from the scores of kept. The loop stops at the first total > draw, and selected_id is the pick: 360 in case 1.
Write it in your language
Your turn.
Start in PythonYour browser keeps your edits and test records. Use the same browser and site to resume.