AI Tutorial menu

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:

  1. Takes some numbers as inputs.
  2. Multiplies each input by a weight (how important that input is) and adds them up, plus a bias.
  3. Passes the total through an activation function that decides the output.

Here is one neuron that decides whether Ayesha should carry an umbrella:

Example

python
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")
Output
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:

LayerJob
Input layerReceives the data, such as pixel values or numbers from a table
Hidden layersFind patterns in the data; "deep" means many hidden layers
Output layerGives 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:

  1. Show the network an example, such as a photo labelled "cat".
  2. The network makes a guess.
  3. Measure how wrong the guess was. This is the loss (the error).
  4. Adjust every weight a tiny bit in the direction that reduces the error. This method is called backpropagation with gradient descent.
  5. Repeat for thousands or millions of examples.

Here is the "adjust a little each time" idea with just one weight:

Example

python
# 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))
Output
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?

Learn AI with a teacher

Join the AI & Prompt Engineering course at Workownix, online or in Orangi Town, Karachi, and get a certificate.

See the course Ask on WhatsApp