The Foundations of Deep Learning

From artificial neurons to CNNs, RNNs, and Transformers , understanding how machines learn patterns, recognise the world, remember sequences, and somehow manage to make mistakes with incredible confidence.

22 min read ·

1. Introduction — When Machine Learning Decided to Get More Complicated

Machine Learning taught us that computers could learn patterns from data instead of relying entirely on manually written rules. We gave them examples, trained models, evaluated predictions, and hoped they would behave sensibly outside the training dataset. Sometimes they did. Sometimes they confidently predicted something completely unreasonable. Progress, apparently.

But what happens when the data becomes too complex for traditional approaches? Consider an image of a cat. A human can recognise it almost instantly, even if the cat is sitting in a strange position, partially hidden, or looking like it has just questioned the meaning of existence. For a computer, however, an image is initially just a collection of numerical pixel values. There is no built-in concept of ears, whiskers, faces, or cats with questionable attitudes.

The same challenge appears in language, speech, videos, and other complex forms of data. Understanding a sentence requires more than counting words. Recognising a voice requires more than examining one audio sample. Understanding a video requires recognising patterns across both space and time.

This is where Deep Learning (DL) enters the picture. Deep Learning is a subfield of Machine Learning that uses neural networks with multiple layers to learn increasingly complex representations from data. Instead of manually defining every feature, we allow the network to discover useful patterns during training.

Think of it as teaching a computer to recognise the world by gradually moving from simple patterns to more meaningful ones. The machine does not suddenly wake up with intelligence. It adjusts millions, sometimes billions, of numerical parameters through training. Intelligence, it turns out, involves an unreasonable amount of matrix multiplication.

2. The Foundation — Artificial Neural Networks (ANN)

Before exploring CNNs, RNNs, or Transformers, we need to understand the basic structure behind neural networks: the Artificial Neural Network (ANN).

ANNs are computational models loosely inspired by the way biological neurons communicate. The word loosely is important here. An artificial neuron is a mathematical function, not a tiny biological brain sitting inside your computer waiting for its morning coffee.

A basic neural network consists of three major types of layers: an input layer, one or more hidden layers, and an output layer. The input layer receives data, hidden layers transform that data, and the output layer produces a prediction. Each connection between neurons has a weight, and each neuron may have a bias. During training, these parameters are adjusted to improve the network's predictions.

Imagine predicting whether a student will pass an examination using study hours, attendance, and assignment scores. The input layer receives these features. Hidden layers combine and transform them using learned weights and activation functions. The output layer might produce a probability representing the likelihood of passing. Of course, the model does not know whether the student actually studied or simply opened the textbook to take a photograph for social media. It only learns from the data provided.

Mathematically, a neuron can be represented as:

$$ z = \sum_{i=1}^{n} w_i x_i + b $$

$$ a = f(z) $$

Here, $x_i$ represents the input features, $w_i$ represents their corresponding weights, $b$ is the bias, and $f$ is an activation function. The output $a$ is the neuron's activated value.

Activation functions introduce non-linearity into neural networks. Without them, stacking multiple layers would essentially produce another linear transformation. Congratulations: you built a deep network that could have been replaced by a much simpler equation.

Common activation functions include ReLU, Sigmoid, and Tanh. ReLU outputs zero for negative inputs and keeps positive inputs unchanged. Sigmoid maps values between zero and one, making it useful in certain probability-based outputs. Tanh maps values between negative one and one.

The important idea is that each layer transforms information, allowing later layers to learn more useful representations. This ability to learn complex relationships is one of the reasons neural networks are so powerful.

3. Forward Propagation — How Information Travels Through a Network

Once the network receives input data, it needs to process that information and generate a prediction. This process is called Forward Propagation.

Information moves from the input layer through the hidden layers until it reaches the output layer. At each layer, the network performs mathematical operations using weights, biases, and activation functions. The final output represents the network's current prediction.

Consider an image classification model receiving an image of a dog. The network processes the numerical pixel values, transforms them through multiple layers, and eventually produces output scores for possible categories. It might predict dog with a probability of 0.92 and cat with a probability of 0.08.

Does that mean the network understands dogs? Not necessarily. It means that, based on its learned parameters, the network assigns a high score to the dog category. Understanding and pattern recognition are not automatically the same thing, despite what marketing departments might suggest.

Forward propagation is only half the story. We also need to measure how wrong the prediction is and use that information to improve the network.

4. Loss Functions — Measuring How Wrong the Model Is

