No history yet

Neural Network Architecture

The Anatomy of a Network

A neural network is a series of layers, each made of simple processing units called neurons. Think of it like an assembly line for data. Information enters at one end, gets processed step-by-step through the middle, and a final result comes out the other end.

Lesson image

There are three main types of layers:

  1. Input Layer: This is where your data enters the network. If you're analysing images that are 100x100 pixels, you might have 10,000 input neurons, one for each pixel's brightness.
  2. Hidden Layers: These are the workhorses. They sit between the input and output. Each neuron in a hidden layer receives inputs from the previous layer, performs a simple calculation, and passes its result to the next. The “deep” in deep learning refers to having many hidden layers.
  3. Output Layer: This layer produces the final prediction. For a yes/no question, it might be a single neuron. For classifying an image into one of ten categories, it would be ten neurons.

Each connection between neurons has a 'weight', a number that represents the strength of the connection. Initially, these weights are set to small random values. The entire process of 'learning' is just the network systematically adjusting these weights to produce more accurate outputs.

How a Network Learns

Learning happens in two main phases. First, data flows forward through the network, from input to output, to make a prediction. This is called a forward pass.

Next, the network compares its prediction to the correct answer. The difference between them is the 'error'. This error is then sent backward through the network in a process called backpropagation to figure out which weights contributed most to the mistake. This is where the magic happens.

Backpropagation tells the network: "You were wrong. The neurons with these specific weights were most responsible. Adjust them slightly so you're less wrong next time."

This adjustment process is guided by an algorithm called gradient descent. Imagine you're on a foggy mountain and want to get to the lowest valley. You can't see the whole landscape, but you can feel which direction is downhill from where you're standing. You take a small step in that direction.

Gradient descent does the same thing with the error. It calculates the 'slope' of the error for each weight and nudges the weight in the downhill direction. Repeat this thousands of times with thousands of data points, and the network's weights slowly settle into a configuration that minimizes the overall error.

Inside each neuron, an 'activation function' decides whether the neuron should fire and how strongly. It's a simple gatekeeper. Early networks used functions that were slow to compute. Today, one of the most common is the Rectified Linear Unit, or ReLU. It's incredibly simple: if the input is negative, the output is zero. If the input is positive, the output is the input itself.

f(x)=max(0,x)f(x) = \max(0, x)

For the final output layer, a function called Softmax is often used for classification problems. It takes the raw scores from the final neurons and converts them into a set of probabilities that sum to 1. This gives a clean, interpretable result, like "85% chance this is a cat, 10% a dog, 5% a fox."

Specialized Architectures

Not all problems are the same, so not all networks are structured the same way. While the basic feedforward network is a great general-purpose tool, specialized tasks call for specialized designs.

Convolutional Neural Networks (CNNs) are the undisputed champions of computer vision. Instead of connecting every neuron to every other neuron in the next layer, a CNN uses 'filters' that slide across an image, looking for specific patterns like edges, corners, or textures. Each layer learns to recognize more complex patterns by building on the patterns found in the previous layer. This makes them highly efficient for image-based tasks.

Lesson image

Recurrent Neural Networks (RNNs) are designed for sequential data, like text, speech, or stock prices. The key feature of an RNN is a loop. As it processes an element in a sequence, it feeds its output back into itself as an input for the next element. This gives the network a form of memory, allowing it to understand context. For example, to understand the word "bank" in a sentence, an RNN can use the preceding words ("river" or "money") to determine the correct meaning.

Choosing the right architecture is a critical step. Using a CNN for text translation or an RNN for image classification would be like using a hammer to turn a screw. It might work eventually, but it's not the right tool for the job.

Quiz Questions 1/6

What is the primary function of the hidden layers in a neural network?

Quiz Questions 2/6

In the context of training a neural network, what is backpropagation?

Understanding these architectural patterns and learning mechanisms is the key to moving beyond simply using neural networks and starting to design and build them effectively.