---
id: how-generative-ai-works
lang: en
title: "How generative AI works"
seoTitle: "How generative AI works, in plain words"
description: "A plain look under the hood: how a language model is trained, what tokens are, why AI sometimes makes things up, and where it shines or fails at work."
part: foundations
partTitle: "Foundations"
partOrder: 1
order: 2
level: Beginner
durationMinutes: 7
outcome: "Describe in simple terms how a model produces text, and predict where it will do well or fail."
summary: "Generative AI works by predicting the next chunk of text, over and over, from patterns it learned in training. That is why it is fluent, and why it sometimes makes things up."
draft: false
updated: "2026-07-26"
furtherReading:
  - title: "Large language model (Wikipedia)"
    url: "https://en.wikipedia.org/wiki/Large_language_model"
    note: "how models like Claude and ChatGPT are built and trained."
  - title: "Generative artificial intelligence (Wikipedia)"
    url: "https://en.wikipedia.org/wiki/Generative_artificial_intelligence"
    note: "the wider family of tools that make text, images, and code."
  - title: "AI hallucination (Wikipedia)"
    url: "https://en.wikipedia.org/wiki/Hallucination_%28artificial_intelligence%29"
    note: "why models sometimes state false things with full confidence."
  - title: "Introduction to Generative AI (Google Skills)"
    url: "https://www.skills.google/paths/118"
    note: "a beginner path from the fundamentals of language models to responsible use."
keywords:
  - how generative AI works
  - large language model
  - what are tokens
  - AI hallucination
  - how AI is trained
  - next word prediction
quiz:
  intro: "Four quick questions. Ace all four and the next lesson unlocks."
  passScore: 4
  questions:
    - q: "At its core, what is a language model actually doing when it writes?"
      options:
        - "Looking up the answer in a database"
        - "Predicting the next chunk of text, over and over, one piece at a time"
        - "Copying the closest sentence it was trained on"
        - "Searching the live web for every word"
      answer: 1
      explain: "That is the engine. It predicts the next token, adds it, and repeats. Everything clever grows out of that one loop."
    - q: "What is a \"token\"?"
      options:
        - "A password the model needs to run"
        - "A chunk of text (a short word or part of a word) that the model reads and writes in"
        - "A coin you spend to send a message"
        - "The name of the model"
      answer: 1
      explain: "A token is a piece of text, often about three-quarters of a word. Models read and write in tokens, not letters."
    - q: "Why does a model sometimes state something false with total confidence (a \"hallucination\")?"
      options:
        - "It is lying on purpose"
        - "It is a prediction machine, not a fact database, so it fills a gap with text that looks right"
        - "Its internet connection dropped"
        - "It only happens with very old models"
      answer: 1
      explain: "It predicts plausible text. When it has no solid pattern to lean on, the most plausible-looking answer can still be wrong."
    - q: "Which task should you trust the least without checking?"
      options:
        - "Rewriting your email to sound warmer"
        - "Summarising a document you pasted in"
        - "Giving a specific statistic, date, or quote from memory"
        - "Brainstorming ten name ideas"
      answer: 2
      explain: "Specific facts pulled from memory are the danger zone. Verify names, numbers, dates, and quotes against a real source."
  pass:
    badge: "Perfect score"
    title: "You've seen under the hood."
    body: "Full marks. You know what the model is really doing, why it slips, and where to keep your guard up. That judgement is worth more than any single trick."
  retry: "Check the marked answers and give it another go. You've got this."
---

> **Level:** Beginner · **Reading time:** ~7 min
>
> **What you'll be able to do:** describe, in plain words, how a model produces text, and predict where it will do well and where it will trip.

The first time Claude writes you a clean email in four seconds, it feels like it *understands* you. It doesn't, not the way a person does. And once you see what it is really doing, you stop being fooled by it and start being good with it. That is the whole point of this lesson: not to make you an engineer, but to give you the mental model that separates people who trust AI blindly from people who use it well.

No maths ahead. Just the idea underneath.

## The one thing it does: guess the next word

Here is the engine, stripped to the metal. **A language model predicts the next chunk of text, then does it again.**

That's it. You give it some words, it works out the most likely next word, adds it, then looks at everything so far and works out the *next* next word, and on and on until the answer is done. It is autocomplete on your phone, grown up and gone to university.

