# How machines learn · AI in Bed

Beginner level · 5 min · https://www.aiinbed.com/learn/beginner/how-machines-learn

*Guess, check, adjust, repeat. Every model on Earth learns with the same simple loop.*

Imagine learning to throw a paper ball into a bin across the room. You throw, you miss to the left, you aim a little more right. Throw again. Closer. Adjust again. Machine learning is exactly that, done millions of times very fast.

*Figure: The training loop: the model guesses, we measure how wrong it was, and nudge it to be a bit less wrong next time.*

### The model makes a guess

A **model** is just a big mathematical function with lots of adjustable knobs called **parameters** (or weights).

At the start the knobs are set randomly, so its guesses are rubbish.

### We measure the mistake

We compare the guess with the right answer. A **loss function** turns "how wrong" into a single number.

Big number = very wrong. Small number = nearly right.

### We nudge the knobs

An algorithm works out which direction to turn each knob to make the loss smaller, and turns it a tiny bit.

This is called **optimisation**. The most famous method is gradient descent (you'll meet it in Intermediate).

### Repeat… a lot

One pass through all the training data is an **epoch**. Models often train for many epochs.

A big language model's knobs get nudged trillions of times during training.

**Quick check:** What does the loss function tell us?

A. How fast the computer is
B. How wrong the model's guess was
C. How many parameters the model has
D. Which data to delete

Answer: B. The loss is a score for wrongness. Training is all about making it smaller.

### Training vs. using

**Training** is the slow, expensive learning phase, where the knobs change.

**Inference** is using the finished model. The knobs are frozen; it just answers. When you chat with an AI, you're doing inference.

> Pillow thought: a model doesn't "remember" its training examples like a diary. It squeezes patterns from them into its knobs, a bit like how you remember the rules of grammar but not every sentence you ever read.

**Quick check:** When you ask a chatbot a question, the model is…

A. Training on your question
B. Doing inference with frozen parameters
C. Searching for the answer in its training data
D. Rewriting its own code

Answer: B. Using a trained model is inference. Its parameters don't change while it answers you.

**Key takeaways**

- A model is a function with adjustable parameters.
- Training loop: predict → measure loss → adjust → repeat.
- Training changes the parameters; inference just uses them.

**Go deeper (free sources)**

- [But what is a neural network? (video series)](https://www.3blue1brown.com/topics/neural-networks) by 3Blue1Brown (Grant Sanderson)
- [ML Crash Course: Linear regression & loss](https://developers.google.com/machine-learning/crash-course) by Google
