🧠 How AI Works

See how signals move through a neural network, train a tiny model, and try a toy next-word predictor, step by step

πŸ”¬ Step 1: Meet the Neural Network

A neural network is a computer program inspired by the human brain. It has layers of connected "neurons" that pass information to each other. Watch the network below β€” each dot is a neuron, and each line is a connection. (This picture is an animation to show the idea; its glow is not real math.)

Input Layer (left): This is where data enters the network β€” like pixels of an image, words in a sentence, or numbers.
Hidden Layers (middle): These layers find patterns in the data. Each neuron looks for a specific feature. With more layers, the network can find more complex patterns.
Output Layer (right): This is the network's answer β€” its prediction or classification. For example: "This is a cat" or "This email is spam."

πŸ“Š Step 2: Train the AI with Data

AI learns from examples, just like you learn from practice. Click the items below to choose labeled examples for a small computer model. It will use them to decide which new things are fruits and which are NOT fruits.

Select at least 4 items to start training

🔮 Step 4: A Toy Next-Word Predictor

Chatbots are built on language models, which estimate which word is likely to come next. This toy does a tiny version of that idea by hand: it counts which word follows which in the sample sentences below. It is a toy, not an AI. Real language models are huge neural networks trained on enormous amounts of text, and they look at far more than one word back.

Nothing you type leaves your browser or is saved. Use a period to end each sentence.

Pick a first word
Pick a first word to begin.

🎲 Roll the dice picks a word at random, but words seen more often get picked more often. Always taking the most likely word can get stuck in a loop (“the cat sat on the cat sat on…”), which is one reason real systems add some randomness. Try making a few sentences. Some will be new sentences that were never in the samples, some will be silly, and some may be untrue. The toy only knows word order, not meaning, which is one reason real chatbots can sound sure while being wrong.

🎯 AI Knowledge Quiz

Test what you learned about how AI works!

What Happens on This Page

The page has four parts, and it helps to know what each one really is before you teach with it.

  • Step 1, the network picture. An animation of a neural network with 4 input nodes, two hidden layers of 6 and an output layer of 3. Press Activate and the glow moves left to right, the way information flows through a real network. The brightness values are random, so treat it as a diagram that moves, not a working network.
  • Step 2, choosing training data. Pick at least 4 of the 12 items. Each item is already labeled fruit or not fruit, and each is described to the computer by three yes/no facts: grows on a plant, people eat it, made by people.
  • Step 3, testing. The model sorts seven new items it has never seen. It finds the (up to) three training examples whose facts are closest and goes with the majority. This method is called k-nearest neighbors. It is a real machine learning technique, simple enough to follow by hand.

Step 4, the toy next-word predictor. It reads a short set of sample sentences (students can edit them), counts which word follows each word, and builds a sentence one word at a time, either taking the most common next word or rolling weighted dice. Google's Machine Learning Crash Course describes a language model as something that "estimates the probability of a token or sequence of tokens," and uses counted word sequences called N-grams as the first example. This toy is a 2-word N-gram counter. It is labeled a toy because it is one: no neural network, no AI service, a few lines of JavaScript.

Things to notice with Step 4: the toy can produce sentences that never appeared in its samples ("the dog ate the fish"), some of which are untrue. Add a new sentence and the counts change at once. That is the core idea behind chatbots, scaled down: they predict likely words from their training text, which is why they can be fluent and still wrong.

A quiz with eight questions sits at the bottom. After each answer, press Next; at the end you see your score and can play again.

Worked Example: Following the Model by Hand

Say a student picks Apple, Banana, Car and Book. Now test Lemon. Lemon's facts are yes, yes, no (plant, eaten, not made by people). Compare with each example by counting how many facts differ:

ExampleFactsDifferences from Lemon
Appleyes, yes, no0
Bananayes, yes, no0
Carno, no, yes3
Bookno, no, yes3

The three closest are Apple, Banana and one of the others. Two of three say fruit, so the model answers "Fruit (2 of 3 closest examples agree)." That is the whole algorithm: measure similarity, look at the closest examples, vote.

Now test Carrot. Its facts are also yes, yes, no, so the model says fruit and gets it wrong. Nothing is broken. The model was never given a fact that separates fruits from vegetables (in botany, a fruit grows from a flower and holds seeds). That is a useful conversation for a class: whoever chooses the features decides what the machine can notice.

