…
…
AI Fundamentals · Lesson 18 / 31 · Language models
PreviewIn this lesson you will
You can read the explanation without an account. The exercises and quiz at the end of the lesson are for members.
Elena asks two questions at the help desk: "If we ask the assistant 'when do dorm applications close' and never give it the Student Handbook, will it know? And what if we paste the whole 80-page regulation?" The answers to both questions are hidden in how the assistant was trained.
In lesson 17 you built a count table from five short announcement sentences and predicted the next word from it. The assistant at the desk does the same job at a very large scale. That scale decides what the assistant knows and what it can never know. At the end of this lesson you will fill in the table below for the ten questions that come to the desk. For now it is empty.
| Question | Can it know? (yes / no / if given a document) | Why? | What do I do? |
|---|---|---|---|
| 1. When do dorm applications close? | ? | ? | ? |
| 2. On which day is the scholarship paid this semester? | ? | ? | ? |
| 3. What is the password rule in Ms. Rivera's email from yesterday? | ? | ? | ? |
| 4. Why is the campus network down today? | ? | ? | ? |
| 5. What are the enrollment freeze conditions in the 80-page regulation? | ? | ? | ? |
| 6. What is an enrollment letter, and what is it for? | ? | ? | ? |
| 7. What is a scholarship, and why is it given? | ? | ? | ? |
| 8. How much does a Block A dorm room cost? | ? | ? | ? |
| 9. What does course add/drop mean? | ? | ? | ? |
In this lesson you will:
A language model is built in two stages. The first stage is called pretraining. The model first reads a very large pile of text: books, encyclopedia entries, forum posts, public web pages. At every position it asks the same question: "Which word comes next?" It guesses, then looks at the real word in the text. If it was wrong, it adjusts its weights a little. This is exactly the error-reducing loop from lesson 16; the only difference is that billions of weights are adjusted at the same time instead of one. The model splits text into words and word pieces; for simplicity we will keep saying "word".
Now put the order of this loop together yourself.
Put the pretraining loop in order.
Click the lines in order; to undo one you placed wrong, click it in the list below.
Shuffled lines
Your order
Let's picture the scale by comparing it with the toy model from lesson 17.
Example 1 (outside the case): Toy model and large model
| The toy model from lesson 17 | A large language model | |
|---|---|---|
| Text it reads | 5 short announcement sentences | Thousands of times more text than a person could read in a lifetime |
| What it learns | Counts of 15 word pairs | Billions of weights |
| The question it asks | "What comes after this word?" | The same question, looking at a much longer history |
When pretraining ends, what is left inside the model? There is a very common misunderstanding here. People think the model keeps the books it read on a shelf and opens the right page when a question arrives. That is not how it works. The model stores not the texts themselves but the patterns in them, inside its weights: which words come together, how sentences are built, how a topic is usually explained. When you finish a novel, you also remember the story and the most repeated lines, not every sentence.
When pretraining ends, what is inside the model?
Some tools also search the internet before writing an answer. Such a tool shows clearly that it searched, and even then you open and read the page it found. The model itself does not look the answer up; it produces the answer from its weights.
The model that comes out of pretraining only knows how to continue text. When you ask it a question, it may write the continuation of a text in which the question appears instead of answering, because in the forums it read, a question is often followed by more questions and comments. This is why the second stage exists: chat adaptation. People write example questions and good answers, and they also mark which of two answers the model gave to the same question is more helpful. From these examples the model learns to answer "like a helpful assistant". The technical names for this stage are fine-tuning and reinforcement learning from human feedback; you do not need to know these names, only what they do.
Example 2 (case): The same prompt, two stages
Fictional output, a model with pretraining only (prompt: "When do dorm applications close?"):
OutputWhen do dorm applications close? anyone know? I am also wondering,
last year...Fictional assistant output, the adapted model (same prompt):
OutputDorm applications usually close before the semester starts. For the exact
date, I suggest you check your institution's announcements.The first output looks like the continuation of a forum thread; the second is an assistant's answer. The second stage makes the difference. An important consequence is hidden here: adaptation also teaches the model to speak politely, in an orderly way, and with confidence. The principle you saw in lesson 4, "fluency is not accuracy", has its root here. The confident tone comes from adaptation; it does not show that the content is correct.
Match each behavior with the stage it comes from.
For each row, pick its match from the list, then check.
The pile of text closes one day. Say the texts were collected up to March; the model was then trained for weeks and released. An announcement published in April never entered the pile. Nothing that happened after the cut is in the model's weights: new announcements, changed fees, yesterday's match score.
The second kind of gap is sneakier: private information. This semester's Student Handbook, the email Ms. Rivera sent yesterday, and your own course notes were never published. Whatever the cutoff date, they never entered the pile of text. "I have this information, so the model must know it too" is therefore a wrong thought.
The real danger is this: when the model is asked something it does not know, it often does not say "I do not know". It writes a plausible answer, built from patterns that are common in similar texts, in the confident tone it learned in adaptation. In the three examples below, both the Handbook lines and the assistant outputs are fictional sample data written for this lesson.
Example 3 (case): A payment day updated after training
Fictional assistant output (prompt: "On which day are scholarship payments made this semester?"):
OutputScholarship payments reach your account on the 1st of each month.Student Handbook line g-08: "Scholarship payments are made on the 15th of each month." The payment day was updated after training, and it is institution-specific information anyway. The assistant states a wrong day without hesitation; this answer is rejected.
Example 4 (case): An email that was never published
Fictional assistant output (prompt: "What was the new password rule in the email Ms. Rivera sent yesterday?"):
OutputAccording to the email, new passwords must be at least 12 characters and
include a special character. You need to change your password every 90 days.The assistant never saw the email; it has no way to see it. It built a plausible text from general password rules and started it with "according to the email". This is rejected too; the answer is taken from the email itself.
Example 5 (case): An answer that states its uncertainty
Fictional assistant output (prompt: "For how many semesters can I freeze my enrollment?"):
OutputThis varies from institution to institution and I cannot know the current
rule; I suggest you check the Student Services regulations. At many
institutions the limit is around two semesters.This is a good answer: it says it cannot know and points to the right source. Handbook line g-11 also says two semesters, so the answer is accepted. But such an answer does not always come. Example 3 and Example 5 came from the same assistant.
Let's try the knowledge cutoff with a small program. The code compares two months: the last month the texts were collected and the month the announcement was published. Change the values and look at the output.
Change the month training ended and the month the announcement was published. When can the announcement be in the model's texts?
Pick a value; predict the output first, then look.
1training_ended = "March"2announcement_month = "February"34months = ["January", "February", "March", "April", "May", "June",5 "July", "August", "September", "October", "November", "December"]67if months.index(announcement_month) <= months.index(training_ended):8 print("The announcement can be in the training texts.")9else:10 print("The announcement was published after training: the model cannot know it.")
The announcement can be in the training texts.
Faded lines didn't run with this value. If the announcement was published in or before the month training ended, it can be in the pile of text; if it was published later, the model cannot know it. "Can be" is not the same as "knows": the model can still remember an announcement that appeared once wrongly (remember the prediction question in the pretraining section).
Now let's think about what would have happened if the answer in Example 3 had left the desk.
The assistant told a student, "Scholarship payments reach your account on the 1st of each month." The student writes to the desk: "The assistant said so, the 1st has passed and I have no money!" What do you do?
Pick an option and see what happens. There are no points; you can try the other options too.
Back to Elena's second question: what if we paste the whole regulation? When the assistant writes an answer, it looks at the text in front of it: your prompt, the document you pasted, and the conversation so far. This text has a limit. The limit on how much text the model can see at the same time while writing an answer is called the context window. Whatever falls outside the limit does not exist for that answer.
This says two things. The first is good news: if you give the document in the prompt, the cutoff and private information problems are largely solved, because the information is now inside the window. The second is a warning: the window is big but not endless. A very long text may not fit, and even when it fits, details in the middle of a very long text can be missed. In a long conversation, the instruction at the very start can be forgotten too. "If I paste a long document, it reads all of it and takes all of it into account" is therefore a wrong thought.
Example 6 (toy window): A 27-word announcement
In the program below, the announcement has 27 words; we counted punctuation marks as separate words. The window takes words from the end of the text backwards: the part the model read last. Change the window value and check whether the date is visible. True in the output means "yes" and False means "no".
Set the window to 12, 20, and 30 words. When is the date (September 12) visible?
Pick a value; predict the output first, then look.
1text = ("Dorm applications end September 12 . Applications need ID , photo and "2 "proof of income . Results are on the board . Ask the help desk .")3window = 1245# 1. Split the text into words6words = text.split()7# 2. Take the last `window` words8visible = words[-window:]9# 3. Check whether the date is visible10print("The model sees:", " ".join(visible))11print("Is the date visible?", "September" in visible)
The model sees: . Results are on the board . Ask the help desk . Is the date visible? False
Faded lines didn't run with this value. With a window of 12 or 20 words, the date is not visible because it sits at the start of the text; the model cannot state the date by looking at this announcement. A window of 30 words takes the whole text. Real windows are thousands of words long; the toy only shows the idea: whatever does not enter the window does not exist for that answer.
What should you do? Give the document in the prompt. If it is very long, select only the relevant section, or split the text into parts and ask about each part separately. In a long conversation, repeat the important instruction.
Now you can look at any question with three checks:
1. Could this information have changed or become new after training?
2. Is it unpublished, personal, or institution-specific information?
3. Does the text needed for the answer fit in the window?
If either of the first two is "yes", check the source or give the document in the prompt. If the text does not fit, select the relevant section or split it. If all are clear, the question is general knowledge and the model can help; you still need the verification step you will learn in lesson 23.
Example 7 (outside the case): Trip planning
| Question | Check | What do I do? |
|---|---|---|
| The museum's opening hours this month? | May have changed after training | I check the museum's official page |
| My friend's wedding date? | Private information | I ask my friend |
| The best route according to a whole 300-page guidebook? | May not fit in the window | I select the chapter for the city and give that |
| Why did the Renaissance start in Italy? | General knowledge | I use it and compare it with sources |
Match each question with its situation from the assistant's point of view.
For each row, pick its match from the list, then check.
One last check: does giving a document solve everything?
You pasted the whole Student Handbook into the assistant and asked for the Block A dorm fee. Which is correct?
The most common mistake in this lesson is to assume "the assistant will say so if it does not know" and take current dates from it. Example 3 showed the opposite: the assistant stated a day it could not know in a confident sentence. The rule for the desk is this: for date, fee, and rule questions, the assistant is used only if the Student Handbook is given in the prompt, and the answer is compared with the line in the Student Handbook before it is sent. The one who sends the answer to the student is still the desk.
The table at the start of the lesson is now filled in:
| Question | Can it know? | Why? | What do I do? |
|---|---|---|---|
| 1. When do dorm applications close? | If given a document | Private information (institution-specific) | I give the Student Handbook in the prompt; g-03: September 12 |
| 2. On which day is the scholarship paid this semester? | If given a document | After training (updated) | I check the Student Handbook; g-08: the 15th of each month |
| 3. What is the password rule in Ms. Rivera's email from yesterday? | No | Private information | I look at the email itself |
| 4. Why is the campus network down today? | No | After training (today) | I check the IT unit's announcement |
| 5. What are the enrollment freeze conditions in the 80-page regulation? | If given a document | Long text | I select the relevant section and give it, or split it |
| 6. What is an enrollment letter, and what is it for? | Yes | General knowledge | I use it; I add where to get it from g-12 |
Of the ten questions, the assistant can answer three by itself, can never know three, and can answer four only if you give it the right document.
Fictional assistant output (prompt: "Why is the campus Wi-Fi not working today?"):
OutputThere is planned maintenance on the Wi-Fi this week and it will last until
Friday evening. I suggest you download your course notes in advance during
this time.Today's outage is something that happened after training. The assistant cannot know about a maintenance notice; "Friday evening" is a made-up date. The answer is rejected; the student is shown the IT unit's announcement page.
A student pastes a whole 60-page term paper. The structure of the prompt is:
Output[at the very start] Format instruction: headings numbered, each section at most two pages.
[in the middle] 60-page paper text
[at the very end] Did you follow the format instruction I gave at the start?The instruction stayed at the very start of the text; in a very long text it can be missed, and the text may not fit in the window at all. A better way: rewrite the instruction together with the question and give the paper in sections.
This time the dorm section of the Student Handbook is inside the prompt. Fictional assistant output (prompt: the dorm section of the Student Handbook + "How much does Block B cost per month?"):
OutputAccording to the text you gave, Block B (four-person room) costs $145 a month.The answer rests on the document in the window and refers to it. Still, before sending it you look at line g-04: Block B is $145, Block A is $210. The number and the block are right; the answer is accepted. The document reduced the risk, and you made the final check.
Thinking "the assistant will say so if it does not know" and taking current or institution-specific information from it.
OutputPrompt: On which day are scholarship payments made this semester?
Fictional assistant output: Scholarship payments reach your account on the 1st of each month.
Student Handbook g-08: Scholarship payments are made on the 15th of each month.Adaptation teaches the assistant to speak with confidence; it writes a date it cannot know in the same confident tone. The right way: look at the question with the three checks (after training, private, fits in the window); if one applies, check the official source or give the document in the prompt, and compare the answer with the line.
Next lesson: The assistant can make up what it does not know when asked; in the next lesson we will see why and how to catch it.
Exercises and quiz are for members
This lesson has 6 coding exercises and a 10-question quiz. Sign up free to solve them, save your progress and move on to the next lesson.
| 10. What was decided at yesterday's student club meeting? |
| ? |
| ? |
| ? |
| 7. What is a scholarship, and why is it given? |
| Yes |
| General knowledge |
| I use it and compare it with a source |
| 8. How much does a Block A dorm room cost? | If given a document | Private information (institution-specific) | I give the Student Handbook and compare with line g-04 |
| 9. What does course add/drop mean? | Yes | General knowledge | I use it; I add the period from g-05 |
| 10. What was decided at yesterday's student club meeting? | No | Private information, after training | I ask the person who wrote the meeting notes |