Neural Networks Simply Explained
A neural network is a group of simple maths units, connected in layers, that together can learn complex patterns.
The Idea of a Neuron
The name comes from the brain, but an artificial neuron is much simpler than a real one. It does three things:
- Takes some numbers as inputs.
- Multiplies each input by a weight (how important that input is) and adds them up, plus a bias.
- Passes the total through an activation function that decides the output.
Here is one neuron that decides whether Ayesha should carry an umbrella:
Example
cloudy = 1 # 1 = yes, 0 = no
humidity = 0.8 # from 0 to 1
w_cloudy = 0.6
w_humidity = 0.5
bias = -0.7
total = cloudy * w_cloudy + humidity * w_humidity + bias
output = 1 if total > 0 else 0
print("Total:", round(total, 2))
print("Carry umbrella?", "Yes" if output == 1 else "No")Total: 0.3 Carry umbrella? Yes
The weights decide the behaviour. Change them, and the neuron makes different decisions.
Layers
One neuron can only learn a simple rule. So we connect many of them in layers:
| Layer | Job |
|---|---|
| Input layer | Receives the data, such as pixel values or numbers from a table |
| Hidden layers | Find patterns in the data; "deep" means many hidden layers |
| Output layer | Gives the final answer, such as "cat 92%, dog 8%" |
Each neuron in one layer sends its output to neurons in the next layer.
How a Network Learns
At first the weights are random, so the answers are bad. Training fixes this step by step:
- Show the network an example, such as a photo labelled "cat".
- The network makes a guess.
- Measure how wrong the guess was. This is the loss (the error).
- Adjust every weight a tiny bit in the direction that reduces the error. This method is called backpropagation with gradient descent.
- Repeat for thousands or millions of examples.
Here is the "adjust a little each time" idea with just one weight:
Example
# Learn the rule: price = weight * kg (true weight is 300 Rs per kg)
weight = 0.0
data = [(1, 300), (2, 600), (3, 900)]
learning_rate = 0.05
for step in range(50):
for kg, price in data:
guess = weight * kg
error = guess - price
weight = weight - learning_rate * error * kg
print("Learned price per kg:", round(weight))Learned price per kg: 300
The program started knowing nothing (weight 0) and learned the price of 300 Rs per kg only by correcting its mistakes. Big neural networks do exactly this, but with billions of weights.
The learning rate controls how big each correction is. Too big and learning jumps around; too small and learning is very slow.
Common Kinds of Networks
- Feed-forward networks: the basic type, data flows one way. Good for tables of numbers.
- Convolutional neural networks (CNNs): good at images, because they look at small areas of a picture.
- Recurrent networks (RNNs): older design for sequences like text and speech.
- Transformers: the modern design behind chatbots. They use "attention" to decide which words in a sentence matter most for each other word.
Why Neural Networks Are Hard to Explain
A trained network is a huge list of numbers. It works, but it is hard to say exactly *why* it made one decision. This is called the black box problem, and researchers work on "explainable AI" to make models easier to understand.
Exercise
Exercise
During training, what does a neural network change to reduce its errors?