How Real Neural Networks Learn

A neural network is made of layers of simple units. Each connection has a number called a weight. Data goes in at the input layer, every unit combines what it receives using those weights, and an answer comes out at the output layer. Training starts with random weights. The network makes a guess on a labeled example, measures how wrong it was, and nudges the weights to be a little less wrong. The method that works out how much to change each weight is called backpropagation. Repeat that over a very large number of examples and the network gets good at its task.

Google's Machine Learning Crash Course describes neural networks as models built to find nonlinear patterns in data, made of nodes, hidden layers and activation functions, trained with backpropagation. The AI4K12 guidelines put the same idea in kid language as Big Idea 3: computers can learn from data. AI4K12 also notes that learning usually needs very large amounts of training data, usually supplied by people.

Three Kinds of Machine Learning

  • Supervised learning uses labeled examples, like this page's fruit and not-fruit items, or photos tagged "cat."
  • Unsupervised learning looks for groups and patterns in data that has no labels, such as grouping customers with similar shopping habits.
  • Reinforcement learning learns by trial and error from rewards. Game-playing systems that improve by playing many games against themselves use it.

Misconceptions to Watch For

  • "The AI understands what fruit is." The model on this page only compares three numbers. Large AI systems are far more capable, but they still learn statistical patterns from data, and they can be confidently wrong.
  • "More examples always fix it." Picking all 12 items still won't fix the carrot, because the problem is the features, not the amount of data.
  • "A neural network is a computer brain." Neural networks were loosely inspired by brain cells, but they work very differently from a brain.
  • "Computers are neutral." A model repeats whatever patterns are in its data. In MIT's 2018 Gender Shades study, three commercial face-analysis programs misclassified the gender of lighter-skinned men no more than 0.8% of the time, but got it wrong for darker-skinned women 20.8% to 34.7% of the time.

Try These in Class

  1. Fruit only. Train with four fruits and no other items. Predict before testing: what will the model say about the key?
  2. One of each. Train with just Apple and Car (plus two more). Does the model still get Lemon and Clock right? Why?
  3. Fix the carrot. On paper, invent a fourth fact (for example, "has seeds inside") and fill it in for every item. Would the model now tell carrots from fruit?
  4. Unplugged version. Give each student a card with three yes/no facts about a mystery object. Classmates vote by finding the most similar cards on the board.

Next, let students label their own examples in Train a Classifier, or see the full set of activities on the AI Literacy hub.

Framework alignment

AI4K12 Big Idea 3 (Learning: computers can learn from data) and Big Idea 5 (Societal Impact). These are guidelines from AAAI and CSTA, not numbered standards.

How AI Works: FAQ

Is the network at the top of the page actually learning?

No. The glowing network in Step 1 is an animation that shows how signals pass from layer to layer. Its numbers are random. The real learning on this page happens in Steps 2 and 3, where a small nearest-neighbor model uses the examples you pick to sort new items.

Why does the model call a carrot a fruit?

Because it only knows three facts about each item: does it grow on a plant, do people eat it, and is it made by people? A carrot has the same three answers as an apple, so the model can't tell them apart. Real AI systems make the same kind of mistake when their data leaves out the information that matters.

What happens if I only pick fruit as examples?

Try it. With no 'not fruit' examples, the model has never seen anything else, so it calls everything a fruit, even a key. This shows why training data has to include every kind of thing the system will meet.

Do ChatGPT and other chatbots work like this?

They also learn from examples, but at an enormous scale. Large language models are neural networks with billions of adjustable weights, trained on huge amounts of text to predict the next word. The small model here has no weights at all; it just compares features. Both depend completely on their data.

Does this page send anything to an AI service?

No. Everything runs in your browser with a few lines of JavaScript. Nothing you click or type is uploaded or saved, and there is no login.

Is the next-word predictor in Step 4 a real chatbot?

No. It is a toy that counts which word follows which in a few sample sentences, then picks the next word from those counts. Real language models do a far bigger version of next-word prediction with neural networks trained on huge amounts of text. The toy shows the basic idea, including why fluent output can still be untrue.

Sources

Last reviewed: November 2026 Β· AI4K12 Big Ideas 3 and 5

🌟 Keep Exploring
πŸ’»Binary Numbers πŸ§ͺTrain a Classifier πŸ€–AI vs Human πŸ“–Parent Guide: AI Literacy