Notice: This page requires JavaScript to function properly.
Please enable JavaScript in your browser settings or update your browser.
Learn Why RNNs and CNNs Fall Short in NLP | Understanding Transformer Foundations
Transformers for Natural Language Processing

bookWhy RNNs and CNNs Fall Short in NLP

Swipe to show menu

When working with natural language processing, the structure and meaning of language often stretch across long spans of text. Early deep learning models like recurrent neural networks (RNNs) and convolutional neural networks (CNNs) were adapted from other domains to handle sequential data, but both approaches face critical bottlenecks when applied to language.

RNNs process input sequences one token at a time, maintaining a hidden state that is updated step by step. This sequential nature makes it impossible to parallelize computations across time steps, which slows down training and inference. Moreover, as the sequence grows longer, gradients passed back through many steps tend to shrink exponentially - a phenomenon known as the vanishing gradient problem. This makes it difficult for RNNs to learn dependencies from distant parts of a sequence, which is especially problematic for tasks like document classification or machine translation, where context from earlier in the text can be crucial.

CNNs, on the other hand, apply convolutional filters over fixed-size windows of the input. While CNNs allow for some parallelization and can capture local patterns efficiently, their local receptive fields mean that each output is only influenced by a limited context window. To capture longer dependencies, you must stack many convolutional layers or increase filter sizes, which quickly becomes inefficient and still struggles to model relationships between distant words in a sentence.

These bottlenecks become especially apparent in real-world text classification or sequence prediction tasks. For example, in sentiment analysis, the sentiment of a sentence might depend on a word at the beginning and another at the end. RNNs may struggle to connect these words due to vanishing gradients, while CNNs may miss the long-range connection entirely if it falls outside their receptive field.

Transformers address these limitations by using a self-attention mechanism that allows every token in the input to directly attend to every other token, regardless of their position in the sequence. This enables the model to capture long-range dependencies efficiently and makes it possible to parallelize computations across all positions in the sequence, greatly speeding up training and inference.

The following table summarizes the key differences between RNNs, CNNs, and Transformers on properties that matter for NLP tasks:

This comparison highlights why Transformers have become the architecture of choice for modern NLP applications.

question mark

Which of the following are key technical limitations of RNNs and CNNs in NLP, and how do Transformers overcome them?

Select all correct answers

Everything was clear?

How can we improve it?

Thanks for your feedback!

Section 1. Chapter 2

Ask AI

expand

Ask AI

ChatGPT

Ask anything or try one of the suggested questions to begin our chat

Section 1. Chapter 2
some-alt