Type *"the capital of France is"* and it will almost certainly say *"Paris"*, because in everything it ever read, that is overwhelmingly what came next. Type *"thanks for your email, I'll get back to you"* and it can carry on in a hundred sensible ways, so it picks one that fits. **The model is not fetching a stored answer. It is building the sentence forward, one likely step at a time.**

<figure class="lesson-svg" aria-labelledby="predict-title">
<svg viewBox="0 0 640 240" width="100%" height="auto" role="img" xmlns="http://www.w3.org/2000/svg" font-family="Inter, system-ui, sans-serif">
<title id="predict-title">Predicting the next word, one step at a time</title>
<desc>A sentence being built left to right. After "The capital of France is" the model weighs candidate next words and picks the most likely, Paris, then continues.</desc>
<text x="0" y="24" font-size="20" font-weight="800" fill="var(--ink,#1F2328)">One word at a time</text>
<rect x="0" y="44" width="392" height="46" rx="10" fill="var(--part-tint,#FDECE7)" stroke="var(--part,#F26440)"/>
<text x="16" y="73" font-size="16" font-weight="700" fill="var(--part-ink,#C33F1F)">The capital of France is&#8230;</text>
<text x="0" y="122" font-size="13.5" fill="var(--med-gray,#5B6169)">The model weighs what could come next:</text>
<rect x="0" y="136" width="140" height="34" rx="8" fill="var(--part,#F26440)"/>
<text x="70" y="158" font-size="14" font-weight="700" fill="#fff" text-anchor="middle">Paris &#160;92%</text>
<rect x="150" y="136" width="140" height="34" rx="8" fill="#fff" stroke="var(--line,#E7E9EC)"/>
<text x="220" y="158" font-size="14" fill="var(--med-gray,#5B6169)" text-anchor="middle">a city&#160; 4%</text>
<rect x="300" y="136" width="150" height="34" rx="8" fill="#fff" stroke="var(--line,#E7E9EC)"/>
<text x="375" y="158" font-size="14" fill="var(--med-gray,#5B6169)" text-anchor="middle">beautiful&#160; 2%</text>
<text x="0" y="206" font-size="13.5" fill="var(--soft-gray,#6E747C)">It picks the likeliest, adds it, then predicts the next word from the new sentence. Repeat.</text>
</svg>
</figure>

Sounds almost too simple to be useful. The surprise of the last few years is that when you do this with a big enough model that has read enough text, "predict the next word" stops looking like a party trick and starts looking like reasoning. To predict the next word in a legal clause, a recipe, or a Python function *well*, the model has to have soaked up a great deal about how the world is put together. Depth comes out of that simple loop, not from some separate "thinking" part.

## Where the smarts come from: training

So how does it know that "Paris" is the likely word? It **learned patterns from an enormous amount of text**: books, articles, websites, code, conversations. Not a tidy list of facts, but the raw stuff of how humans write.

Picture reading more than any person could in a thousand lifetimes, with one job: get better and better at guessing the hidden next word. Cover a word, guess it, check the real answer, nudge yourself when wrong. Do that billions of times and you slowly absorb grammar, tone, facts, arguments, the shape of a good email and a working formula. That long, one-off process is **training**, and it is where nearly all the cost and computing power go.

Two things follow that matter every day at work:

**Its knowledge has an end date.** Training finishes at some point, so the model's built-in knowledge stops there. Ask about something after that cut-off and, unless it can search the web, it is guessing from before. (Some tools, including Claude, can look things up live. That is a bolt-on, not the model's memory.)

**It learned patterns, not a filing cabinet.** The model did not save the pages it read. It distilled them into a sense of what usually follows what. That is why it can write about *your* situation, which appears in no book, and also why it cannot always pull back an exact fact on demand. Hold on to that second point. It explains the next section.

## Tokens: how it reads and writes

One quick piece of plumbing, because the word shows up everywhere. Models don't read letter by letter, or quite word by word. They work in **tokens**: chunks of text, often about three-quarters of a word. "Cat" is one token. "Unbelievable" might be three ("un", "believ", "able"). A rough rule: **100 tokens is about 75 words.**

Why should you care? Tokens are the unit for three things you will bump into:

