Chapter 1 of 1 · Free, no signup

Support Us

Generative AI & LLM Engineering · Chapter 1 · ~15 min · No maths needed

What an LLM Actually Is — Inside the Next-Token Machine

ChatGPT, Claude and Gemini feel like magic. Underneath, they do one simple thing again and again: guess the next small piece of text. Play with the machine and you'll understand AI better than most people who use it daily.

  • Explain an LLM in one sentence
  • See text split into tokens
  • Control randomness with temperature
  • Estimate cost & context limits

1Super-powered autocomplete

Your phone keyboard suggests the next word. A Large Language Model (LLM) is the same idea, trained on a huge slice of the internet and books so its guesses are amazingly good. It never “looks up” an answer — it writes one, piece by piece.

The

Loop: read everything so far → guess the next piece → stick it on the end → repeat. Step 1 of 8.

Real-world picture: a very well-read friend finishing your sentence. Brilliant at sounding right — but they can still confidently guess wrong.

How does an LLM produce a long answer?

2Tokens: the pieces the model reads

Models don't see letters or whole words. They see tokens — common chunks of text. “the” is one token; a rare word like “unbelievably” may be three. Type below and watch it slice.

Hello·world!·Tokenization·is·unbelievably·important.

14 pieces · 52 characters · “·” marks a space that belongs to the token. Common words stay whole; rare long words get chopped.

Rule of thumb for English: 1 token ≈ 4 characters ≈ ¾ of a word. Code, emoji and many non-English languages use more tokens. Count real tokens with the AI Token Counter.

Roughly how many tokens is a 400-character English paragraph?

3Probabilities & the temperature dial

For every step the model gives each possible token a score, turned into percentages. Then it picks one. Temperature decides how adventurous that pick is. Drag it and roll the dice several times.

The cat sat on the ___

mat
68%
sofa
17%
floor
12%
roof
3%
moon
1%
Balanced
0 – 0.3

Data extraction, code, facts. Same input → nearly same output.

0.5 – 1.0

Chat and writing help. Natural but sensible.

1.2+

Brainstorming, poems. Surprising — and more mistakes.

You need the model to extract invoice numbers into JSON reliably. Which temperature?

4Context window & cost

The context window is the model's short-term memory: your prompt + chat history + its answer must fit inside. You also pay per token — both what you send in and what it writes back. Slide to feel the numbers.

Context window used (128K tokens)4%
Tokens per request
5,400
Cost per request
$0.0031
Cost per day
$3.10

Example prices: $0.50 per million input tokens, $1.50 per million output tokens (~500 tokens per page).

Output tokens usually cost more than input tokens. Short, clear prompts and asking for concise answers save real money. Compare providers with the LLM API Cost Calculator.

Why might a chatbot ‘forget’ the start of a very long conversation?

5What LLMs are great — and bad — at

Great at

  • Writing, summarising, rewriting
  • Explaining & generating code
  • Turning messy text into structured JSON
  • Translation & tone changes

Watch out for

  • Hallucinations: confident made-up facts
  • No knowledge after its training cutoff
  • Exact maths & counting letters (tokens hide them!)
  • Your private data it has never seen
Small prompt changes can change answers a lot. Test two prompt versions side by side with Prompt Diff.

6Chapter challenge

Next-token machine check

Answer all four correctly to complete the chapter.

0 / 4 correct
  1. 1Which sentence best describes an LLM?

  2. 2Why do LLMs often miscount the letter ‘r’ in “strawberry”?

  3. 3Raising temperature from 0.2 to 1.5 will…

  4. 4Your 900-page manual doesn't fit the context window. Best next step?

7Recap

  • An LLM is super-powered autocomplete: predict a token, append, repeat.
  • Tokens are text chunks — about 4 English characters each.
  • Temperature controls randomness: low for facts/code, higher for creativity.
  • The context window limits what the model can see; you pay for input and output tokens.
  • LLMs can hallucinate — always verify important facts.

Solve the challenge above to complete the chapter, or

Enjoying this free lesson? Your support helps us build more free animated chapters.

Support Us