I believe it makes most sense for me to start my first-ever blog with Neural Networks, as this is where I want to specialize.
Before going into technical details and all the mathematics behind of Neural Networks, I want to talk a bit about what it actually is. It’s a cheap shot to “copy” human brain, using a unit called artificial neurons to process data and recognize patterns. And for our “Hello, World!” I will be talking about MNIST dataset neural network, a machine learning model trained to recognize handwritten digits ranging from 0 to 9. It’s important to keep in mind that this is a Feedforward Neural Network (FNN).
This system has four key parts. First is the input layer, where the model takes in raw data, such as pixels of a handwritten digit (or words from text, though not for MNIST). Second are the hidden layers, which sit between the input and output where the computer does the math to find patterns. Third is the output layer, which, as name suggests, gives the final answer/prediction. Fourth are the weights and biases. And yeah, it would be really fun and easy if this was how things simply played out, but (un)fortunately, this is a really high-level overview of what’s actually happening. So let me go a bit more into detail.
It is also important to understand what values neurons hold. Normalized MNIST inputs are between 0 and 1, but a neuron’s value depends on its activation function. For example, ReLU outputs can be any non-negative number, while the output probabilities produced by softmax are between 0 and 1.
- Input Layer: A pixel image is flattened into a one-dimensional vector of 784 values. Each hidden neuron receives all 784 input values through separate weighted connections. For hidden neuron , the weighted sum before activation is
where is input pixel , is the weight connecting input to neuron , and is that neuron’s bias.
- Hidden Layer: The raw value is passed through a non-linear activation function such as ReLU:
Here, is the neuron’s activation. Without non-linear activation functions, multiple layers would collapse into a single transformation and the network could only model linear decision boundaries. This process repeats through every hidden layer in the network and becomes more expressive as the network gets deeper.

Image source: IBM, “What Is a Neural Network?”.
- Output Layer: The final hidden layer connects to an output layer consisting of 10 nodes, one for each digit from 0 to 9. Its raw outputs are called logits. To distinguish them from the hidden neuron’s value , let represent output logit . Softmax converts each output logit into a normalized probability :
The probabilities are each between 0 and 1 and sum to 1. The class with the highest probability becomes the model’s prediction (i.e., the model assigns a 95% probability to digit 2):
During training, a loss function compares this distribution with the ground-truth label. For MNIST, a common choice is cross-entropy loss:
Here, is component of the true one-hot label vector (1 for the correct digit and 0 for every other digit), and is the predicted probability. If is the true class, the sum simplifies to
Backpropagation uses the chain rule to determine how much each weight and bias contributed to the loss. Gradient descent then updates all the model’s parameters, represented by , in the direction that reduces the loss. The update from iteration to iteration is
where contains the current parameter values, contains the updated values, is the loss produced by the current parameters, and is the learning rate. The term is subtracted from because the gradient points in the direction in which the loss increases most quickly. Subtracting it moves the parameters in the opposite direction, toward lower loss and, hopefully, a local minimum.
In practice, training begins with randomized weight initialization, while biases are often initialized to zero. Rather than using the entire dataset for every update, training usually processes one mini-batch at a time. For each mini-batch, the network performs a forward pass, calculates the loss, and uses backpropagation to calculate the gradient of the loss with respect to every parameter. The optimizer then applies the update above. Once the model has processed every mini-batch in the training set, it has completed one epoch.
This process usually repeats for a fixed number of epochs, or early stopping ends training when performance on a validation set no longer improves. Convergence does not necessarily mean the parameters stop moving or the model reaches the minimum possible error. Neural-network loss surfaces are non-convex, so training may instead reach a useful solution where further improvements are small. The learning rate is where things can go wrong: if it is too large, training can become unstable and simply “miss” the local minimum; if it is too small, training can take too long and waste resources.