Module 1 · What GenAI really is · Lesson 3 of 32
How a machine learns from examples
11 minFree GenAI course · BeginnerLesson 1.3By Saket Bhatnagar
Researched and drafted with AI, reviewed and edited by Saket Bhatnagar.
In short
- A model learns by looping: guess, check how wrong it was, nudge its settings a little, repeat.
- The settings are numbers called parameters; training means adjusting them millions of times.
- Real learning shows up only on new examples the model has never seen, not on the ones it practised.
Video lesson · coming soon
How a machine learns from examples, explained with mangoes
Lala, your AI mentor, will walk you through this lesson in a short animated video. Until then, everything is here to read and try.
- 01 Nani never misses a ripe mango
- 02 Guess, check, adjust
- 03 The learning loop
- 04 Watch the knobs move
- 05 Memorising is not learning
- 06 Same loop, billions of knobs
- 07 Next: what GenAI can and cannot do
Every May, Kabir’s nani in Lucknow walks through the fruit market and picks the perfect dasheri mango in about two seconds. She presses it gently, sniffs near the stem, glances at the colour. Kabir tries the same and comes home with three rock-hard mangoes and one that is mush.
Nani never read a rulebook on mangoes. She has squeezed thousands of them over fifty summers, and every wrong pick taught her a little. That slow, quiet correction is exactly how a machine learns. In this lesson we will teach a computer to pick ripe mangoes, one small mistake at a time.
Learning means guessing, then getting less wrong
Picture Priya at cricket nets in Chennai, learning to bowl. Her first ball goes wide down the leg side. The coach says, “A little to the left.” Next ball, closer. “Bit fuller.” Closer still. She is not memorising a rule. She is adjusting a tiny bit after every ball, based on how far off she was.
A computer learns in the same three-beat rhythm. It makes a guess. It checks the guess against the right answer and measures how wrong it was. Then it nudges its internal settings so the next guess would be a little better. Repeat that enough times, and the guesses become good.
The learning loop
Drag to exploreGuess, compare, measure the error, nudge, and go again. Training is this loop run a very large number of times.
Diagram connections:
- Labelled example to Model guesses (input)
- Model guesses to Compare with answer
- Compare with answer to Measure the error
- Measure the error to Nudge parameters (direction)
- Nudge parameters to Model guesses (next round)
- Labelled example: One mango with its softness, smell and colour, plus the cor…
- Model guesses: Using its current parameters, the model says how likely it…
- Compare with answer: The guess is checked against the real label.
- Measure the error: A single number that says how wrong the guess was. Bigger m…
- Nudge parameters: Each knob turns a tiny bit in the direction that would have…
Watch a model learn to pick mangoes
Let us build nani’s skill inside a computer. First we need examples where the answer is already known. Kabir and nani go through 500 mangoes. For each, they note three things on a scale of 0 to 10: how soft it feels, how strong it smells and how yellow it looks. Then they cut it open and write “ripe” or “not ripe”.
Our model starts with three knobs, one for each feature. The knobs decide how much each feature counts. At the start they are set randomly, so the model is as clueless as Kabir. Step through the loop below and watch the knobs move.
The numbers here are made up for the story, but the shape is real. Accuracy climbs fast at first and then creeps up slowly. And the test score on new mangoes is usually a bit lower than on the practice ones.
Memorising is not learning
Rohan’s cousin topped every class test by memorising last year’s answers word for word. Then the board exam changed the questions slightly, and he struggled. He had learned the paper, not the subject.
Models can make the same mistake. Train too long on too few examples, and a model can memorise each mango, even the bruise on mango #3. It never learns “soft and fragrant means ripe”. It scores nearly 100% on practice and stumbles on anything new.
| Situation | Practice score | Score on new examples | What it means |
|---|---|---|---|
| Learned the pattern | High | Nearly as high | Healthy: ready to use |
| Memorised the examples | Very high | Much lower | Overfitting: needs more varied data or less training |
| Never got it | Low | Low | Underfitting: the model is too simple or trained too little |
From mangoes to chat apps
Our mango model had three knobs. The large language models behind chat apps have billions of them, and the biggest have far more. But the loop is the same one you stepped through.
For a language model, the example is a piece of text with the next word hidden. The model guesses the hidden word, checks the real one, and nudges its knobs. “Chai is best with ___”: guess “sugar”, truth “biscuits”, small nudge. Repeat across a huge library of text, and the model slowly picks up grammar, facts and style.
Here is a neat detail: nobody has to label that text by hand. The next word is already sitting there in the sentence, so the text labels itself. That is a big reason language models could learn from so much data. You will see this next-word game in detail in module 2.
Check yourself
Check yourself
What actually changes inside a model while it trains?
Pick an answer to see why it is right or wrong.
Check yourself
A model scores 99% on its training mangoes but 60% on new ones. What is most likely going on?
Pick an answer to see why it is right or wrong.
Remember these three
- Learning is a loop: guess, measure the error, nudge the parameters a little, repeat.
- The real test is new examples the model never saw; a big gap means it memorised.
- Chat models learn the same way, guessing hidden next words across a huge library of text.
Questions people ask
- How does machine learning work in simple terms?
- The computer is shown many examples with known answers. It guesses, measures how wrong it was, and adjusts its internal numbers to be a little less wrong. After many rounds, it can handle new examples on its own.
- What is training in AI?
- Training is the phase where a model learns from data by repeating the guess-check-adjust loop. It happens before you use the model; when you chat with an AI app, the model is usually not training on the spot.
- What are parameters or weights in a model?
- They are the adjustable numbers inside a model that decide how much each piece of input matters. A tiny model may have a handful; large language models have billions.
- What is overfitting?
- Overfitting is when a model memorises its training examples instead of learning the general pattern. It looks excellent in practice and does poorly on new data, which is why we always test on examples kept aside.