Lecture 11: Why RNNs Were Not Sufficient — The Development into the Transformer
Part 1 (20 minutes) — Intuitive introduction with analogies and examples
Language models aim to process spoken or written language as a sequence of words or characters and to make predictions, such as the next word or the agreement between sentence parts. Previously, many of these models were built on sequential architectures: Recurrent Neural Networks (RNNs) and their evolved variants like LSTM or GRU. The basic idea in RNNs is that the model updates a kind of "short-term memory" at each new word — a hidden state representation that summarizes information from the sequence seen so far.
A vivid analogy is that of a message whispered along a chain of people. Each person hears the message so far and adds to or modifies it. In this way the RNN tries to keep an updated summary with each new input word. This approach has advantages: it is naturally sequential and requires only a compact internal representation per time step.
However, two practical problems arise when texts become very long. First, important information can "blur" or "leak" across many time steps — early details are lost in the compact state representation. Second, the sequential passing of information is a bottleneck for training: gradients that are backpropagated during learning must traverse many steps, which can be numerically problematic and slow training. These phenomena are discussed extensively in the literature (see Bengio et al., 1994; Pascanu et al., 2013).
Researchers responded with technical improvements: LSTM and GRU cells introduced mechanisms that store or forget information more selectively, for example via "gates" that decide what is retained (Hochreiter & Schmidhuber, 1997). This mitigated some problems but did not fully solve them, especially when models needed to learn very long-range dependencies or many diverse, distant relationships.
A second image for clarification: Imagine a librarian who has only one notepad to remember all the books she has read. For short texts the notepad is sufficient; for long sequences of books the precision degrades. LSTM/GRU are like a notepad with compartments: better organization, but still limited space. The question was: How can a model directly and efficiently access arbitrary earlier positions without having to step through everything sequentially?
Part 2 (20 minutes) — Technical terms and deeper explanation
To understand why the Transformer is a fundamentally different model, we need to introduce some terms precisely. "Backpropagation Through Time" (BPTT) denotes the method by which gradients are computed in RNNs: the network is unfolded over time steps, and gradients are backpropagated along this temporal chain. In this process gradients can become very small (vanishing gradients) or very large (exploding gradients); both make learning long-term dependencies difficult (Bengio et al., 1994; Pascanu et al., 2013).
LSTM (Long Short-Term Memory) extends the RNN by introducing a cell state and gates that control which information enters, which is retained, and which is output. This design reduces the vanishing gradient problem and allows certain information to be stabilized across longer steps (Hochreiter & Schmidhuber, 1997). In practice, LSTM-based sequence-to-sequence models improved the quality of translations and other tasks (Sutskever et al., 2014).
Another important step was the introduction of attention mechanisms. Work on neural machine translation showed that an internal mechanism that explicitly weights parts of the input substantially improved performance. Instead of compressing everything into one compact vector, the model can directly "look at" relevant parts of the input (Bahdanau et al., 2014). This principle upgrades the notepad analogy: instead of having only one sheet, the system can consult a shelf selectively.
The Transformer took this idea further and replaced the sequential core structure entirely with "self-attention." Self-attention computes, for each position in a sequence, how strongly it interacts with every other position. Technically, for each token query, key, and value vectors (Query, Key, Value) are computed; the compatibility of Query and Key produces the weights with which the Values are mixed into a new representation (Vaswani et al., 2017).
Important technical terms, briefly defined: "Self-Attention" describes the procedure by which elements of a sequence weight each other; "Multi-Head Attention" means multiple independent attention heads simultaneously learn different aspects of relationships; "Positional Encoding" is a mechanism that supplies the Transformer with information about the order of tokens, since the pure attention operation itself does not encode sequence order (Vaswani et al., 2017).
Two technical consequences are crucial: First, self-attention in a given layer is directly effective between all pairs of positions — long-range dependencies do not have to be passed along sequentially but can be modeled in a few steps. Second, the structure allows extensive parallelization during training because the computation does not have to proceed strictly step-by-step in time. These aspects explain why transformer models are often both more efficiently trainable and more powerful for many language tasks than classical RNN-based models (Vaswani et al., 2017).
At the same time it is important to mention: attention has costs. Naive self-attention scales quadratically with sequence length in terms of computation time and memory, because a weight is computed for every pair of positions. This limitation is an active area of research to make it manageable for very long texts (Vaswani et al., 2017). In addition, transformer models require large amounts of data and compute resources to realize their potential; this is a practical, not purely theoretical, issue.
Part 3 (10 minutes) — Applications, limits and thought exercises
Concrete applications illustrate the difference: in machine translation early RNN sequence-to-sequence models already produced sensible results (Sutskever et al., 2014), but jumps in quality and efficiency were achieved only with attention mechanisms and later with transformers. Transformer models then came to dominate many NLP tasks, such as text classification, question answering, text generation and more (Vaswani et al., 2017).
Limits and open issues are also a reality: the quadratic cost structure of self-attention complicates very long contexts; furthermore, transformer models are data- and compute-intensive. Research efforts try to address these limitations through sparse or approximate attention designs, hybrid architectures, or efficient training methods. There remains active research; there is no final consensus on which solutions will be best in the long term.
To consolidate learning, three short thought exercises you can work through alone or in groups: First: Take a long sentence with a pronoun whose antecedent is many words away (e.g., "The scientist who had written the report later showed us that he was mistaken."). Consider which mechanisms an RNN, an LSTM and a Transformer would use to assign the correct referent for "he", and what weaknesses each might have. Second: Imagine you need to train a model to link information from arbitrarily distant text positions. Which aspects of the architecture (memory capacity, direct access to previous positions, training efficiency) are most important to you and why? Third: Discuss advantages and disadvantages of the parallelizability of transformers versus sequential RNNs — for both training (batch size, hardware utilization) and inference (latency, streaming requirements).
Finally a note for context: the shift from RNNs to attention-based models is a well-documented development in the research literature and in practical systems (Bahdanau et al., 2014; Vaswani et al., 2017). LSTM/GRU were important steps and remain relevant in many applications, but the Transformer has shown fundamental advantages in several areas. At the same time practical limits and active research questions remain; it is not a definitive solution to all problems in language processing.