Module 4 โ€“ How AI Learns
beginner15 XP

Training AI with Examples ๐ŸŽ“

See how AI learns from labelled examples โ€” just like how you learned to read

Training AI with Examples ๐ŸŽ“

Remember Learning to Read?

When you were tiny, someone showed you pictures and said words:

Code
๐Ÿ“ธ "CAT"    ๐Ÿ“ธ "DOG"    ๐Ÿ“ธ "CAR"
๐Ÿ“ธ "CAT"    ๐Ÿ“ธ "DOG"    ๐Ÿ“ธ "CAR"
... (repeated many, many times) ...
โ†’ You learned to recognize and read those words!

Training AI works EXACTLY the same way โ€” just with millions of examples instead of dozens!

The Training Process ๐Ÿ‹๏ธ

Code
Step 1: Show AI an example
        [Photo of cat] + label: "cat" ๐Ÿฑ

Step 2: AI makes a guess
        "I think this is... a dog?" ๐Ÿ• (Wrong!)

Step 3: Tell AI it's wrong
        "No! This is a cat!" 

Step 4: AI adjusts tiny numbers inside itself

Step 5: Try again with next photo
        [Photo of cat] + label: "cat"
        AI guesses: "cat?" ... "Yes!"

Step 6: Repeat 10,000,000 times
        โ†’ AI becomes GREAT at recognizing cats!

๐Ÿคฏ How Much Training Does AI Need?

AI SystemTraining Examples
Basic cat recognizer~10,000 photos
Face IDMillions of face photos
Self-driving carBillions of driving miles
ChatGPT570 GB of text (billions of sentences)

๐ŸŽฎ Real Example: Google's Cat Detector

In 2012, Google built an AI and showed it 10 million YouTube thumbnails without telling it what was in them.

The AI independently discovered that cats were one of the most common things in images online!

Nobody told it what cats were. It figured it out from PATTERNS alone. Mind-blowing! ๐Ÿคฏ

The Training Ingredients

Python
# Training data: examples WITH their labels (the right answers)
training_data = [
    {"ears": "pointy", "sound": "meow", "label": "cat"},
    {"ears": "pointy", "sound": "meow", "label": "cat"},
    {"ears": "floppy", "sound": "woof", "label": "dog"},
    {"ears": "pointy", "sound": "woof", "label": "dog"},
]

# A new animal the AI has never seen before
new_animal = {"ears": "pointy", "sound": "meow"}

# "Learning": each example that sounds the same gets a vote
votes = {"cat": 0, "dog": 0}
for example in training_data:
    if example["sound"] == new_animal["sound"]:
        votes[example["label"]] += 1

print("Votes:", votes)
print("My guess:", max(votes, key=votes.get))
# Real AI does this with photos and MILLIONS of examples!
โŒจ๏ธ

Type it yourself

Don't just read it โ€” type the example from above into the box, press Run โ–ถ, and watch what happens. Typing it yourself is how it really sticks! Stuck? Tap Show example.

Python ยท Playground
Output
Press โ–ถ Run to see your code come to lifeโ€ฆ

Quick check

01/3
How is training an AI similar to how you learned to recognize words as a child?