← ALL AI GUIDES/ MACHINE LEARNING / GRADIENT DESCENT

How neural networks learn

Weights, losses, gradients and the difference between training and using a model.

THE SHORT ANSWER

A neural network learns by repeatedly measuring an error, calculating how parameters affect it, and updating weights. Training changes the model; inference uses the weights that already exist.

Choose your level of detail
How it works · Your choice is saved across lessons

Training minimizes a loss by changing model weights. Backpropagation gives gradients and the learning rate controls update size. Inference only uses the trained values.

01 / EXPLANATION

Start with a weighted calculation

A basic artificial neuron multiplies input values by weights, adds a bias, and passes the result through an activation function. Connecting many such units creates a network that can represent more complicated mappings.

Changing a weight changes the output. That's what makes weights trainable. More neurons do not automatically make a model correct; their usefulness depends on the data, training objective, architecture and optimization.

02 / EXPLANATION

What does a loss function measure?

A model makes predictions on training examples. A loss function converts the difference between predictions and targets into a number that training attempts to reduce. Classification models often use cross-entropy losses; regression models can use squared error.

A lower training loss is not the same thing as good performance on new data. Overfitting happens when a model captures patterns specific to its training set and generalizes poorly outside it.

03 / EXPLANATION

Backpropagation tells us how to adjust weights

For each example, a forward pass computes predictions. Backpropagation applies the chain rule to calculate gradients of the loss with respect to model parameters. An optimizer such as gradient descent takes steps against those gradients.

The learning rate controls step size. Too small can mean painfully slow improvement; too large may cause oscillation or instability. Our tiny interactive classifier exposes learning rate so you can watch its influence directly.

04 / EXPLANATION

Why XOR is an interesting teaching problem

The XOR task expects one when its two binary inputs differ and zero otherwise. No single straight decision line perfectly separates those four cases, making it a classic illustration of why hidden nonlinear transformations matter.

Our browser playground computes actual analytic gradients for a small two-input, tanh-hidden, sigmoid-output network and visualizes its prediction surface. Its four-example training set is intentionally tiny, and convergence is not guaranteed for every neuron count and learning rate.

05 / EXPLANATION

Training and inference are separate workflows

When you type a prompt into a pretrained language model, the model ordinarily runs inference: it calculates outputs using the existing weights. That does not mean the underlying parameters are updated on every prompt.

Training a new model requires data, a defined objective, optimization, evaluation and substantial compute at large scales. A browser-size classifier demonstrates the core idea without pretending to reproduce large language model training.

WORKED EXAMPLE / CHECK THE LIMITS

Teach a tiny OR classifier

Inputs (0,0) → target 0; (0,1), (1,0), (1,1) → target 1

Our small model can compute predictions, compare them with the four targets, and lower binary cross-entropy using gradient descent. Try increasing the learning rate or switching to XOR.

What this does not prove: This is a genuine four-example training exercise, not evidence that the model can generalize to untested real-world data.

Train a real tiny neural network ↗
QUESTIONS PEOPLE ASK

Questions and clear answers

Does a chatbot learn new weights whenever I send a message?

A normal inference request doesn't automatically retrain its foundation model. Product memory, retrieval and future training pipelines are separate capabilities.

What happens if I increase the learning rate?

Updates become larger, which can speed initial progress or overshoot useful parameter values. There is no universally best rate.

Why use hidden neurons?

Nonlinear hidden layers let the network combine inputs in ways that a single linear decision boundary cannot, as the XOR example illustrates.

Research & verificationLearning through gradient descentPeer reviewed
Peer reviewedSite demo: not independently audited
Learning representations by back-propagating errors ↗Rumelhart, Hinton & Williams, Nature, 1986

Publication review: Peer-reviewed scientific journal article.

Independent verification: Our training experiment is original scalar regression, not an experimental reproduction of the paper. Its math has unit tests, not external certification.

Peer review of a paper does not certify this demo.