Learn / How LLMs Actually Work

Training, generation & fine-tuning

Assemble a GPT, learn the loss, sample text, and see how assistants are aligned.

Start free, no card 10 lessons a month on the free tier.

Lessons in this class

Stack blocks into a GPT (forward pass)

python · 3 steps · free

Assemble the full model and read out next-token scores.

  1. Embed and add position
  2. Run through the blocks
  3. Final norm and unembed to logits

Start this lesson

The training objective

python · 4 steps · free

Cross-entropy, and watching a loss actually go down.

  1. Logits to probabilities
  2. Cross-entropy for one token
  3. Average over a batch
  4. Watch a loss go down

Start this lesson

Sampling: how text comes out

python · 4 steps · free

Greedy, temperature, top-k and top-p decoding.

  1. Greedy: always the top token
  2. Temperature
  3. Top-k
  4. Top-p (nucleus)

Start this lesson

From base model to assistant

python · 1 steps · free

How next-token predictors become ChatGPT: SFT and RLHF.

  1. The last mile: alignment

Start this lesson

How CodeTrain teaches this

No videos and no multiple-choice quiz at the end. Each lesson is a handful of small steps in a real editor. You type the code yourself, it runs, and the tutor reviews what you actually wrote. It will not hand you the answer, and the step doesn't advance until your code passes. What you get at the end is a record of which steps you wrote unaided, not a completion percentage.

The rest of How LLMs Actually Work

Neural-net foundationsTokens & embeddingsThe Transformer block
Start this class free Browse every course