A neural network needs a way to measure the difference between its predictions and the actual target values. This is the job of a Loss Function.

The loss function calculates how far the model's prediction is from the expected output. A higher loss generally indicates a worse prediction, while a lower loss indicates that the model is performing better according to the chosen objective.

For regression tasks, Mean Squared Error (MSE) is commonly used:

$$ MSE = \frac{1}{n}\sum_{i=1}^{n}(y_i-\hat{y}_i)^2 $$

Here, $y_i$ represents the actual value and $\hat{y}_i$ represents the predicted value.

For classification tasks, Cross-Entropy Loss is commonly used because it evaluates the model's predicted probability distribution against the correct class.

The choice of loss function matters because it defines what the network is trying to optimise. A model can be excellent at minimising its chosen loss and still be unsuitable for the real-world problem if the objective was poorly designed. Give a model the wrong goal and it will pursue that goal with impressive dedication. Much like a student who memorises every answer but understands absolutely nothing.

5. Backpropagation — How a Neural Network Learns From Its Mistakes

Now comes one of the most important concepts in Deep Learning: Backpropagation.

Forward propagation produces a prediction. The loss function measures the prediction error. Backpropagation then calculates how each trainable parameter contributed to that error by using the chain rule of calculus.

In simple terms, the network works backward from the output layer, calculating gradients that indicate how changes in weights and biases would affect the loss. These gradients provide the information needed to update the network's parameters.

This is where calculus becomes less of an academic punishment and more of an actual engineering tool.

The process is generally repeated across many training examples and iterations. The network makes predictions, calculates loss, computes gradients, and updates its parameters. Over time, these adjustments can improve its ability to recognise patterns in the training data.

Backpropagation itself does not decide how large each update should be. That responsibility belongs to an optimisation algorithm.

6. Optimisers — Deciding How the Network Improves

An optimiser uses gradients to update the network's trainable parameters. One of the most fundamental optimisation algorithms is Gradient Descent.

The basic update rule is:

$$ w_{\text{new}} = w_{\text{old}} - \eta \frac{\partial L}{\partial w} $$

Here, $w$ is a model parameter, $L$ is the loss function, and $\eta$ is the learning rate. The learning rate controls the size of each update.

If the learning rate is too large, the model may make unstable updates and fail to converge. If it is too small, training may become unnecessarily slow. Finding a suitable learning rate is important because apparently even mathematical optimisation needs a little patience.

Other widely used optimisers include Stochastic Gradient Descent (SGD), RMSprop, and Adam. Adam combines ideas related to momentum and adaptive learning rates, making it a popular choice for many neural network tasks.

An optimiser does not magically make a model intelligent. It simply provides a strategy for adjusting parameters so that the chosen loss can be reduced.

7. Understanding the Different Types of Neural Networks

Not all data has the same structure, and not every neural network is designed to handle every kind of problem efficiently. An image, a sentence, a time series, and a spreadsheet contain different patterns. Using the same architecture for every problem would be like using a screwdriver to cut vegetables. Technically, you can try. Nobody should trust the result.

Different neural network architectures are designed to capture different kinds of information. Three important families are Artificial Neural Networks, Convolutional Neural Networks, and Recurrent Neural Networks. Transformers introduced another powerful approach, particularly for handling sequences and relationships between different parts of the input.

8. Convolutional Neural Networks (CNN) — Teaching Machines to See

A Convolutional Neural Network (CNN) is a neural network architecture particularly effective at processing grid-like data, especially images.

An image contains spatial relationships. Nearby pixels often contribute to meaningful visual patterns, and objects can be recognised through combinations of edges, textures, shapes, and more complex structures.

A traditional fully connected network may require a large number of parameters when dealing with high-resolution images. CNNs address this challenge using convolutional layers, which apply learnable filters across local regions of the input.

Imagine showing a computer thousands of photographs of cats and dogs. Instead of manually telling it that cats have whiskers and dogs have particular facial structures, a CNN can learn useful visual features from examples. Early layers may detect simple patterns such as edges and textures. Deeper layers can combine these patterns into more complex representations.

A typical CNN architecture may include convolutional layers, activation functions, pooling layers, and fully connected layers. The convolutional layer extracts local features using filters. Pooling layers reduce spatial dimensions and can help create more compact representations. Fully connected layers may then use the extracted features to perform classification.

