Master data processing, modeling, and deep learning algorithms.
A large language model (LLM) is a system trained to predict the next token in text. That single idea, scaled to enormous models and datasets, produces the conversational behavior people now interact with every day. Understanding what an LLM actually does — generate text token by token from learned probabilities — is the key to using it well and not being misled by it. This lesson builds the full picture: tokenization, embeddings, the Transformer, attention, pretraining and fine-tuning, decoding, retrieval (RAG), and the crucial distinction between a model and an agent. It is the most conceptual lesson in this batch. The TRY_IT is a toy next-token predictor. It is not an LLM and is clearly labeled as such.
| Discriminative | Generative | |
|---|---|---|
| Learns | Boundary between classes | The data distribution |
| Typical output | A label or score | New samples (text, images) |
| Example | Spam classifier | An LLM generating text |
For each token, the model computes a query, key, and value. A token attends to others by comparing its query against their keys; the resulting attention scores weight the values.
Generation loops through this pipeline once per token. The model does not "look up an answer"; it computes a distribution over the next token each step.
| Setting | Effect |
|---|---|
| Temperature | Higher = more random; lower = more deterministic |
| Top-k | Sample only from the k most likely tokens |
| Top-p | Sample from the smallest set covering p of probability mass |
Decoding controls how the next token is chosen from the probability distribution. Higher temperature does not mean "smarter" — it means more random.
| Training | Inference | |
|---|---|---|
| Input | Large dataset | User prompt tokens |
| Work | Optimize parameters | Forward pass + decoding |
| Cost | Huge (many GPUs) | Lower per request |
| Result | A trained model | Generated output |
A prompt is the interface through which you give a language model a task, context, and constraints. Because an LLM produces text from the prompt it is given, a well-specified prompt is how you steer its output.
Many conversational systems separate instructions into two roles. System instructions set standing rules for the whole conversation; user instructions contain the specific request. This gives an instruction hierarchy: system rules persist while user messages vary.
Few-shot examples are most useful when the desired format or classification is not obvious, and when the model can learn the pattern from the examples alone.
Instead of answering from memory, a model can request that an external tool be run. The model emits a structured "tool call"; the surrounding application decides whether and how to execute it, then returns the result to the model.
| Fine-tuning | RAG | |
|---|---|---|
| Changes | Model parameters | Adds external knowledge at inference |
| Best for | Style, format, domain behavior | Fresh or private facts |
| Example | Teach a consistent brand voice | Answer from company documents |
RAG retrieves relevant documents and feeds them into the prompt so the model grounds its answer in provided facts rather than memorized parameters.
Evaluating an LLM is harder than testing a deterministic program, because there is no single "correct" output. The same question can have many valid answers, and a fluent answer can still be wrong.
| Human evaluation | Automated evaluation | |
|---|---|---|
| How | People judge quality | Programs score against references or rules |
| Strength | Captures nuance | Fast, cheap, repeatable |
| Weakness | Slow, costly, subjective | May miss subtle errors |
Evaluation ties directly to the rest of this node: RAG answers are checked for groundedness, structured output is checked for valid, correct fields, and production monitoring watches whether quality drifts over time.
A hypothetical distribution over the next token.
(decoding settings change which token is chosen)
Choosing the right approach.
(one changes parameters; the other adds facts at query time)