Learn / How LLMs Actually Work

The Transformer block

Self-attention, causal masking, multi-head, LayerNorm, and the full block.

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

Lessons in this class

Self-attention from scratch

python · 5 steps · free

The one mechanism at the heart of every Transformer.

  1. See attention before you build it
  2. Query-key scores
  3. Scale it
  4. Softmax into weights
  5. Weighted sum of values

Start this lesson

Causal masking

python · 3 steps · free

Stop the model from peeking at the future it's predicting.

  1. A lower-triangular mask
  2. Block the future with -inf
  3. Softmax respects the mask

Start this lesson

Multi-head attention

python · 3 steps · free

Run several attentions in parallel and combine them.

  1. Split into heads
  2. Attention per head
  3. Concatenate and project

Start this lesson

LayerNorm and the feed-forward network

python · 3 steps · free

The two sublayers that sit around attention.

  1. LayerNorm
  2. The GELU activation
  3. The feed-forward network

Start this lesson

Assemble a Transformer block

python · 3 steps · free

Wire attention and the FFN together with residuals.

  1. A residual connection
  2. Pre-norm, two sublayers
  3. Stack it

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 & embeddingsTraining, generation & fine-tuning
Start this class free Browse every course