- **Limits.** A model can only hold so many tokens at once (its "context window", the star of a later lesson). That cap is in tokens, not pages.
- **Cost.** If you use AI through an API or a paid tier, you often pay per token, in and out. Longer prompts and longer answers cost more.
- **Speed.** The model writes one token at a time, which is why you watch answers stream in rather than land all at once.

You will almost never count tokens by hand. But when someone says "it ran out of context" or "that was a lot of tokens", now you know they mean chunks of text, and roughly how many.

## Why it sometimes makes things up

This is the most important part of the lesson, so here it is in one line: **a model is a prediction machine, not a fact database, and it will confidently produce text that looks right but isn't.** The polite word for this is a **hallucination**.

It helps to see *why* it happens, because then you can predict it. The model's whole drive is to produce plausible next words. Usually plausible and true line up, because true things are what it mostly read. But when it has no strong pattern to lean on, an obscure fact, a specific figure, a court case, a citation, it does not stop and say "I don't know". It does what it always does: it generates the most plausible-looking text. And a made-up statistic or a fake but believable book title can look *extremely* plausible. Fluent and wrong at the same time.

The tell is confidence. A hallucination doesn't arrive hedged and nervous. It arrives in the same calm, well-written voice as everything true the model says, which is exactly what makes it dangerous. **Never read fluency as proof.**

<figure class="lesson-svg" aria-labelledby="hall-title">
<svg viewBox="0 0 640 320" width="100%" height="auto" role="img" aria-labelledby="hall-title hall-desc" xmlns="http://www.w3.org/2000/svg" font-family="Inter, system-ui, sans-serif">
<title id="hall-title">A confident answer that is completely made up</title>
<desc id="hall-desc">A chat mockup. The user asks for a specific figure from a named report. Claude replies in a calm, fluent voice with an exact statistic, but a warning note shows the report does not exist. Caption: fluent is not the same as right.</desc>
<text x="616" y="20" font-size="11" font-weight="700" fill="var(--med-gray,#5B6169)" text-anchor="end">You</text>
<rect x="300" y="26" width="324" height="58" rx="14" fill="var(--part,#F26440)"/>
<text x="316" y="52" font-size="13" fill="#fff">What&#8217;s the exact figure from</text>
<text x="316" y="72" font-size="13" fill="#fff">the 2021 Harman Report?</text>
<text x="16" y="108" font-size="11" font-weight="700" fill="var(--med-gray,#5B6169)">Claude</text>
<rect x="16" y="114" width="470" height="120" rx="14" fill="var(--part-tint,#FDECE7)" stroke="var(--part,#F26440)" stroke-width="1.5"/>
<text x="34" y="140" font-size="13" fill="var(--ink,#1F2328)">The 2021 Harman Report put the</text>
<text x="34" y="162" font-size="13" fill="var(--ink,#1F2328)">average at 42.7%, up from 38.1%</text>
<text x="34" y="184" font-size="13" fill="var(--ink,#1F2328)">the year before, driven mainly</text>
<text x="34" y="206" font-size="13" fill="var(--ink,#1F2328)">by faster onboarding.</text>
<rect x="16" y="246" width="470" height="40" rx="10" fill="#FCEBEA" stroke="#E7B9B2" stroke-width="1.5"/>
<circle cx="38" cy="266" r="9" fill="#C1121F"/>
<text x="38" y="270" font-size="12" font-weight="800" fill="#fff" text-anchor="middle">!</text>
<text x="56" y="270" font-size="12.5" font-weight="700" fill="#C1121F">Fluent, calm, and completely invented.</text>
<text x="16" y="310" font-size="12.5" font-style="italic" fill="var(--soft-gray,#6E747C)">Fluent is not the same as right.</text>
</svg>
</figure>

None of this makes the tool broken. It makes it a tool with a known failure mode, like a very fast, very well-read assistant who would rather give you *an* answer than admit a blank. Once you expect that, you manage it: ask for sources, paste in the real document instead of trusting memory, and check anything specific. The next section sorts the safe jobs from the risky ones.

## What it's brilliant at, and where to take care

Generative AI is not equally good at everything. Match the task to the tool and it feels like a superpower. Hand it the wrong kind of job unchecked and it burns you. The split follows straight from how it works.

