Language models
"I'm hungry, so I'll make a …" and you think sandwich. A chatbot does the same: it finishes sentences. One word at a time, very fast, with a huge amount of practice.
First, what do you think?
When you ask a chatbot something, where does the answer come from? Make a guess.
What is a language model?
The whole story in three sentences. Behind every chatbot is a language model. It learned from a huge amount of text which word usually comes next. When you ask something, it predicts its answer one word at a time.
Try it. "I'm hungry, so I'll make a …" You probably thought sandwich. Nobody told you. You've seen and heard sentences like it thousands of times.
A language model does exactly that. You may also see it called an LLM, a large language model. It's the predictor behind every chatbot.
- It learned from text. Lots of it. Google calls it "a phenomenal amount". From that text it learned patterns. Which words go together. How a question is usually answered. What a recipe or a letter looks like.
- It predicts the next word. Google describes language models as autocomplete on a huge scale. Like your phone's word suggestions, but trained on far more text.
- It does that again and again. It predicts one word, adds it, and predicts the next. Hundreds of times, in a few seconds. That's the answer you see appear.
Strictly speaking it predicts tokens, pieces of words. That's the next lesson. For now, word is close enough.
A first small step: next time a chatbot answers, watch the text appear. You're watching it predict.
What the predictor does
The rule: for every next word, the predictor works out how likely each word is. Then it picks one.
An example. "The cat sat on the …" Maybe mat gets 40% chance, sofa 25%, chair 15%. The predictor doesn't always pick the top one. There's a bit of chance in the pick. Makers call that setting the temperature. Low: almost the same answer each time. High: more variety.
That explains three things you may have noticed.
- The same question gives a different answer. Each word is a pick with a bit of chance. Change one early word, and the rest of the answer follows a different path.
- It sounds fluent. Fluent sentences are exactly what it learned. Every word fits the one before.
- It can be wrong, and still sound right. It predicts what fits, not what is true. Most of the time those are the same. Not always.
A language model finishes sentences. It predicts each next word, and a bit of chance decides which.
Try it yourself
Be the predictor. Pick the next word, then see the chances.
Everything runs in your browser. Nothing you type is sent anywhere.
Use the free version of any chatbot. Don't type anything personal.
Ask a chatbot the same thing twice, in two new chats:
Write one sentence about a cat on a rainy day.What to expect. Two different sentences. Both fluent, both fitting.
What to look for. Where do they start to differ? Often after the first few words. From there, each answer follows its own path.
In practice
Three people are surprised by a chatbot. The predictor explains it.
Case 1Two different answers
Iris (12) asks a chatbot for a title for her talk about bees. She likes it, closes the app, and asks again later. She gets a different title.
Think the chatbot changed its mind, or that the first answer was wrong.
It has no mind to change. Each answer is a new string of predictions. Every pick has a bit of chance in it.
Ask for five titles at once. Pick the one you like and save it.
You use the variety on purpose. A predictor is a good idea machine.
Case 2The confident wrong answer
Mark (36) asks a chatbot how long his dog may be alone at home. It gives a clear, friendly answer with a clear number of hours.
Take the number as fact.
The predictor makes text that fits the question. A clear number fits well. Whether that number is right for his dog, it doesn't check.
Use the answer to know what to ask. Then check it with a vet or a reliable animal website.
The chatbot gives you the right questions fast. A source gives you the right answer.
Case 3"It understood my email"
Ans (63) pastes an angry email from a neighbour into a chatbot. It writes a calm, polite reply. Ans is amazed: "It understood exactly how I felt."
Send it as it is.
The predictor made a reply that fits angry emails in general. It doesn't know her neighbour, or what happened.
Use the reply as a draft. Change what doesn't fit, add what only she knows, and then send it.
The predictor gives a good start. Ans makes it true to the situation.
By situation
A language model writes fluent text about almost anything. That doesn't make it a source. For homework, use it to understand or to plan. Get facts from your book or a reliable website.
Language models are good at drafts: emails, summaries, a first version of a text. They don't know your company, your clients or yesterday's meeting unless you tell them. Check every fact before you send.
A chatbot can help with a letter or a recipe. Or with a question you'd rather not ask a person. Remember it predicts what fits. For health, money or legal questions, check with someone who knows.
Myths and mistakes
| Claim | True? | Why |
|---|---|---|
| A chatbot looks up the answer | No | It predicts the answer word by word. Some chatbots can search the web too, but they still predict the text. |
| A different answer means the first was wrong | No | Each answer is a new set of predictions. Both can be fine, or both can be wrong. |
| Fluent means correct | No | It predicts what fits, not what's true. |
| It plans the whole answer first | Not how it works | It predicts one word at a time, each time adding the last word to what it sees. |
Related topics
Read first
- What is AI?the predictor in one page.
Next
- Tokensthe pieces the predictor really predicts.
Related
- Hallucinationswhy it sometimes makes things up.
- A good prompthow to get the answer you need.
Sources
- explainerGoogle for Developers. LLMs: What's a large language model?.A language model predicts the next token, like a very large autocomplete. A token can be a word, part of a word or one character. Training needs a huge amount of text. Predictions often contain mistakes.
- documentationGoogle AI for Developers. Prompt design strategies.The model picks the next token with some chance, set by the 'temperature'. Low: more the same each time. High: more varied answers. Prompt advice: give clear and specific instructions, add context, include a few examples, say what format you want. Not the result you expected? Rephrase it; a good prompt often takes a few tries.
Test
You get 5 questions about the whole page. Get 4 right, and you've mastered the topic.
About the tools in this course. Every tool is described in the same way, in alphabetical order, without a recommendation. Names, prices and features change often: the maker's own site is always right. This site was built with the help of Claude, one of the tools described here.