The Maths Behind Neural Networks, Gently Explained

Learning is just adjusting numbers to reduce error

You don't need maths to use AI. But understanding the core idea of how neural networks learn makes everything else — training, fine-tuning, overfitting — click. Here's the gentle version.

A Single Neuron

A neuron takes inputs, multiplies each by a weight, adds a bias, and passes the result through an activation function:

output = activation(w1·x1 + w2·x2 + b)

Example: predicting if a ticket is urgent from "number of users affected" (x1) and "is production" (x2). The weights say how important each input is.

Activation Functions

They add non-linearity so networks can learn complex patterns:

  • ReLU — max(0, x), the common default
  • Sigmoid — squashes to 0–1, useful for probabilities
  • Softmax — turns scores into probabilities across many classes (used to choose the next token in LLMs)

Layers

Stack neurons into layers: input → hidden layers → output. Deep learning = many layers. LLMs have billions of weights across many layers.

Loss: Measuring Wrongness

A loss function measures how far predictions are from the truth. For LLMs, the loss measures how surprised the model was by the actual next token.

Gradient Descent: Learning

Imagine standing on a hilly landscape in fog, trying to reach the lowest valley (lowest loss). You feel the slope under your feet and take a small step downhill. Repeat millions of times.

  • The gradient tells you the slope for each weight
  • The learning rate is your step size

Backpropagation

The algorithm that efficiently calculates the gradient for every weight, working backwards from the output layer to the input. It's what makes training deep networks practical.

A Tiny Example in Python

# Learn y = 2x with one weight
w = 0.0
data = [(1, 2), (2, 4), (3, 6)]
lr = 0.05
for step in range(100):
    for x, y in data:
        pred = w * x
        grad = 2 * (pred - y) * x   # derivative of (pred - y)^2
        w -= lr * grad
print(round(w, 3))  # ≈ 2.0

That's learning: start with a guess, measure error, adjust, repeat.

Overfitting

If a model memorises training data instead of learning general patterns, it fails on new data. Techniques like more data, regularisation, and validation sets help.

Every AI model — from a spam filter to a frontier LLM — learns this way: guess, measure, adjust. Scale is what makes it powerful.

Arivanandhan Chitheshwaran