<figure class="lesson-svg" aria-labelledby="fit-title">
<svg viewBox="0 0 640 330" width="100%" height="auto" role="img" xmlns="http://www.w3.org/2000/svg" font-family="Inter, system-ui, sans-serif">
<title id="fit-title">What generative AI does well, and where to take care</title>
<desc>Two columns. On the left, tasks it is great at: rewriting and drafting, summarising text you give it, explaining, brainstorming, translating, formatting. On the right, handle with care: specific facts from memory, exact numbers and maths, recent events, legal or medical calls.</desc>
<text x="0" y="24" font-size="20" font-weight="800" fill="var(--ink,#1F2328)">Match the task to the tool</text>
<rect x="0" y="42" width="310" height="272" rx="14" fill="var(--part-tint,#FDECE7)" stroke="var(--part,#F26440)"/>
<text x="20" y="72" font-size="16" font-weight="800" fill="var(--part-ink,#C33F1F)">Great at</text>
<text x="20" y="104" font-size="13.5" fill="var(--ink,#1F2328)">Rewriting, drafting, shortening</text>
<text x="20" y="134" font-size="13.5" fill="var(--ink,#1F2328)">Summarising text you give it</text>
<text x="20" y="164" font-size="13.5" fill="var(--ink,#1F2328)">Explaining an idea simply</text>
<text x="20" y="194" font-size="13.5" fill="var(--ink,#1F2328)">Brainstorming and first drafts</text>
<text x="20" y="224" font-size="13.5" fill="var(--ink,#1F2328)">Translating and changing tone</text>
<text x="20" y="254" font-size="13.5" fill="var(--ink,#1F2328)">Structuring and formatting</text>
<text x="20" y="290" font-size="12.5" font-style="italic" fill="var(--soft-gray,#6E747C)">Language work: its home turf.</text>
<rect x="330" y="42" width="310" height="272" rx="14" fill="#fff" stroke="var(--line,#E7E9EC)"/>
<text x="350" y="72" font-size="16" font-weight="800" fill="var(--ink,#1F2328)">Handle with care</text>
<text x="350" y="104" font-size="13.5" fill="var(--med-gray,#5B6169)">Specific facts from memory</text>
<text x="350" y="134" font-size="13.5" fill="var(--med-gray,#5B6169)">Exact numbers and maths</text>
<text x="350" y="164" font-size="13.5" fill="var(--med-gray,#5B6169)">Recent events (past cut-off)</text>
<text x="350" y="194" font-size="13.5" fill="var(--med-gray,#5B6169)">Quotes, citations, sources</text>
<text x="350" y="224" font-size="13.5" fill="var(--med-gray,#5B6169)">Legal, medical, money calls</text>
<text x="350" y="254" font-size="13.5" fill="var(--med-gray,#5B6169)">Anything you can't check later</text>
<text x="350" y="290" font-size="12.5" font-style="italic" fill="var(--soft-gray,#6E747C)">Useful here too, but verify.</text>
</svg>
</figure>

Notice the pattern. It is **strongest when the raw material is in front of it**: rewrite this, summarise that, turn these notes into an email, explain this paragraph. There is little to invent, so little to get wrong. It is **weakest when you ask it to recall something specific from memory**, because that is exactly when it might smoothly fill a gap.

So the working rule for the rest of your AI life: **let it do the language, and you own the facts.** Give it the source instead of trusting its memory. Ask it to show where an answer came from. Double-check every number, name, date, and quote before it leaves your hands. Do that and hallucinations shrink from a scary flaw to a manageable quirk.

And a reassuring note: the tools are getting better at this. Newer models make things up less, hedge more honestly when unsure, and can cite sources or search the web. The skill of checking never goes out of date, but you are not fighting the tool. You are steering it.

## Try it

Ask a chatbot a factual question with a precise answer: a specific statistic, a date, the author of a particular book, the population of a mid-sized town. Then check it against a real source (an official site, a reference you trust).

Do this two or three times. Sometimes it nails it. Sometimes it is confidently off. Either way you are training the instinct that matters most with these tools: **treat a fluent answer as a strong draft to verify, never as the final word.** That habit alone will save you from ninety percent of the trouble people get into with AI.

*(General exercise. Role and industry versions come once accounts are in.)*

## Key terms

[Large language model](/glossary#large-language-model), [Token](/glossary#token), [Training](/glossary#training), [Hallucination](/glossary#hallucination), [Context window](/glossary#context-window)
