Recommended resources
The freely available resources this lesson will direct you to.
Hello! Welcome to the first lesson in our new module on the Transformer architecture.
In the previous module, we successfully built and trained a Recurrent Neural Network (RNN) in the form of an LSTM for sentiment analysis. We saw how these models process text sequentially, token by token, to understand language. This approach was the state-of-the-art for many years. However, the deep learning landscape has shifted dramatically, and today, nearly all cutting-edge NLP models are based on the Transformer architecture.
This lesson addresses a crucial question: why did this shift happen? Before we dive into the mechanics of the Transformer, we must first understand the fundamental limitations of the models it replaced. By the end of this lesson, you will be able to explain the key challenges of RNNs, such as their sequential nature, that paved the way for the Transformer revolution.
The Sequential Nature of RNNs
As we've seen, RNNs were a natural fit for sequential data like text. They process a sentence one word at a time, maintaining a hidden state that carries context forward. This mimics how a person might read.
Transformers Explained: The Discovery That Changed AI Forever
To set the stage, let's watch a brief segment from the video 'Transformers Explained' by Y Combinator. It perfectly describes why sequential models like RNNs were initially developed and introduces their core operational challenge.
Please watch from 00:52 to 02:04. This clip covers: Why early feed-forward networks failed at sequence tasks. How RNNs were designed to handle sequences by iterating through inputs. The introduction of the 'vanishing gradients' problem caused by this iterative process.
While intuitive, this step-by-step processing introduces several major limitations that ultimately hindered progress in the field. Let's examine them one by one.
Limitation 1: Sequential Computation Prevents Parallelization
The defining feature of an RNN is also its primary weakness. The computation of the hidden state at any given time step, , is dependent on the hidden state from the previous step, .
This means you cannot calculate until is complete, which in turn depends on , and so on. This creates a dependency chain that forces the computation to be performed in sequence.

This inherent sequentiality has a massive practical consequence: it prevents parallelization within a sequence. Modern hardware like GPUs and TPUs excel at performing thousands of operations in parallel. Because an RNN must process a sequence element by element, it cannot fully leverage this power. The time it takes to process a sequence scales linearly with the length of that sequence, making training on very large datasets incredibly slow.
Limitations of Traditional RNN Approaches
The article 'Limitations of Traditional RNN Approaches' from ApX Machine Learning provides an excellent technical summary of this issue.
Please read the section titled 'Sequential Computation Hinders Parallelization'. It clearly explains why the dependency on the previous hidden state becomes a bottleneck.
This limitation was a major motivation for finding an architecture that could process all elements of a sequence at once.

Limitation 2: The Challenge of Long-Range Dependencies
For a model to truly understand language, it needs to connect words that are far apart. Consider this sentence:
"The cat, which had been sleeping peacefully in the sunny spot by the window for several hours, finally woke up and purred."
To correctly predict "purred," the model must connect it back to "cat," which appeared many words earlier. This is known as a long-range dependency.
While LSTMs and GRUs were created with gating mechanisms to better control the flow of information and help with this problem, they don't fully solve it. The issue stems from the backpropagation process in RNNs, called Backpropagation Through Time (BPTT).
During BPTT, the gradient signal must travel backward from the end of the sequence to the beginning. At each step, it is repeatedly multiplied by the recurrent weight matrix.
- If the values in this matrix are small, the gradient can shrink exponentially, becoming so tiny that it has no effect on the early layers. This is the vanishing gradient problem. The model fails to learn the connection between distant words.
- If the values are large, the gradient can grow exponentially until it becomes unstable. This is the exploding gradient problem.
Limitations of Traditional RNN Approaches
For a deeper look at this, let's turn back to the 'Limitations of Traditional RNN Approaches' article.
Please read the section titled 'The Challenge of Long-Range Dependencies'. It explains how BPTT leads to vanishing and exploding gradients, making it difficult for the network to learn connections between distant elements.
Limitation 3: The Information Bottleneck
In many tasks, such as machine translation, a classic RNN architecture uses an encoder-decoder structure. The encoder RNN reads the entire input sentence and compresses all its information into a single, fixed-size vector (often its final hidden state). The decoder RNN then uses this single vector to generate the output sentence.
This creates an information bottleneck. Forcing a model to summarize a long, complex sentence into one small vector is extremely difficult. Inevitably, information is lost, especially details from the beginning of the sentence.
Transformers Explained: The Discovery That Changed AI Forever
The Y Combinator video eloquently explains this 'fixed-length bottleneck' and how it impacts performance.
Please watch from 03:10 to 04:14. Pay attention to how the single-vector summary limits the model's ability to handle long sentences and preserve word order, pointing to a 'deeper architectural problem'.
The attempt to solve this bottleneck with a mechanism called attention—which allowed the decoder to look back at all the encoder's hidden states—was a critical step. However, as long as this attention mechanism was paired with a recurrent structure, the fundamental problem of sequential computation remained.
Conclusion
In this lesson, we explored the critical weaknesses of RNNs that drove the search for a new architecture.
Key Takeaways:
- Sequential Computation: RNNs process data one element at a time, which prevents parallelization on modern hardware and makes them slow to train on long sequences. The runtime scales linearly with sequence length.
- Long-Range Dependencies: Due to the vanishing and exploding gradient problems during backpropagation, RNNs struggle to learn connections between words that are far apart in a sequence.
- Information Bottleneck: Classic RNN encoder-decoder models compress the entire input into a single fixed-size vector, making it difficult to retain all necessary information from a long input.
These three limitations—slowness, difficulty with long-term memory, and information compression—created a clear need for a model that could process all words in parallel and allow any word to directly connect with any other word, regardless of distance. The Transformer architecture, and its core component, self-attention, was the answer.
Preview of the Next Lesson
Now that we understand the problem, we can begin to study the solution. In our next lesson, we will dissect the engine of the Transformer: the self-attention mechanism. You will learn how it calculates relationships between all words in a sequence simultaneously, overcoming the limitations we've discussed today.