No history yet

Neural Network Architecture

Anatomy of a Neural Network

A neural network processes information in a way inspired by the human brain. The most common structure is the Multi-Layer Perceptron (MLP), which consists of layers of interconnected nodes, or neurons. Information flows in one direction, from the input layer, through one or more hidden layers, to the output layer.

Lesson image

Think of it as a digital assembly line. The input layer receives the raw data, like the pixels of an image or the words in a sentence. Each node in this layer represents a single feature of the input.

The data then moves to the hidden layers. This is where the real work happens. Each layer takes the output from the previous one and performs complex transformations, learning to recognize progressively more abstract features. In image recognition, the first hidden layer might detect edges, the next might identify shapes like eyes and noses, and a deeper layer might recognize a face.

Finally, the output layer produces the final result. This could be a single value, like the probability that an image contains a cat, or multiple values for classifying the input into one of several categories.

The Mechanics of a Neuron

Each connection between neurons has a numerical weight, which determines the strength and sign (positive or negative) of the connection. Think of weights as dials that tune the importance of different inputs. A neuron also has a bias, which is an extra value that can shift the neuron's output up or down. This allows the network to fit the data better.

z=i=1n(wixi)+bz = \sum_{i=1}^{n} (w_i x_i) + b

This weighted sum, zz, is then passed through an activation function. This function introduces into the model, which is crucial. Without it, a neural network, no matter how many layers it has, would just be a complex linear model, incapable of learning intricate patterns like the curve of a road or the nuance in a piece of music.

Different activation functions have different properties:

FunctionRangeUse CasePros & Cons
Sigmoid(0, 1)Binary classification (output layer)Maps to probability, but can suffer from vanishing gradients.
Tanh(-1, 1)Hidden layers (especially in older models)Zero-centered, but also prone to vanishing gradients.
ReLU[0, ∞)Standard for hidden layersComputationally efficient, avoids vanishing gradients, but can 'die'.

The process of passing an input through the network, from the input layer to the output layer, is called forward propagation.

Learning from Mistakes

A neural network learns through a process of trial and error. After a forward pass, the network's output is compared to the correct answer using a loss function. This function calculates a score that represents how wrong the prediction was. The goal of training is to minimize this loss score.

To do this, the network uses an algorithm called backpropagation. It calculates the gradient of the loss function with respect to each weight and bias in the network. The gradient is a vector that points in the direction of the steepest increase of the loss. To reduce the loss, we need to adjust the parameters in the opposite direction of the gradient.

Backpropagation relies on the from calculus to efficiently compute these gradients, layer by layer, starting from the output and moving backward to the input.

Once the gradients are calculated, an optimization algorithm called Gradient Descent updates the weights and biases. It takes a small step in the direction opposite to the gradient. The size of this step is controlled by a parameter called the learning rate. This iterative process of forward propagation, loss calculation, backpropagation, and parameter updates is repeated thousands or millions of times until the network's predictions are accurate.

wnew=woldηLw_{\text{new}} = w_{\text{old}} - \eta \cdot \nabla L

Choosing the right learning rate is critical. If it's too small, the model will learn very slowly. If it's too large, it might overshoot the optimal values and fail to converge. This entire process is how a network goes from making random guesses to performing complex tasks with high accuracy.

Quiz Questions 1/6

What is the primary role of the hidden layers in a Multi-Layer Perceptron?

Quiz Questions 2/6

Why are non-linear activation functions crucial in neural networks?