Objectives
By the end of this lesson, you will be able to:
- Explain that a language model generates text by repeatedly predicting the next piece
- Describe what tokens are and what the model was trained on
- Explain why fluent output does not prove understanding or truth
Key terms
- Generative AI
- AI that produces new content, such as text, images, audio or video.
- Large language model (LLM)
- A very large neural network trained on huge amounts of text to predict what comes next.
- Token
- A piece of text, often a word or part of a word, that a language model reads and produces one at a time.
- Context window
- The amount of text a model can take into account at once.
Reading
Predict the next word
Finish this sentence: "The sun rises in the ..." You said "east" without effort, because you have met that pattern many times. A language model does the same thing at enormous scale.
Given some text, it calculates which piece of text is likely to come next. It picks one, adds it to the text, and predicts again. Word by word, a whole answer appears. Your phone's keyboard suggestions are a tiny version of the same idea.
The pieces are called tokens. A token is often a whole word, and longer or rarer words are split into several tokens.
Trained on an enormous amount of text
A large language model is a neural network, like those in Unit 3, with billions of weights. It is trained on a huge collection of text: books, articles, websites, code, conversations. The training task is simple to state: hide the next token, have the model guess it, and adjust the weights when the guess is wrong.
To get good at that game across so much text, the model has to pick up a great deal along the way: grammar, facts that are stated often, styles of writing, how arguments are structured, how code is laid out. This is why one model can write a poem, summarize a report and explain a math problem.
Fluent is not the same as true
The model is trained to produce text that is likely, given what came before. Likely text is usually sensible and often correct, because much of what people write is correct. But the model has no separate step that checks facts against the world.
It also has limits you should know. It only knows what was in its training text, up to the date that text was collected, unless it is connected to a search tool. It can only consider what fits in its context window. And because it usually picks among likely tokens with some randomness, asking the same question twice can give different answers.
A helpful way to think of it: a very well-read assistant that writes fluently about almost anything, has never left the library, and cannot always tell what it remembers from what merely sounds right.
Try it · Interactive lab
Run a tiny language model
This model has read eight short sentences and nothing else. Build a sentence by picking each next word, or let the model choose.
This is everything the model has ever read. Edit it and the model retrains instantly.
The model writes
the▍
After "the", the model has seen
Try this: generate a few sentences. Some will be things the training text never said, such as the dog sitting on the mat. The model is not lying; it is following likely word patterns. Now add a sentence about a new animal to the training text and watch it appear in the choices. A chatbot works on the same principle, with billions of weights and far more text.
Group activity 20 min
Be the language model
You will need
- Paper strips
- A short paragraph of "training text" printed for each group (four or five simple sentences on one topic)
- 1
Read the training text. For each word, list which words followed it and how often. This table is your model.
- 2
Pick a starting word. Using only your table, choose a likely next word, then the next, until you have a sentence of about ten words.
- 3
Read the sentences aloud. Which sound sensible? Which are fluent but false or meaningless?
- 4
Discuss: your model knows nothing beyond its paragraph. What would it say about a topic that was not in the paragraph?
Discuss
- Q1
Your paper model produced sentences nobody wrote. Is that creativity? Why or why not?
- Q2
If a model learned from text written mostly in a few languages, what would you expect about its answers in other languages?
- Q3
Why might the same question give two different answers from a chatbot?
Write your answer to one of the questions. Saved only on this device.
Quick check
Choose an answer to see whether you were right, and why.
Key takeaways
- A language model writes by predicting the next token, again and again.
- It learned from an enormous amount of text and picked up patterns of language and knowledge.
- Fluent output can still be wrong, outdated or made up.