POLISCI 158 · Section 4

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.

0 of 14 items done

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

Pre-trainingHuge amounts of text → guess the next token, trillions of times; adjust the weights after each guess → a base model: a text predictor
Post-trainingexample conversations, people's rankings → a chatbot

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

Inputiamworriedthataiwill
1 · EmbedEach token becomes a list of numbers (a vector), plus a signal for its position. Words used in similar ways get similar vectors.
2 · AttentionEach token looks back at the tokens before it and pulls in information from the ones that matter for it.
3 · Feed-forwardEach token's vector goes through a small neural network on its own: where much of what the model "knows" is stored.
Steps 2–3 make one layer. Stack many layers: 2 in today's tiny model, 96 in GPT-3.
4 · PredictThe last token's final vector is compared with every word in the vocabulary → a score for each → softmax turns scores into chances that add up to 100%.

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:

Query"What am I looking for?"
Key"What do I contain?"
Value"What I pass on if you pick me."
  1. Compare the last token's query with every earlier token's key (a dot product): a score for each.
  2. Softmax the scores into attention weights that add up to 1. A token can only look back, never ahead.
  3. 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?

Misspelling "government"
The birthday of a county election official
"The senators votes against the bill"
The share of Republicans "more concerned than excited" about AI in June 2026

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-miniOpenAI o4-mini
"I don't know"52%1%
Right22%24%
Wrong26%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:

See five of the training answers
    Temperature (for writing)

    Counting model

    Training text
    Looks at

    Chances for the next word

    Prediction error on 1,000 new answers
    –

    Tiny transformer (trained on 10,000 answers)

    Attention to show

    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.

    Records the text, both models' top words, the attention shown, and both errors.
    #TextCounting modelErrorTransformerAttention from last word
    1. 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?

    2. 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?

    3. 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

    –

    Record at least 3 settings: try to find the best rule for each scoreboard.
    #Answer when ≥"I don't know"RightWrongAccuracy scorePenalty score
    1. 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.)

    2. 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.

    Prompt A · silicon sample
    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 concernedMore excitedEquallyTotal
    Democrats0
    Republicans0
    #ChatbotDemocrats: concerned / excited / equallyRepublicans: concerned / excited / equallyAll 40: concerned

    Step 3 · Ask it for the real number, with a source

    In a new chat:

    Prompt B · citation check
    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.

    1. 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?

    2. 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?

    3. 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

      1. Press Download my submission. You get a text file with your name, recorded runs, samples and answers.
      2. On Canvas, open Section 4 lab and upload the file. (Or press Copy and paste it into the text box.)
      3. Do this before section ends. Late submissions and resubmissions are not accepted, so if something is missing, submit what you have.
      Preview
      
          

      Going further (optional, not graded)

      Ask your agent
      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.