One of the most interesting properties of CNNs is parameter sharing. A filter is applied across different spatial locations rather than learning an entirely separate set of parameters for every position. This makes CNNs more efficient for many visual tasks.

CNNs are used in image classification, object detection, medical image analysis, facial recognition systems, and various computer vision applications.

But here is the interesting question: CNNs are excellent at learning spatial patterns. What happens when the order of information matters more than its spatial arrangement? For example, understanding a sentence, predicting tomorrow's temperature, or analysing a sequence of events?

That takes us to another architecture.

9. Recurrent Neural Networks (RNN) — Teaching Machines to Remember Sequences

A Recurrent Neural Network (RNN) is designed to process sequential data. Unlike a basic feedforward network, an RNN maintains a hidden state that carries information from previous time steps.

This makes it useful for tasks where the current input depends on what came before it.

Consider the sentence: "I went to the bank to deposit money." Understanding the word bank depends partly on the surrounding words. Without context, the model may struggle to distinguish a financial institution from the side of a river. Language, inconveniently, refuses to behave like a neat spreadsheet.

An RNN processes a sequence one step at a time. At each time step, it receives the current input and the previous hidden state, then produces an updated hidden state.

A simplified representation is:

$$ h_t = f(W_xx_t + W_hh_{t-1} + b) $$

Here, $x_t$ is the current input, $h_{t-1}$ is the previous hidden state, and $h_t$ is the updated hidden state.

The hidden state acts as a form of contextual memory. It allows information from earlier parts of a sequence to influence later predictions.

RNNs have been used in language modelling, speech recognition, time-series forecasting, and sequence prediction. However, traditional RNNs have limitations when dealing with long sequences.

One major problem is the vanishing gradient problem. During training, gradients can become extremely small as they are propagated backward through many time steps. This makes it difficult for the network to learn long-range dependencies. In other cases, gradients can become excessively large, producing unstable updates.

In other words, the network may remember what happened a moment ago but struggle to remember something important from much earlier in the sequence. A familiar problem, honestly.

10. LSTM and GRU — Improving the Memory of RNNs

To address some of the limitations of traditional RNNs, researchers developed more advanced recurrent architectures, including Long Short-Term Memory (LSTM) and Gated Recurrent Unit (GRU) networks.

LSTMs introduce a cell state and several gates that regulate how information is retained, updated, and removed. These gates help the network preserve useful information across longer sequences.

The forget gate determines what information should be discarded. The input gate controls what new information should be stored. The output gate determines what information should influence the current hidden state.

GRUs provide a simpler gated architecture, typically using fewer gates than LSTMs. They can perform well on many sequential tasks while maintaining a relatively compact structure.

Both architectures were important developments in sequence modelling. They helped neural networks handle longer dependencies more effectively than traditional RNNs in many situations.

However, recurrent architectures process sequences step by step, which can make parallel computation difficult. As models and datasets grew larger, researchers began exploring a different approach.

And that approach changed the direction of modern AI.

11. Transformers — When Attention Became the Main Character

A Transformer is a neural network architecture introduced in the 2017 research paper Attention Is All You Need. It changed the way many language and sequence-processing systems are designed.

Traditional RNNs process sequential data one time step at a time. Transformers, by contrast, use attention mechanisms to model relationships between different positions in a sequence. This allows them to process many input tokens in parallel during training, subject to the model's architecture and implementation.

The central idea behind Transformers is Attention.

Imagine reading the sentence: "The animal didn't cross the road because it was tired." To interpret the word "it", a language model needs to identify which earlier word it refers to. Attention mechanisms help the model assign different levels of importance to different parts of the input when constructing its representations.

The most well-known form is Self-Attention. It allows each token in a sequence to consider information from other tokens in that same sequence.

Self-attention uses three important representations: Query, Key, and Value.

A Query represents what a token is looking for. A Key represents information that can be matched against a query. A Value contains the information that contributes to the resulting representation.

The scaled dot-product attention operation is:

$$ Attention(Q,K,V) = softmax\left(\frac{QK^T}{\sqrt{d_k}}\right)V $$

Here, $Q$, $K$, and $V$ represent the Query, Key, and Value matrices, while $d_k$ is the dimensionality of the key vectors.

The attention scores determine how strongly different tokens influence one another. This allows the model to capture contextual relationships across a sequence.

Transformers also use Multi-Head Attention, which allows the model to learn different types of relationships simultaneously. Positional information is incorporated because attention alone does not automatically provide a sense of token order.

