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.
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.
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.Why it sounds so clever
The three parts of a prompt
- 1
System prompt
The standing orders from the developer. "You are a helpful support agent for Acme. Never discuss competitors." - 2
User message
What the human typed right now. "Where is my order?" - 3
Everything else
Search results, file contents, web pages, tool output, past messages. This is the part that gets dangerous later.
Tokens: the model's alphabet
un + believ + able. Roughly, 1 token is about 4 letters of English.Watch and read more
Lab
You will see next-token probabilities with your own eyes.
The problem
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.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
Q2Two models have identical perplexity on your test set. One is far more useful in your product. Give a concrete mechanism.Reveal
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