Artificial Intelligence Fundamentals / Clusters and Neural Networks

How neural networks learn

Lesson 17 of 26. Open to read. No account needed.

Why Look Inside

Neural networks power image recognition, speech recognition and language models. They can seem mysterious, but each part is simple arithmetic. This lesson follows that arithmetic by hand for one small unit, then shows how many such units, and many small corrections, add up to a model that learns. The next lesson trains a small network on real images.

One Neuron

A network is built from neurons, also called units. A neuron does two things:

  1. It calculates a weighted sum: each input is multiplied by its own weight, the products are added, and a bias is added at the end. Weights say how much each input matters, and in which direction; the bias shifts the result.
  2. It passes that sum through an activation function. A common one, called ReLU, keeps positive values unchanged and turns negative values into 0.

Worked example: three inputs 2, 1 and 3; weights 0.5, −1 and 0.25; bias 0.5.

StepCalculationResult
Weighted sum0.5 × 2 + (−1) × 1 + 0.25 × 3 + 0.51.25
ReLU1.25 is positive, so it is kept1.25

If the weighted sum had been −0.7, ReLU would output 0. That on-off behaviour is what lets networks build up patterns that a single weighted sum could not represent.

Layers

Neurons are arranged in layers. The inputs, such as 64 pixel values of an image, feed every neuron in the first hidden layer; each of those neurons has its own weights and bias. Their outputs feed the next layer, and so on, to the output layer, which produces the prediction: for digit images, one output per digit, 0 to 9. A network with one hidden layer of 32 neurons reading 64 pixels already has 64 × 32 weights between those two layers, plus 32 × 10 weights to the output layer.

"Deep" learning simply means many hidden layers. Nobody chooses the weights by hand: there are far too many, and nobody knows the right values. They are learned.

A small network: three inputs on the left connect to a hidden layer of neurons, which connect to an output. One hidden neuron is enlarged to show its weighted sum of inputs plus a bias, followed by the activation. On the right, the output is compared with the right answer to give a loss, and an arrow labelled weight updates runs back through the network.

Read the diagram from left to right, then follow the return arrow. Inputs flow forward through the layers to an output. The output is compared with the right answer to measure the error, called the loss. The return arrow is training: the loss is used to adjust every weight a little.

Loss: Measuring the Error

To learn, the network needs a number that says how wrong it is: the loss. For a number target, one common loss is the squared error: the difference between the right answer and the output, squared. Suppose the right answer for our neuron's input was 2:

loss = (2 − 1.25)² = 0.75² = 0.5625

For classification, networks use a loss based on how much probability they gave to the right class. Whatever the form, lower loss means better predictions on the training data.

Training: Many Small Corrections

Training repeats one idea: change each weight slightly in the direction that lowers the loss.

For each weight, calculus gives the gradient: how much the loss would change if that weight changed slightly, and in which direction. For the third weight in the example, the gradient is −4.5: increasing that weight would lower the loss. Training takes a small step against the gradient, scaled by the learning rate. With a learning rate of 0.02:

StepCalculationResult
New third weight0.25 − 0.02 × (−4.5)0.34
New weighted sum0.5 × 2 + (−1) × 1 + 0.34 × 3 + 0.51.52
New loss(2 − 1.52)²0.2304

The loss fell from 0.5625 to 0.2304 after one small step. A real network updates every weight at once, using the gradient for each, and repeats over many examples and many passes through the data. Finding all the gradients efficiently, layer by layer from the output backwards, is called backpropagation. This repeated stepping downhill on the loss is gradient descent; scikit-learn's networks use refined versions of it, by default one called Adam.

Two consequences matter in practice:

  • Training is a search that can stop before it has finished. If it hits its step limit first, scikit-learn warns that the optimisation has not converged, as with logistic regression.
  • Networks are sensitive to the scale of their inputs; features on very different scales make the steps poorly sized. Scaling the inputs first, as in the leakage lesson, is standard practice.

What a Trained Network Is

After training, a network is a large set of numbers: weights and biases. Making a prediction is the forward calculation from this lesson, repeated for every neuron. The network does not store its training examples, and it does not reason about them; it has numbers that happen to produce good outputs for inputs like the ones it was trained on. Its answers on very different inputs can be confidently wrong, which matters again for language models.

Check Your Understanding

  1. A neuron has inputs 1 and 4, weights 2 and −1, and bias 1. What does it output with ReLU?
  2. Why does a network's answer for the same input change after training, although its code does not?
  3. A loss curve keeps falling but training stops with a convergence warning. What happened, and what are two possible responses?

Answer and Reasoning

  1. The weighted sum is 2 × 1 + (−1) × 4 + 1 = −1. ReLU turns negative values into 0, so the output is 0.
  2. Training changed the weights and biases, the numbers the code calculates with. The calculation is the same; the numbers in it are different.
  3. Training reached its maximum number of iterations while the loss was still improving. Allow more iterations, or make each step more effective, for example by scaling the inputs. Then check the test score, since a lower training loss does not by itself mean better predictions on new data.

References

Study this course with an account

Course access adds revision notes, the Quick Reference, saved progress, bookmarks and your own notes.

INR 199 plus 18% GST. 90 days of online access. No auto-renewal.

See course access

This website is operated by VECTAMETRIC EDTECH (OPC) PRIVATE LIMITED, operating as Vectametric.

Corporate Identity Number (CIN): U85499KA2026OPC229822. GSTIN: 29AAMCV8281D1ZS. Registered office: RS NO/38/2A/1 BASTAND, ROAD MAHANTESH NAGAR, Ramdurg, Ramdurg, Belgaum- 591123, Karnataka.

Queries and grievances: Prajval Honnungar, Grievance Officer and Data Protection Contact.

Telephone: +91 94800 09310. Support: support@vectametric.com. Grievances: support@vectametric.com.

Copyright 2026 VECTAMETRIC EDTECH (OPC) PRIVATE LIMITED. All rights reserved.

Vectametric home · Roadmaps · Vecta IT Exams · Vecta Government Exams · Vecta Banking & Finance Exams · Vecta Entrance Exams · About us · Contact · Privacy Policy · Terms and Conditions · No-Refund Policy