A typical Transformer architecture also contains feedforward neural network layers, residual connections, and normalisation components. Together, these mechanisms support the training of deep models.

Transformers are widely used in language models, translation systems, text summarisation, code generation, image processing, speech systems, and multimodal AI.

And yes, the architecture behind many modern language models belongs to this family. The next time an AI system generates a surprisingly convincing answer, remember that there is an enormous amount of learned numerical structure behind those words. It is not a tiny human living inside a GPU. Disappointing, perhaps, but considerably more practical.

12. CNN vs RNN vs Transformer — Different Problems, Different Strengths

It is tempting to ask which architecture is the best. Unfortunately, this is Deep Learning, not a school competition where everyone receives a ranking and one architecture gets a trophy.

CNNs are particularly effective at extracting spatial patterns from images and other grid-like data. RNNs are designed to process sequential information while maintaining a recurrent hidden state. LSTMs and GRUs improve the handling of longer dependencies through gating mechanisms. Transformers use attention to model relationships across input positions and have become central to many modern AI systems.

The choice depends on the task, dataset, computational resources, latency requirements, and deployment constraints. A Transformer is not automatically the best choice for every problem, just as a more expensive laptop does not automatically make its owner a better programmer.

Understanding the strengths and limitations of each architecture is much more valuable than memorising their names.

13. Training Deep Learning Models — From Data to Predictions

Building a Deep Learning model involves more than importing a library, writing a few lines of code, and waiting for an accuracy score to appear like a gift from the universe.

The process begins with understanding the problem and collecting relevant data. The data must be inspected, cleaned, transformed, and divided into training, validation, and test sets. Depending on the task, preprocessing may involve normalisation, resizing images, tokenising text, padding sequences, or encoding categorical features.

Next comes architecture selection. You need to decide whether a basic ANN, CNN, RNN, LSTM, or Transformer is appropriate for the problem. The model is then configured with its layers, activation functions, loss function, and optimiser.

During training, the model performs forward propagation, calculates the loss, computes gradients through backpropagation, and updates its parameters. This process repeats across batches and epochs.

An epoch represents one complete pass through the training dataset. A batch is a subset of the training data processed in one training step. Batch size, learning rate, number of epochs, and model architecture can all influence training behaviour.

Validation data helps monitor how well the model performs on examples that were not used to update its parameters. Finally, the test set provides an independent evaluation of the trained model.

And please, do not celebrate a 99% training accuracy before checking the validation results. Your model may have learned the underlying patterns. Or it may have memorised the training dataset and developed an unhealthy attachment to it.

14. Overfitting, Underfitting, and Regularisation — Keeping the Model Honest

Deep Learning models can contain millions or even billions of parameters. This gives them the capacity to learn highly complex patterns, but it also creates opportunities for overfitting.

Overfitting occurs when a model learns the training data too closely, including noise and irrelevant patterns, resulting in poor generalisation to unseen data.

Underfitting occurs when a model is too simple, insufficiently trained, or otherwise unable to capture the important patterns in the data.

Several techniques can help improve generalisation. Dropout randomly disables a proportion of neurons during training, reducing excessive dependence on particular activations. L1 and L2 regularisation penalise certain parameter values to discourage unnecessarily complex solutions. Data augmentation creates modified training examples, particularly useful in computer vision. Early stopping monitors validation performance and stops training when further learning begins to hurt generalisation.

The goal is not to build a model that remembers every training example. The goal is to build one that can recognise meaningful patterns in data it has never seen before.

A model that performs well only on familiar examples is not intelligent. It is just very good at remembering its homework.

15. Frameworks and Tools — Turning Mathematical Ideas Into Working Models

Understanding the mathematics behind Deep Learning is important, but implementing every neural network operation from scratch is not always practical. This is where frameworks such as TensorFlow, Keras, and PyTorch become useful.

TensorFlow provides tools for building, training, and deploying machine learning models. Keras offers a high-level interface that makes defining neural network architectures more approachable. PyTorch is widely used in research and development, offering flexible tensor operations and automatic differentiation.

These frameworks handle many lower-level operations, including gradient computation, tensor management, and GPU acceleration.

For example, a simple neural network can be created using Keras with a few layers, an optimiser, and a loss function. A CNN can be constructed using convolution and pooling layers. An RNN or LSTM can process sequences, while Transformer architectures can be implemented using attention layers or specialised libraries.

But remember: knowing how to call model.fit() does not mean you understand how the model learns. Frameworks make implementation easier; they do not replace the need to understand the underlying concepts.

