No history yet

Neural Architectures

The Bedrock: Multi-Layer Perceptrons

At the core of many deep learning models is the Multi-Layer Perceptron (MLP). Think of it as the original blueprint for a neural network. An MLP consists of an input layer, one or more hidden layers, and an output layer. Its defining feature is that each neuron in a given layer is connected to every neuron in the next layer. This is called being 'fully connected' or 'dense'.

Information flows in one direction, from input to output. At each neuron, two things happen. First, the neuron calculates a weighted sum of all its inputs. Then, it passes this sum through an activation function to decide its output. This process repeats layer by layer, allowing the network to learn increasingly complex patterns from the initial data.

The activation function is a critical component. Without it, a neural network, no matter how many layers it has, would just be a complex linear function. Activation functions introduce non-linearity, enabling the network to learn intricate relationships between inputs and outputs. Different functions have different properties and are suited for different tasks.

  • Sigmoid: Squeezes numbers into a range between 0 and 1. It's often used in the output layer for binary classification problems, where the output can be interpreted as a probability.
  • Tanh (Hyperbolic Tangent): Similar to sigmoid, but it maps inputs to a range between -1 and 1. Its zero-centred nature can sometimes help models learn faster.
  • ReLU (Rectified Linear Unit): This is the most popular activation function. It's simple: if the input is positive, it returns the input; otherwise, it returns zero. It's computationally efficient and helps mitigate certain problems that can arise during training.
ReLU(x)=max(0,x)\text{ReLU}(x) = \max(0, x)

Seeing the World with CNNs

While MLPs are powerful, their fully connected nature creates a problem for high-dimensional data like images. A simple 256x256 pixel colour image has 256 * 256 * 3 = 196,608 input values. Connecting this to even a modest hidden layer would result in an astronomical number of parameters, making the network slow to train and prone to overfitting.

Enter the Convolutional Neural Network (CNN). CNNs are designed specifically for grid-like data, such as images. Instead of connecting every input pixel to every neuron in the first hidden layer, CNNs use a clever system of local connectivity.

They achieve this with that apply filters, also known as kernels, across the input image. Each filter is a small matrix of weights that slides over the image, looking for a specific feature, like an edge, a corner, or a patch of colour. By using the same filter across the entire image, the network learns to recognise a feature no matter where it appears. This property is called translation invariance.

Lesson image

A CNN typically stacks multiple convolutional layers. The early layers learn simple features like edges and textures. Deeper layers combine these simple features to recognise more complex patterns, like eyes, noses, or wheels. This creates a spatial hierarchy of features, from simple to complex. After a few convolutional layers, a CNN often uses pooling layers to downsample the feature maps, reducing the spatial dimensions and making the network more efficient.

This specialised structure makes CNNs incredibly effective for tasks like image classification, object detection, and facial recognition. They trade the brute-force connectivity of an MLP for a smarter, more efficient architecture that understands the spatial nature of images.

Remembering the Past with RNNs

What about data where sequence matters, like text, speech, or stock market prices? A CNN or MLP treats every input independently. They have no memory of what came before. For sequential data, context is everything. The meaning of the word 'bank' depends on whether the previous words were 'river' or 'money'.

Recurrent Neural Networks (RNNs) are designed to handle this. The key innovation in an RNN is a loop. As the network processes an element in a sequence, it doesn't just produce an output; it also updates its internal hidden state and passes this information along to the next time step. This hidden state acts as the network's memory, carrying a summary of the information it has processed so far.

This recurrent nature allows RNNs to model dependencies across time, making them suitable for language translation, text generation, and time-series forecasting. However, the simple RNN architecture has a significant weakness.

As sequences get longer, it becomes difficult for the network to propagate information over many time steps. The signal, carried by gradients during training, can either shrink exponentially until it vanishes or grow exponentially until it explodes. This is known as the vanishing (or exploding) gradient problem. It means the network struggles to learn long-range dependencies, effectively having a short-term memory. This limitation led to the development of more sophisticated architectures like LSTMs (Long Short-Term Memory) and GRUs (Gated Recurrent Units), which use special mechanisms called gates to better control the flow of information through time.

Choosing the Right Tool

The choice between an MLP, CNN, or RNN boils down to the structure of your data and the problem you're trying to solve. Each architecture represents a different set of assumptions about the data.

  • MLPs assume no spatial or temporal structure. They are the universal approximator, but can be inefficient for structured data. Use them for simple classification or regression on tabular data where feature order doesn't matter.
  • CNNs assume local spatial patterns are important. They are the go-to for any grid-like data, most famously images, but also things like spectrograms in audio processing.
  • RNNs assume that the order of data points is crucial. They are built for sequences: natural language, financial time series, or DNA sequences.

Understanding these architectural trade-offs is key to building effective deep learning models. It's not about which one is 'best' overall, but which one is best suited for the task at hand.

Quiz Questions 1/6

What is the primary purpose of an activation function in a Multi-Layer Perceptron (MLP)?

Quiz Questions 2/6

You are tasked with building a model to classify images of cats and dogs. Which neural network architecture is specifically designed for this type of grid-like data?

These three architectures form the foundational pillars of deep learning. While newer, more complex models often combine their elements, a solid grasp of how MLPs, CNNs, and RNNs work is essential for navigating the field.