A long-range dependency is a relationship between sequence elements far enough apart that earlier information can affect how a later element is interpreted or predicted. Capturing such relationships is a challenge for sequence models: an RNN processes elements one at a time, updating a recurrent state, and can struggle with long sequences and distant relationships. section 1.1.1 section 2.1.2
An LSTM can selectively remember or forget earlier information, and attention can help it account for long-term dependencies. But its input still arrives sequentially, slowing training and inference. Stacking recurrent layers can represent more complex patterns, yet makes error signals harder to propagate during training and can cause stability problems such as vanishing gradients. section 2.1.2 section 2.1.1
Transformer self-attention offers a different route: each position can consider other positions directly rather than relying on a state passed from one time step to the next. Attention scores express contextual relationships across the sequence; multihead attention lets the model examine different relationships in parallel. This supports long-range relationships without sequential input processing or deep recurrent-layer stacking. section 1.1.2 section 2.1.2
Figure 2.2 Comparing RNN (left) and self-attention (right) architectures. As illustrated, transformers, with their use of self-attention, can directly attend to all positions in the sequence, regardless of their position in time. Dashed lines represent the flow of information or dependencies. The variables x1 to x5 represent data input, and the circles above represent the state of the network at each timestep for the RNN. In contrast, for the self-attention mechanism, the circles above denote how each state considers information from all other states, not just the immediate predecessor.
Compare the RNN’s step-to-step information flow with self-attention’s direct links between sequence positions. section 2.1.2
Translation as a sequence task
To translate “I don’t speak French” into “Je ne parle pas français,” an RNN encoder reads the input word by word and passes a final context vector to its decoder. A transformer instead uses attention to relate input words to the rest of the sentence while producing contextual features for translation. The example illustrates the architectural difference; it does not isolate a particular distant word pair. section 1.1.1 section 1.1.2


