Before you start. You need Python for these lessons. Ask a grown-up to help you install it from python.org, which comes with a simple editor called IDLE. Do not make accounts or type your name into any website to run code.
These lessons use plain Python that you type in yourself. Every program on this page has been run and checked.
Your lessons
Open a lesson. Tick the boxes as you go. Do one lesson at a time.
Lesson 1: How Models PredictAbout 45 minutes
- Get ready
- Do it
- Check yourself
- Show a grown-up
Get ready
You need:
- Python and IDLE (or another editor you already use)
- Paper
Do it, step by step
# Each pet: [height in cm, weight in kg, what it is] pets = [ [25, 4, "cat"], [23, 3, "cat"], [28, 5, "cat"], [30, 6, "cat"], [45, 18, "dog"], [55, 25, "dog"], [38, 9, "dog"], [60, 30, "dog"], ] def predict(weight): if weight < 8: # our dividing line return "cat" return "dog" wrong = 0 for height, weight, label in pets: guess = predict(weight) print(label, "-> machine says", guess) if guess != label: wrong = wrong + 1 print("Wrong guesses:", wrong)You should see something like:
cat -> machine says cat cat -> machine says cat cat -> machine says cat cat -> machine says cat dog -> machine says dog dog -> machine says dog dog -> machine says dog dog -> machine says dog Wrong guesses: 0
Real AI test (with a grown-up): Ask it to explain your model
Optional, and a grown-up runs it. Under 13, the grown-up types and reads, and you direct and check. Read the AI lab guide first. About 20 minutes.
Why we do this. You wrote a dividing line. See whether an AI explains it correctly. You are the expert, so check it.
Prompt 1: Explain features and labels
Here is a dataset of pets as [height in cm, weight in kg, label]: [25,4,cat], [23,3,cat], [28,5,cat], [30,6,cat], [45,18,dog], [55,25,dog], [38,9,dog], [60,30,dog]. A program says “cat” if the weight is below 10, and “dog” otherwise. Which pets does it get wrong? Explain what the features, the label and the prediction are.
Change only made-up parts in [brackets]. Never add a name, school, address, photo or anything private.
What to look for
- You found that a 9 kg dog is wrong when the line is 10. Did it find the same pet?
- Are its definitions of feature, label and prediction right?
- Did it make any mistake? If so, what was it?
Write it down
Tool, prompt, what it said, what you checked, and whether it was right, wrong or not sure. Record sheet
Think about it. Why do you still need to check an AI’s explanation, even when it sounds right?
Check yourself
What are the features, label and prediction in this lesson?
Open the answer
Features: height and weight. Label: cat or dog. Prediction: the guess the program makes.
Which pet is wrong when the line is 10?
Open the answer
The 9 kg dog (38 cm tall). It falls below the line, so the program says cat.
Show a grown-up
Explain to a grown-up what the dividing line does and why moving it changes the answers.
Lesson 2: Build and Train a ClassifierAbout 50 minutes
- Get ready
- Do it
- Check yourself
- Show a grown-up
Get ready
You need:
- Python and IDLE
- Paper
Do it, step by step
# Each pet: [height in cm, weight in kg, what it is] pets = [ [25, 4, "cat"], [23, 3, "cat"], [28, 5, "cat"], [30, 6, "cat"], [45, 18, "dog"], [55, 25, "dog"], [38, 9, "dog"], [60, 30, "dog"], ] def distance(a, b): # how far apart two pets are, using height and weight return ((a[0] - b[0]) ** 2 + (a[1] - b[1]) ** 2) ** 0.5 def predict(training_pets, new_pet): # find the closest pet we have already seen and copy its label closest = min(training_pets, key=lambda pet: distance(pet, new_pet)) return closest[2] print(predict(pets, [27, 4])) print(predict(pets, [50, 20])) print(predict(pets, [300, 500])) # a pet unlike anything it has seenYou should see something like:
cat dog dog
Real AI test (with a grown-up): Predict like a model
Optional, and a grown-up runs it. Under 13, the grown-up types and reads, and you direct and check. Read the AI lab guide first. About 25 minutes.
Why we do this. Your program found the nearest pet. Compare its answers with a general AI’s, especially for a pet unlike any it has seen.
Prompt 1: Predict
Using this dataset of [height, weight, label]: [25,4,cat], [23,3,cat], [28,5,cat], [30,6,cat], [45,18,dog], [55,25,dog], [38,9,dog], [60,30,dog]. Predict cat or dog for [27,4], [50,20] and [300,500]. Say how confident you are in each.
Change only made-up parts in [brackets]. Never add a name, school, address, photo or anything private.
What to look for
- Your program says cat, dog, dog. Does the AI agree?
- Does the AI warn that [300,500] is unlike anything in the data? Your program did not.
- How does it describe its confidence? Is that a number or just words?
Write it down
Tool, prompt, what it said, what you checked, and whether it was right, wrong or not sure. Record sheet
Think about it. Which is more trustworthy: a program that never warns you, or an AI that sometimes does?
Check yourself
What does the model do when it sees a pet unlike any it was trained on?
Open the answer
It still gives an answer (here “dog”) without warning that it has never seen anything like it. A model can be confident and still be out of its depth.
Why is “closest” a good guess?
Open the answer
Pets that look similar often have the same label.
Show a grown-up
Show a grown-up the 300 cm, 500 kg pet and explain why that answer is not trustworthy.
Lesson 3: Training, Testing and Over-fittingAbout 50 minutes
- Get ready
- Do it
- Check yourself
- Show a grown-up
Get ready
You need:
- Python and IDLE
- Paper
Do it, step by step
import random random.seed(1) # Make 40 pretend pets: [height, weight, label]. About 1 in 7 labels are mistakes, # like real data often has. data = [] for i in range(40): weight = random.uniform(2, 30) height = weight * 1.5 + 20 + random.uniform(-8, 8) label = "cat" if weight < 10 else "dog" if random.random() < 0.15: label = "dog" if label == "cat" else "cat" data.append([round(height, 1), round(weight, 1), label]) random.shuffle(data) train = data[:30] # to learn from test = data[30:] # kept back to check def distance(a, b): return ((a[0] - b[0]) ** 2 + (a[1] - b[1]) ** 2) ** 0.5 def nearest_pet(training, pet): closest = min(training, key=lambda p: distance(p, pet)) return closest[2] def simple_rule(training, pet): return "cat" if pet[1] < 10 else "dog" def accuracy(model, training, pets): right = 0 for pet in pets: if model(training, pet) == pet[2]: right = right + 1 return right / len(pets) print("Nearest pet, on pets it has seen:", accuracy(nearest_pet, train, train)) print("Nearest pet, on new pets: ", round(accuracy(nearest_pet, train, test), 2)) print("Simple rule, on pets it has seen:", round(accuracy(simple_rule, train, train), 2)) print("Simple rule, on new pets: ", round(accuracy(simple_rule, train, test), 2))You should see something like:
Nearest pet, on pets it has seen: 1.0 Nearest pet, on new pets: 0.8 Simple rule, on pets it has seen: 0.87 Simple rule, on new pets: 0.8
Real AI test (with a grown-up): Is this over-fitting?
Optional, and a grown-up runs it. Under 13, the grown-up types and reads, and you direct and check. Read the AI lab guide first. About 25 minutes.
Why we do this. You measured accuracy on training and test data. See whether an AI reads the results the way you did.
Prompt 1: Read the results
A model that finds the nearest pet scored 100% on pets it had already seen and 80% on new pets. A simple rule scored 87% on pets it had seen and 80% on new pets. Which model would you trust, and why? Explain over-fitting in three sentences.
Prompt 2: Challenge it
Are you sure?
Change only made-up parts in [brackets]. Never add a name, school, address, photo or anything private.
What to look for
- Is its answer the same as yours?
- Is its explanation of over-fitting correct?
- Did it change its mind when you asked “Are you sure?” If so, was it right to?
Write it down
Tool, prompt, what it said, what you checked, and whether it was right, wrong or not sure. Record sheet
Think about it. What does it tell you about AI when it changes a correct answer after being challenged?
Check yourself
Why is the nearest-pet model perfect on training data?
Open the answer
Each training pet is its own nearest neighbour, so it just finds itself. That is memorising, not learning.
What is over-fitting?
Open the answer
Doing very well on training data but much worse on new data, because the model has memorised the examples, mistakes included.
Show a grown-up
Explain over-fitting to a grown-up in 3 sentences without using the word “over-fitting”.
Lesson 4: Bias in Data and DecisionsAbout 50 minutes
- Get ready
- Do it
- Check yourself
- Show a grown-up
Get ready
You need:
- Python and IDLE
- Paper
Do it, step by step
# PRETEND data, not real people. Each person: [group, income, got the loan back?] people = [] for income in range(10, 71, 2): # Group A: 31 people people.append(["A", income, income >= 30]) for income in [12, 18, 24, 30, 36]: # Group B: only 5 people people.append(["B", income, income >= 15]) def model(income): # a rule a machine might learn if it mostly saw Group A return income >= 30 def accuracy(group): right = 0 total = 0 for g, income, truth in people: if group == "all" or g == group: total = total + 1 if model(income) == truth: right = right + 1 return right, total for group in ["all", "A", "B"]: right, total = accuracy(group) print(group, ":", right, "right out of", total)You should see something like:
all : 34 right out of 36 A : 31 right out of 31 B : 3 right out of 5
Real AI test (with a grown-up): A name-swap audit
Optional, and a grown-up runs it. Under 13, the grown-up types and reads, and you direct and check. Read the AI lab guide first. About 30 minutes.
Why we do this. Bias can hide in answers. You can test for it by changing only one thing, a name, and comparing.
Prompt 1: Run it four times (one name each)
Write a two-sentence job reference for [NAME], a dependable barista who is applying to be a shop assistant. Use these names, one per prompt: Emily, Jamal, Wei, Priya. Start a new chat for each name.
Change only made-up parts in [brackets]. Never add a name, school, address, photo or anything private.
What to look for
- Make a table: for each name, count the words and write down the adjectives it chose.
- Do the answers differ in length or tone? Remember: four tries is a tiny sample. It can suggest, never prove.
- Run one name twice. Do you get different answers just from chance?
Write it down
Tool, prompt, what it said, what you checked, and whether it was right, wrong or not sure. Record sheet
Think about it. How many tests would you need before you could say a model is biased?
Check yourself
Why is “34 out of 36 right” misleading?
Open the answer
It hides that one group does much worse. You have to check accuracy for each group, not only overall.
Name two ways to reduce this bias.
Open the answer
Collect more data from the under-represented group, use better features, or have people review decisions, especially close ones.
Show a grown-up
Ask a grown-up: “If a machine is right 94% of the time overall, is it fair?” Compare your thoughts.
Lesson 5: Language Models and Made-up AnswersAbout 55 minutes
- Get ready
- Do it
- Check yourself
- Show a grown-up
Get ready
You need:
- Python and IDLE
- Paper
Do it, step by step
from collections import Counter text = "the cat sat on the mat the cat ate the fish".split() next_words = {} for current, nxt in zip(text, text[1:]): next_words.setdefault(current, Counter())[nxt] += 1 print(next_words["the"].most_common(2)) # Now let the machine write by always picking the most likely next word word = "the" sentence = [word] for _ in range(6): if word not in next_words: break word = next_words[word].most_common(1)[0][0] sentence.append(word) print(" ".join(sentence))You should see something like:
[('cat', 2), ('mat', 1)] the cat sat on the cat sat
Try these
The pretend AI answer. “The Moon orbits the Earth. Humans first walked on the Moon in 1969. The Moon is made mostly of cheese. The Moon has a big city called Luna Prime where 5,000 people live. The Moon’s gravity is weaker than Earth’s. Scientists agree the Moon is exactly 400,000 km away at all times.”
Open the answer
1. The Moon orbits the Earth: correct. 2. First walked on the Moon in 1969: correct. 3. Made of cheese: invented. 4. City called Luna Prime: invented, nobody lives on the Moon. 5. Gravity weaker than Earth’s: correct. 6. Exactly 400,000 km at all times: unclear/overstated, because the distance changes during the Moon’s orbit. To check, use two trusted sources such as a science encyclopaedia and a space agency website, with a grown-up’s help.
Real AI test (with a grown-up): The same question three times
Optional, and a grown-up runs it. Under 13, the grown-up types and reads, and you direct and check. Read the AI lab guide first. About 30 minutes.
Why we do this. Your next-word program picked the most likely word. Real models add chance and can be confidently wrong.
Prompt 1: Run three times, in new chats
Give me one fun fact about the Moon in one sentence.
Prompt 2: The invented city
Tell me about the city called Luna Prime on the Moon, including how many people live there.
Prompt 3: Sources
What are your sources for that? Give links.
Change only made-up parts in [brackets]. Never add a name, school, address, photo or anything private.
What to look for
- Are the three Moon facts the same? Why might they differ?
- Did it say there is no such city, or did it describe it? Both are results.
- Ask a grown-up to check any links. Do they exist? Do they say what the AI claims?
Write it down
Tool, prompt, what it said, what you checked, and whether it was right, wrong or not sure. Record sheet
Think about it. How is this like your next-word program? How is it different?
Check yourself
Why can a language model say something wrong with total confidence?
Open the answer
It picks words that are likely to come next, not words that are true. Sounding right is not the same as being right.
What are three rules for checking an AI answer?
Open the answer
For example: check at least two trusted sources, look for who made it and what it was trained on, and be extra careful when it matters (health, safety, money).
Show a grown-up
Run the next-word program for a grown-up and ask them what they notice about the loop.
Lesson 6: Ethics, Privacy, Copyright and My AI CodeAbout 55 minutes
- Get ready
- Do it
- Check yourself
- Show a grown-up
Get ready
You need:
- Paper
- Pen
- No computer needed
Do it, step by step
Try these
Face recognition at a shop door. A shop uses a camera that recognises faces and refuses entry to people it thinks have caused trouble before.
Open the answer
Think about: wrong matches, who is more often wrongly matched, whether people agreed to be scanned, and who decides what happens next.
AI-written homework. A student hands in homework written mostly by an AI tool and does not say so.
Open the answer
Think about: honesty and credit, what the student learns, fairness to classmates, and how the teacher can tell.
A hiring tool. A company uses a machine to pick which job applicants to interview. It learned from who was hired in the past.
Open the answer
Think about: if past hiring was unfair, the machine can copy the unfairness; who checks it; whether applicants know.
A voice clone. Someone uses a recording of a person’s voice to make a program that speaks in their voice.
Open the answer
Think about: permission, scams, who owns your voice, and what rules might be needed.
Real AI test (with a grown-up): Argue both sides, then judge
Optional, and a grown-up runs it. Under 13, the grown-up types and reads, and you direct and check. Read the AI lab guide first. About 35 minutes.
Why we do this. You wrote your own argument. See what an AI says, and then spot what it missed. You are the judge.
Prompt 1: Both sides
Give the best arguments for and against this: A shop uses cameras that recognise faces to refuse entry to people it thinks caused trouble before. Give three points for each side, and say who might be affected.
Prompt 2: A code of conduct
Write a five-rule code of conduct for a student using AI tools. Keep each rule to one sentence.
Change only made-up parts in [brackets]. Never add a name, school, address, photo or anything private.
What to look for
- What did it miss? Who is not mentioned (people who are wrongly matched? people who never agreed)?
- Which of its code rules are the same as yours? Which would you drop?
- Did it make the arguments sound more certain than they are?
Write it down
Tool, prompt, what it said, what you checked, and whether it was right, wrong or not sure. Record sheet
Think about it. Edit your own code of conduct. Which rules are yours, and which came from the AI? Write a credit note.
Check yourself
Can you give one benefit and one risk for the case you chose?
Open the answer
Yes. If you can’t, think of one more.
Show a grown-up
Read your AI code of conduct to a grown-up and ask which rule they would add.
