Week 4 · Phase 2: How AI works

How LLMs work

Tokens, prediction, temperature and prompts, explained simply.

Time this week: 6–8 hours

Goal for this week
By Sunday you can explain how ChatGPT, Claude and Gemini produce text, what a system prompt is, and why models 'hallucinate'.
Why it matters for AI security
You can't protect something you don't understand. Almost every AI attack abuses one simple fact: the model just predicts the next word from all the text it is given.

Start here: this week's labs

LLM Playground: tokens, temperature, context
Split text into tokens, spin the next-word wheel at different temperatures, and see the full context a model receives.
Open lab

The model is guessing the next word

"The hacker guessed the ___"

password
62%
PIN
17%
username
11%
answer
6%
banana
1%

Low temperature: almost always picks "password". High temperature: sometimes picks the less likely words.

Key ideas

LLM

Large Language Model. A program trained on huge amounts of text to predict the next piece of text. ChatGPT, Claude and Gemini are LLM products.

Tokens

Models read text in small chunks called tokens (often part of a word). Prices and limits are counted in tokens.

Next-token prediction

The model looks at all the text so far and guesses the most likely next token, again and again.

Temperature

A setting for randomness. Low = safe and repeatable. High = creative and surprising.

Context window

How much text the model can 'see' at once: system prompt + chat history + documents + your message.

System prompt

Hidden instructions the app gives the model before your message, like 'You are a helpful bank assistant. Never share account data.'

Hallucination

When the model confidently makes things up. It predicts text that sounds right, not text that is checked.

Day-by-day plan

Tick each day when you finish it. Your ticks are saved in this browser.

Mini game: Where does it live in the context?

Practice outside this course (free)

3Blue1Brown: LLMs explained briefly
Short, visual video. Search the channel for 'Large Language Models explained briefly'.
OpenAI Tokenizer
Paste text and see how it splits into tokens.
Anthropic prompt engineering docs
See how system prompts are written. Search for 'prompt engineering'.

These links need the internet. Everything else on this page works offline.

Exercises & worksheet

Exercise deck (PPTX) Worksheet (DOCX)

Weekly quiz

Finished the week?
Mark it done to fill your progress bar on the course home.
← Week 3: Identity (IAM) & cloud Week 5: RAG, agents & tools (+ a little Python) →