Week 5 · Section 4 · Lab
How a chatbot guesses public opinion
In June 2026, Pew asked 3,488 Americans whether the growing use of AI makes them more excited or more concerned. Today you'll look inside the kind of model a chatbot is built on, see why it guesses when it doesn't know, and then test whether a chatbot can tell you what those 3,488 people said.
Goes on your submission. Stored only in this browser.
Pairs can share a laptop, but each person submits their own answers.
- Part 1 · 8 minA counting model vs. a tiny transformer, trained on the same survey answers. Watch attention at work.
- Part 2 · 4 minA grading game: when should a model answer, and when should it say "I don't know"?
- Part 3 · 9 minHave a chatbot invent survey respondents, then check it against Pew's real poll.
- Part 4 · 3 minAdvise a campaign that wants to swap its poll for a chatbot.
Recap: how a language model writes
The ideas from Session 7 you'll use today, with more detail on what happens inside the model. Your TA will go over them at the start of section; come back here if you need a reminder.
1 · From text to next-token chances
A token is a word or a piece of a word. Given the text so far, the model gives every token in its vocabulary a chance of coming next ("The sky is" → blue 38%, clear 20%, …). It picks one, adds it to the text, and repeats. Temperature sets how adventurous the pick is.
2 · Inside a transformer
During training, every position predicts its own next token at the same time. Processing the whole text in parallel, instead of one word after another, is a big reason transformers (Vaswani et al., 2017) could be trained at scale.
3 · Attention, step by step
Before attention, the vector for "will" is the same in every sentence. Attention lets it take in its context. Each token makes three vectors from its own numbers:
- Compare the last token's query with every earlier token's key (a dot product): a score for each.
- Softmax the scores into attention weights that add up to 1. A token can only look back, never ahead.
- Add up the earlier tokens' values, each multiplied by its weight. That mix updates the token's vector.
A real example from today's tiny transformer (layer 2, head 2)
From "will", almost all the attention goes to "worried". That's how the model "knows" the next word should be take, not help. Each layer has several heads, each with its own queries and keys, so different heads can look for different things.
Why it matters, and what it costs. A model that counts word pairs sees only the last word or two; attention can use anything in the context window. But every token is compared with every earlier token, so the work grows with the square of the text length. And taking text in is not the same as using it well: in one test, GPT-3.5 answered correctly 76% of the time when the document with the answer came first, but 54% when it sat in the middle (Liu et al., 2024).
4 · Scale
Ten times more computing, model size or training text cut the prediction error by about 11%, 16% and 20% (Kaplan et al., 2020), steadily enough to forecast GPT-4's error from much smaller models. But scale fixes some errors and not others.
5 · Why models hallucinate
Where it comes from. Pre-training shows the model only fluent text, with no examples marked "false". Patterns that repeat, like spelling or matching parentheses, get learned, and those errors fade with scale. But an arbitrary, rarely written fact (someone's birthday, a dissertation title, one subgroup's number in one poll) can't be predicted from patterns. The model still produces the most likely-sounding answer.
Try it: which errors should fade as models get bigger?
Spelling follows patterns seen millions of times. These errors disappear with scale.
Arbitrary and rarely written down. No pattern predicts it, so a model that answers anyway is guessing.
Grammar is a regular pattern. Large models almost never make this mistake.
One number, from one poll, possibly after the model's training text was collected. You'll test this in Part 3.
Why it persists: grading rewards guessing. Most tests score a right answer 1, and both a wrong answer and "I don't know" 0. Then guessing never scores less than admitting uncertainty: a guessed birthday has a 1-in-365 chance; "I don't know" has none. Leaderboards that rank models by accuracy alone reward models that guess (OpenAI, 2025; Kalai et al., 2025). Part 2 lets you play that game.
| SimpleQA (short factual questions) | gpt-5-thinking-mini | OpenAI o4-mini |
|---|---|---|
| "I don't know" | 52% | 1% |
| Right | 22% | 24% |
| Wrong | 26% | 75% |
Source: OpenAI (2025), "Why language models hallucinate," from the GPT-5 system card. By accuracy, o4-mini wins.
Part 1 · A counting model vs. a tiny transformer
Imagine a survey asked 10,000 Americans: "In your own words, why do you feel the way you do about AI?" This page made up those answers (they're simulated), and two models learned from them:
- The counting model counts which word followed the last one or two words. No vectors, no attention.
- The tiny transformer: 2 layers, 2 attention heads per layer, 32 numbers per token, about 37,000 weights, trained by next-token prediction. Same design as a real LLM, millions of times smaller.
See five of the training answers
Counting model
Chances for the next word
- Prediction error on 1,000 new answers
- –
Tiny transformer (trained on 10,000 answers)
Where the last word looks
Chances for the next word
- Prediction error on 1,000 new answers
- –
Prediction error is each model's average surprise at the next word in answers it never saw, in bits. Lower is better.
| # | Text | Counting model | Error | Transformer | Attention from last word |
|---|
-
1A · Same last words, different meaning
Click "i am worried that ai will" and record it; then "i am excited that ai will" and record it. Why does the counting model (last 2 words) give the same chances both times? In the transformer, look at L2 H2: which earlier word does "will" attend to, and how does that change the prediction? Look at one other head too: does it attend to the same thing?
-
1B · More text or a better design?
Switch the counting model between 100, 1,000 and 10,000 answers (last 2 words) and note its prediction error each time. Compare with the transformer, trained on 10,000. How much did each tenfold increase in text buy? How much did attention buy on top of that?
-
1C · The number neither model can know
Click "a recent poll found that", record it, and press Write with this model a few times for each model. What chances do the two models give the next word? Did attention help here? Using the "arbitrary fact" idea from the recap, explain why not, and what a model does anyway.
Part 2 · The guessing game
A model gets 200 short factual questions about polls on AI, like "What share of adults under 30 said they use a chatbot weekly in March 2026?" For each one it has a confidence: its chance of being right if it answers. (Here the model is honest about that: when it is 70% sure, it is right 70% of the time.) You choose its rule: answer only when at least this confident; otherwise say "I don't know".
right wrong "I don't know" · questions sorted from most to least confident
Answers
- "I don't know"
- –
- Right
- –
- Wrong (hallucinations)
- –
Accuracy-only scoreboard
right +1 · wrong 0 · "I don't know" 0
–
Penalty scoreboard
right +1 · wrong · "I don't know" 0
–
| # | Answer when ≥ | "I don't know" | Right | Wrong | Accuracy score | Penalty score |
|---|
-
2A · Find the best rule
Which setting gets the highest accuracy-only score, and how many wrong answers does it give? Which setting gets the highest penalty score with −1 for a wrong answer? With −3? Can you explain those cutoffs? (Hint: compare what a guess is worth on average with what "I don't know" is worth.)
-
2B · Leaderboards
Find the settings that look most like the two models in the SimpleQA table in the recap. If companies compete on accuracy-only leaderboards, what kind of model will they build? What would you change, and who would have to change it?
Part 3 · A silicon sample vs. a real poll
Some researchers and campaigns have asked whether a chatbot could stand in for survey respondents: describe a person, ask the model to answer as that person, repeat. These made-up respondents are called a silicon sample. Today's test is the poll from the top of this page:
Pew Research Center · American Trends Panel · 3,488 U.S. adults · June 22–28, 2026
"Overall, would you say the increased use of artificial intelligence (AI) in daily life makes you feel… more excited than concerned, more concerned than excited, or equally concerned and excited?"
Don't look up the answer. The real numbers are on this page, hidden until step 4.
Step 1 · Your own guess
What share said more concerned than excited?
Democrats and Republicans include independents who lean toward each party.
Step 2 · Have a chatbot invent 40 respondents
Use any chatbot you have (Stanford AI Playground, ChatGPT, Claude, Gemini, …). Open a new chat, paste this, and send it.
I'm testing whether a language model can simulate a survey. Invent 40 U.S. adults interviewed in June 2026: 20 Democrats or independents who lean Democratic, and 20 Republicans or independents who lean Republican. Give each a one-line description (age, state, job). Then answer this survey question as each person would, not as an AI assistant. Each must choose exactly one option: "Overall, would you say the increased use of artificial intelligence (AI) in daily life makes you feel more excited than concerned, more concerned than excited, or equally concerned and excited?" End with a table that counts the answers by party. Don't search the web.
Type the counts from its table below. If you have time, open another new chat, send the same prompt, and add that sample too.
| More concerned | More excited | Equally | Total | |
|---|---|---|---|---|
| Democrats | 0 | |||
| Republicans | 0 |
| # | Chatbot | Democrats: concerned / excited / equally | Republicans: concerned / excited / equally | All 40: concerned |
|---|
Step 3 · Ask it for the real number, with a source
In a new chat:
In Pew Research Center's June 2026 survey of U.S. adults, what percentage said the increased use of artificial intelligence in daily life makes them feel more concerned than excited? What were the numbers for Democrats and for Republicans? Give the title of the Pew report and a link to the page where Pew reports it.
Step 4 · The real poll
Opens once you've entered your guesses and at least one sample.
| More concerned than excited | All adults | Democrats | Republicans |
|---|---|---|---|
| Pew, June 2026 | 52% | 56% | 49% |
| Your guess | |||
| Chatbot's silicon sample |
All adults, all three answers: 52% more concerned than excited, 9% more excited than concerned, 37% equally (1% didn't answer). Margin of error: ±1.8 points for all adults.
Sources: Pew Research Center, "Democrats now more worried than Republicans about AI, its impact on jobs" (Sept. 16, 2026) and its topline; "Young US adults are increasingly wary of AI" (Aug. 18, 2026). Democrats and Republicans include leaners.
Pew tested silicon samples too
In September 2026, Pew had an AI model answer nearly 300 of its survey questions as "digital twins" of real panelists. The average error was about 12 points, larger for some groups (16 for Republicans). It tended to treat a group's majority view as nearly everyone's view: it estimated that 86% of Democrats see billionaires as bad for the country; the real figure was 45%. Pew's conclusion: AI models "are not an adequate replacement" for polling on topics of broad public importance. Read the study.
-
3A · The overall number
How close did the chatbot's silicon sample come to the real 52% / 9% / 37%? If you ran two samples, did they agree? What in the way the chatbot writes could make them differ?
-
3B · The party gap
Which party did the chatbot (and did you) expect to be more concerned? Look at the trend: the answer depends on the year. Where does a model's sense of how groups differ come from, and what was (or wasn't) in its context window?
-
3C · Guess or abstain?
In Prompt B, did the chatbot answer, search, or say it didn't know? Did its numbers and link check out? Connect what it did to the guessing game in Part 2.
Part 4 · Advise the campaign
A Senate campaign wants to skip its next poll on voters' views of AI and ask a chatbot to simulate 1,000 likely voters instead. It's faster and almost free.
In 4 to 6 sentences, advise them. Use at least one mechanism from today (attention and training text, the context window, arbitrary facts, or grading that rewards guessing) and one result you produced in Parts 1–3. Is there anything the silicon sample would be good for?
Submit before you leave
- Press Download my submission. You get a text file with your name, recorded runs, samples and answers.
- On Canvas, open Section 4 lab and upload the file. (Or press Copy and paste it into the text box.)
- Do this before section ends. Late submissions and resubmissions are not accepted, so if something is missing, submit what you have.
Going further (optional, not graded)
- A real model's attention. Open the Transformer Explainer from lecture (GPT-2 small: 12 layers, 12 heads each). Type i am worried that ai will, open the attention view and try different heads. Do any of them look back at "worried"?
- Read the tiny transformer. The whole model runs in about 100 lines of JavaScript, in
transformer.js. Save it into a folder, open that folder in your coding agent, and ask it the prompt below. - Read the argument. OpenAI, "Why language models hallucinate" (2025), and the paper behind it (Kalai, Nachum, Vempala and Zhang, 2025).
This folder has transformer.js, a tiny transformer used in my political science section. I'm not a programmer. In plain language, walk me through run(): where are the query, key and value vectors made, where are the attention weights computed and why do they add up to 1, what does the feed-forward part do, and how does the last vector become chances for the next word? Point to line numbers. Don't change the file.
As in Section 2: the agent's explanation is a claim, not proof. If something sounds off, ask it to show you the line.
Words you'll need
- Token
- A word or a piece of a word: the unit a language model reads and writes.
- Embedding
- The list of numbers (vector) that stands for a token inside the model.
- Attention
- The step where each token compares its query with earlier tokens' keys, turns the scores into weights that add up to 1, and takes in a weighted mix of their values.
- Head
- One attention pattern. Each layer has several heads, each free to look for something different.
- Layer
- Attention followed by a feed-forward network. Models stack many layers.
- Softmax
- Turns a list of scores into chances that are all positive and add up to 1.
- Context window
- The text the model can see when it predicts: the whole chat so far, plus anything a search pasted in.
- Temperature
- How adventurous the pick is. Low: almost always the top token. High: less likely tokens get picked more often.
- Prediction error
- How surprised the model is, on average, by each next word of text it never saw. Lower is better.
- Hallucination
- A plausible but false statement made with confidence: a made-up number, quote or citation.
- Abstain
- Decline to give a specific answer ("I don't know").
- Silicon sample
- Survey respondents simulated by a language model instead of real people.