In this lesson: how a language model works out what a word like "it" means, by looking back over the other words and picking out the ones that matter. This is called attention: it is why one changed word can change a whole answer, and why you name the thing when no word decides it.
1. One word flips the answer
We asked an AI two questions and told it to answer in two words. In the sentence "My phone didn't fit in my pencil case because it was too big", what does "it" mean? Before you read on: what would you say?
It answered: My phone.
Then we changed one word. "My phone didn't fit in my pencil case because it was too small." It answered: Pencil case.
Both answers are right. The two sentences are the same except for the last word, and the meaning of "it" flips from the phone to the pencil case. You do the same without thinking: a phone can be too big to fit, and a pencil case can be too small to hold it. To know what "it" means, you look at a word that comes after it, and at the two things before it, the phone and the pencil case. Section 2 shows how a model, which only looks back, gets there too.
Notice that in the "too big" sentence, "it" is the phone, which is not the nearest thing to "it". So the old idea that "it always means the nearest thing" is wrong. One sentence that breaks "always" is enough to show it.
One changed word, a different “it”
2. It looks back over everything
Remember how a language model writes: one likely word at a time, using everything written so far. It can only look back: the words after the one it is working on aren't there yet. And it doesn't treat the earlier words as equally important. For each new word, it works out which other words matter most right now. This is called attention: giving some earlier words much more weight (how much they count) than others.
It is also how a model uses a long prompt: it doesn't weigh hundreds of words equally, it picks out the few that matter for the word it is writing now, and it can miss one, most often in the middle of a long prompt.
So how can "big", which comes after "it", decide what "it" means? Because of when the model answers. You gave it the whole sentence and then the question, so by the time it writes its answer, every word, "big" included, is already behind it. It looks back from the answer and picks out the phone, the pencil case and "big".
You don't need the maths. The picture is enough: when it answers, the words "phone", "pencil case" and "big" or "small" matter a lot, and "my" or "because" matter very little.
Looking back, a few words weigh the most
3. Like a class group chat
Someone in your class chat writes "it's cancelled". You don't read that message alone. You scroll up: was it the football match or the maths test? The right earlier message decides what "it" means. Attention is the model scrolling up and picking out the messages that matter. (Unlike you, it doesn't scroll one message at a time: it weighs all of them at once.)
A model does the same with a chat you have with it. When it writes its next reply, your earlier messages and its own are all behind it, and attention picks out the few that matter for what you just asked.
That is how a chatbot can stay in character. Say your first message is "You are a pirate cat who loves fish". Twenty messages later you ask "What's for dinner?", and the reply can still come in a pirate cat's voice, about fish. That first message is far back, but as long as the chat isn't too long for the model to hold (today's models can hold hundreds of pages), it is still behind the reply, and attention can give it a lot of weight. In a very long chat, some apps drop or shorten the oldest messages, and then a setup can quietly stop working: check it still holds. Being near isn't the main thing that makes a message count; mattering for the new reply is.
A system prompt (the hidden instruction an app puts before your messages, from the lesson on characters) works the same way: it comes at the very start, so it is behind every reply. You will use this in the Character Chatbot project, in the step Write the hidden instructions: what you set up at the start keeps steering what comes later.
If the message that decides it was never written, there is nothing to pick out, and the model has to guess. That is what the next section is about.
Scroll up to the message that decides
4. When no word decides it
Sometimes nothing in the sentence decides the meaning. "Tell the captain's dad that his bike is in the shed." Whose bike: the captain's or his dad's? No word settles it. Ask an AI that question and it may say so; but when the sentence is inside a job you give it, such as "write this message to the captain's dad for me", it may just pick one without saying it picked. Give it the same job twice, or change one word, and the pick may change.
The fix is simple: name the thing. "Tell the captain's dad that the captain's bike is in the shed." Now there is nothing to guess. Some jokes and word puzzles use sentences like this on purpose; your prompts shouldn't.
When nothing decides it, name the thing
5. What this means when you build
- Context changes meaning. The same words can mean different things, depending on what is around them.
- Say what you mean. If your prompt has more than one thing "it" could be, name the thing instead. "Put the club logo on the poster and make it blue" could mean two things; "make the logo blue" means one.
- It can still pick wrong. When the clue is weak or missing, it may pick one without saying so, and a wrong pick reads as smoothly as a right one: check it picked the thing you meant.
Context changes meaning: say what you mean