Module 01 · Building with LLMs

What an LLM actually is

With no math at all, work out the basic facts about large language models by experiment: tokens, next-token prediction, temperature, context and cost, embeddings, and how to choose a model.

Lessons

  1. 01
    Tokens: text as the model sees it

    Cut real passages of Chinese, English, classical Chinese and code with the DeepSeek and OpenAI tokenizers, see what the model actually splits text into, why that sets the price, and why models can't count characters.

    35 min · Beginner
  2. 02
    The model does one thing: predict the next token

    Make the model show its candidate tokens and probabilities at every step, see how an answer is generated one token at a time, then how it turned from a text-continuation machine into an assistant, and where hallucination comes from.

    35 min · Beginner
  3. 03
    Temperature and sampling: why the same question gets different answers

    Take the model's real candidate-token probabilities, implement temperature and top_p sampling yourself in numpy, measure how temperature changes answer variety through the API, and see why temperature 0 still doesn't guarantee identical results.

    40 min · Beginner
  4. 04
    Context windows and cost

    Put the entire httpx documentation into one request, see what it costs and whether the model can find one sentence hidden in the middle, watch the cache make the second call over 30 times cheaper, and write a function that prices a call from usage.

    40 min · Beginner
  5. 05
    Embeddings: turning meaning into numbers

    Turn sentences into vectors locally with an open-source Chinese embedding model, compare their meaning with cosine similarity, and see what it's good at and what it can't tell apart. This is the basis for semantic search and RAG later.

    35 min · Beginner
  6. 06
    How to choose a model

    Leaderboards tell you a model's average level, not how it does on your task. Compare four model configurations on 20 questions for accuracy, speed and cost, and learn to choose with a small test set of your own.

    40 min · Beginner

This module doesn't cover how a neural network computes internally; that's for the second part. It covers only what every user needs to know: what the model sees, how its output is produced, and where the money goes.

Every lesson rests on experiments. You'll cut a Chinese sentence apart yourself with DeepSeek's tokenizer, use the logprobs parameter to see which words the model hesitates between at each step, bring a real probability distribution home and simulate temperature with numpy, and stuff the entire httpx documentation into a single request to see how much the cache saves. Some of the results disagree with what you'll read online, and I've written them down as they came out.

Why this order

Tokens come first, because everything after is measured in them: price, context length, output limits. Next is how the model produces an answer one token at a time, which explains hallucination and randomness. Temperature builds on "drawing by probability", so it's lesson 3. Lesson 4 turns what came before into money and context. Lesson 5's embeddings are a different kind of model: instead of generating text, it turns text into vectors, which module 04's RAG relies on. The last lesson covers choosing a model for your own task and draws on everything before it.

You're done when

  • Given a passage of text, you can count its tokens with a tokenizer and estimate what sending it to a model will cost.
  • You can explain why asking the same question twice gives different answers, and why even temperature 0 doesn't guarantee identical ones.
  • When a model gives you a specific version number or API parameter, you know it needs checking, and where to check it.
  • You can write a function that works out the cost of a call from its usage, including the cache-hit part.
  • With 20 questions of your own, you can compare which of two models suits your task better.

Code for this module

Code and program output are shown exactly as they ran, so comments and printed output are in Chinese.