Sitemap
Sankalp Salve

Sankalp Salve

Tech, history, and physics enthusiast. Writing stories that explore the evolution of technology, the impact on society, and the fundamental laws of our universe

A Beginner’s Guide to Neural Networks: Forward and Backward Propagation Explained

3 min readAug 24, 2024

--

Neural networks are a fascinating and powerful tool in machine learning, but they can sometimes feel a bit like magic. The truth is, they’re built on simple mathematical concepts. Today, we’ll dive into how neural networks work, focusing on forward propagation and backward propagation, the core processes that allow these models to learn.

Press enter or click to view image in full size

What is a Neural Network?

Imagine a neural network as a set of connected layers, each layer consisting of several nodes (neurons). These neurons process input data and pass on the information to the next layer, leading to a final prediction or output.

Here’s a simple structure of a neural network:

  • Input Layer: Where the data enters the network.
  • Hidden Layers: Where the data is processed and transformed.
  • Output Layer: Where the final prediction is made.

Forward Propagation: How Data Flows Through the Network

Forward propagation is the process of moving data through the network from the input layer to the output layer.

Example:

Let’s break it down with a simple neural network that predicts house prices.

Input Layer: We start with inputs like the number of bedrooms (x1) and the square footage (x2).

Hidden Layer: These inputs are passed through neurons in the hidden layer. Each neuron applies a weight (W) and a bias (b) to the input, then processes it through an activation function (like ReLU or sigmoid).

The math looks like this:

h1 = activation(W1 * x1 + W2 * x2 + b1) h2 = activation(W3 * x1 + W4 * x2 + b2)

Output Layer: The results from the hidden layer are passed to the output layer, where another weighted sum is calculated, and an output (y) is generated.

Get Sankalp Salve’s stories in your inbox

Join Medium for free to get updates from this writer.

y = activation(W5 * h1 + W6 * h2 + b3)

The result is the network’s prediction, which could be the estimated price of a house.

Backward Propagation: How the Network Learns

After making a prediction, the neural network needs to learn from its mistakes, which is where backward propagation comes in.

Example:

Let’s say the network predicted a house price of $300,000, but the actual price was $350,000. The difference between the predicted and actual prices is the error (or loss).

  1. Calculate the Loss: We use a loss function (like Mean Squared Error) to quantify how far off the prediction was.

Loss = (y_pred - y_actual)^2

Backpropagation: The network then works backward from the output layer to the input layer, calculating how much each weight contributed to the error.

Update the Weights: Using a technique called gradient descent, the network adjusts its weights to reduce the error in future predictions.

W_new = W_old - learning_rate * gradient

With each iteration, the network gets better at making accurate predictions by adjusting its weights and biases, effectively “learning” from its mistakes.

Why Forward and Backward Propagation Matter

These two processes are what make neural networks so powerful. Forward propagation allows the network to make predictions, while backward propagation enables it to learn and improve. Together, they form the foundation of most deep learning models.

Real-Life Example

Think of forward propagation as guessing on a math test, and backward propagation as reviewing your mistakes after the test to understand where you went wrong. With each test (or iteration), you get better and better at solving problems.

Conclusion

Understanding forward and backward propagation is essential for anyone interested in neural networks. These processes might seem complex at first, but they’re built on simple mathematical principles that work together to create the powerful learning algorithms behind modern AI.

--

--

Sankalp Salve
Sankalp Salve

Written by Sankalp Salve

Tech, history, and physics enthusiast. Writing stories that explore the evolution of technology, the impact on society, and the fundamental laws of our universe