16. Where Deep Learning Is Used in the Real World

Deep Learning is no longer limited to research laboratories or impressive conference demonstrations. It is used in systems that people interact with every day.

In healthcare, deep learning models can assist with analysing medical images and identifying patterns that may require further examination by professionals. In computer vision, CNN-based systems can support object detection, image classification, and quality inspection. In natural language processing, Transformer-based models power translation, summarisation, question answering, and code assistance.

Speech recognition systems convert spoken language into text. Recommendation systems use learned representations to identify patterns in user interactions. Autonomous systems use combinations of machine learning techniques to interpret sensor information and support decision-making.

Deep Learning is also being explored in scientific research, robotics, climate modelling, drug discovery, and financial analysis.

However, impressive performance does not eliminate limitations. Models can inherit biases from their training data, generate incorrect outputs, require substantial computational resources, and behave unpredictably outside their intended conditions.

A model can produce a beautifully formatted answer and still be completely wrong. Presentation is not evidence, and confidence is not accuracy. Humans should probably remember that too.

17. What Makes Deep Learning Different From Traditional Machine Learning?

Traditional Machine Learning often relies on manually selected or engineered features, depending on the problem and the algorithm. Deep Learning can learn useful feature representations automatically through multiple layers of computation.

For example, in a traditional image classification workflow, a developer might extract handcrafted features before training a classifier. A CNN can instead learn visual features directly from image data during training.

This does not mean Deep Learning always replaces traditional Machine Learning. Simpler models can be more efficient, interpretable, and effective when working with smaller structured datasets. Deep Learning tends to become particularly useful when working with large amounts of complex data, such as images, audio, text, and other high-dimensional inputs.

The real skill is knowing when to use which approach. Choosing a Transformer for a tiny dataset just because Transformers are fashionable is not innovation. It is an expensive way to discover that simpler solutions exist.

18. What to Explore Next — Turning Curiosity Into Experiments

If you have reached this point, you probably have a better understanding of why Deep Learning is such an important area of modern AI. But reading about neural networks is only the beginning. The interesting part starts when you build something, observe its behaviour, and investigate why it behaves that way.

Start with a basic ANN using a simple classification or regression dataset. Experiment with different numbers of layers, activation functions, and optimisers. Observe how changing the learning rate affects training.

Then move to CNNs. Build an image classifier and experiment with convolutional filters, pooling, data augmentation, and model evaluation. Try understanding what happens when the model receives an image that looks different from its training examples.

After that, explore sequence modelling through RNNs and LSTMs. Work with text or time-series datasets and observe how sequence length and context influence predictions.

Finally, study Transformers. Start with tokenisation, embeddings, positional encoding, self-attention, and multi-head attention. Understand the original Transformer architecture before jumping directly into large language models.

Do not rush through these topics just to collect architecture names for your résumé. Build small experiments, inspect the results, question unexpected behaviour, and gradually increase the complexity of your projects.

The goal is not to use every architecture. It is to understand why these architectures exist and what problems they were designed to solve.

19. Final Thoughts — The More You Learn, the More Interesting It Gets

Deep Learning is one of the most fascinating areas of Artificial Intelligence because it allows machines to learn complex representations from data. From ANN to CNN, from RNN to Transformers, each architectural development represents a different attempt to solve a fundamental challenge: how can a machine learn useful patterns from increasingly complex information?

The mathematics may look intimidating at first. Gradients, tensors, activation functions, attention mechanisms, and millions of parameters can make the subject feel like a collection of unrelated concepts. But once you understand how the pieces connect, the bigger picture becomes much clearer.

An ANN introduces the fundamentals of neural computation. CNNs demonstrate how networks can learn spatial features. RNNs introduce sequential processing and contextual memory. LSTMs and GRUs improve sequence modelling, while Transformers use attention mechanisms to capture relationships across input sequences.

And the most interesting part? These are not just concepts to write in an examination. They are the foundations behind technologies that are actively changing how we interact with information, software, research, and the world around us.

So, keep experimenting. Build networks that fail. Investigate why they fail. Change the architecture, inspect the loss curves, question the predictions, and learn to distinguish a genuinely useful model from one that has simply memorised its training data.

Keep building. Keep questioning. Keep debugging.

And remember, a neural network with 100 million parameters isn't automatically intelligent. It might just be 100 million opportunities for you to discover a bug.

In the margin

Enter to leave a note.

More from Utkarsh