Learn / How LLMs Actually Work

Tokens & embeddings

Turn text into vectors: tokenizers, embeddings, similarity, and position.

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

Lessons in this class

A character tokenizer

python · 5 steps · free

Turn text into integers a model can read, and back again.

  1. Play with a tokenizer first
  2. Build the vocabulary
  3. String -> integer
  4. Integer -> string
  5. Encode and decode

Start this lesson

Train a mini BPE tokenizer

python · 4 steps · free

Learn a subword vocabulary by merging frequent pairs.

  1. Words as lists of symbols
  2. Count adjacent pairs
  3. Merge the top pair
  4. Repeat to grow the vocabulary

Start this lesson

Embeddings are a lookup table

python · 3 steps · free

Map token ids to vectors the model can do math on.

  1. An embedding table
  2. Look up one token
  3. Look up a whole sequence

Start this lesson

Cosine similarity

python · 4 steps · free

Measure how close two vectors point, the basis of 'meaning'.

  1. The dot product
  2. Lengths (norms)
  3. Put it together
  4. Find the nearest

Start this lesson

Positional encoding

python · 4 steps · free

Give an order-blind model a sense of position.

  1. Why position needs encoding
  2. sin for even, cos for odd
  3. The full (seq_len, d) matrix
  4. Add it to the embeddings

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