FoundationsBeginnerLesson 24 min read

What a large language model does

An LLM is autocomplete that swallowed a library. Understanding that one sentence explains most of its strengths and every one of its weaknesses.

Lesson in motion

In 60 seconds

What a large language model does

An LLM is autocomplete that swallowed a library. Understanding that one sentence explains most of its strengths and every one of its weaknesses.

1/5
In simple words
It plays "guess the next word", over and over, extremely fast. That is the whole trick.
Type The cat sat on the ___ and the model does not "think about cats." It scores every word it knows and picks a likely one. Then it does it again with the new word included. And again.
The cat sat on the ___Next word: optionsmat61.0%floor14.0%roof8.0%piano2.0%telephone0.4%it rolls a weighted dice on this list — that is why the same question gives different answers
Every answer is built one word at a time. The model never plans the whole sentence first. It commits to a word, then guesses again from there.

Why it sounds so clever

It read an enormous amount of human writing. Textbooks, code, arguments, recipes, poems. To guess the next word well in all of that, it had to absorb a lot of structure about how the world is described.
So it is not "just autocomplete" in a dismissive sense. It is autocomplete that had to learn grammar, facts, reasoning shapes and tone to do its job. But the job is still: guess the next word.

The three parts of a prompt

  1. 1

    System prompt

    The standing orders from the developer. "You are a helpful support agent for Acme. Never discuss competitors."
  2. 2

    User message

    What the human typed right now. "Where is my order?"
  3. 3

    Everything else

    Search results, file contents, web pages, tool output, past messages. This is the part that gets dangerous later.
Danger
Hold on to this: the model sees all three parts as one long stream of text. There is no hard wall saying "this part is orders, this part is just data." Module 9 is entirely about the damage that causes.

Tokens: the model's alphabet

Models do not read letters or words. They read tokens, which are word-chunks. "Unbelievable" might be un + believ + able. Roughly, 1 token is about 4 letters of English.
This is why models are sometimes bad at counting letters in a word. They literally cannot see the letters, only the chunks.

Watch and read more

But what is a GPT? Visual intro to transformers3Blue1Brown · 27 min · video
Intro to Large Language ModelsAndrej Karpathy · 1 hr · video

Lab

You will see next-token probabilities with your own eyes.

~15 min

The problem

Take any sentence and, by hand, write your five best guesses for the next word with a rough probability for each. Then get a real model to show its distribution (any provider's API with logprobs, or an open model with transformers). Compare your intuition against the machine's. Then set temperature to 0 and to 1.5 and generate 200 tokens at each.
Starter codepython
from transformers import AutoTokenizer, AutoModelForCausalLM
import torch

name = "gpt2"   # small enough for a laptop
tok = AutoTokenizer.from_pretrained(name)
model = AutoModelForCausalLM.from_pretrained(name)

prompt = "The cat sat on the"
ids = tok(prompt, return_tensors="pt").input_ids

with torch.no_grad():
    logits = model(ids).logits[0, -1]        # last position only

probs = torch.softmax(logits, dim=-1)
top = torch.topk(probs, 10)
for p, i in zip(top.values, top.indices):
    print(f"{p.item():6.2%}  {tok.decode(i)!r}")

You are done when

Hard questions

Try to answer before you reveal. If you can answer these, you understood the lesson.

Q1The top token has probability 0.61. The model is 'confident'. Is the answer more likely to be true? Justify carefully.Reveal
No. That 0.61 is confidence about which token follows in text like the training data, not about the world. If the training corpus confidently stated something false, the model is confidently wrong at 0.61 too. Token probability measures typicality, not truth. This is exactly why calibration is listed as an open gap in Module 30 — and why a confidence score cannot be used as a correctness filter.
Q2Two models have identical perplexity on your test set. One is far more useful in your product. Give a concrete mechanism.Reveal
Perplexity averages over every token, and most tokens are easy — articles, punctuation, common words. Two models can tie on the average while differing sharply on the small tail of tokens that carry the meaning: names, numbers, the decisive word in an instruction. Add post-training: an instruction-tuned model and a base model can have similar perplexity while only one follows a request.

Please sign in to continue.

Questions people ask

Why does it give a different answer each time?

Because it picks from that probability list with a bit of randomness, controlled by a setting called temperature. Low temperature means "always pick the safest word" and gives repetitive, predictable text. High temperature means "take chances" and gives creative, sometimes wrong text.

Does it look things up on the internet?

Not by itself. A plain model only has what it absorbed during training, frozen at a date. When it does look things up, that is a tool being used — see Module 4 — and that tool is a doorway an attacker can push things through.

Why does it confidently invent fake sources?

Because "a plausible-looking citation" is a very likely next-word pattern. The model is optimising for likely, not for true. Nothing in the machine checks reality unless you bolt a checker on.

What is the difference between a model and a chatbot?

The model is the engine. The chatbot is the whole car: engine plus a system prompt, plus chat history, plus safety filters, plus sometimes tools and a memory. Most security problems live in the car, not the engine.

Is a bigger model always better?

Usually smarter, always more expensive and slower. For many jobs a small model with good instructions and good tools beats a giant model with neither.

Lesson test

5 questions. Get 3 right (60%) to pass and complete this lesson.

Sign in with your phone number to take the test and save your progress