On the Computational Power of Transformers and Its Implications in Sequence Modeling
Paper · 2020 · Satwik Bhattamishra, Arkil Patel and Navin Goyal
Summary
A Transformer receives an entire input sequence at once, yet many tasks require it to use that sequence in order and remember what it has already done. Bhattamishra, Patel and Goyal ask how a Transformer can carry out those operations and which parts of the architecture make them possible. Their test of computational power is Turing completeness, the ability to simulate any computation a Turing machine can perform. They study the full encoder–decoder architecture under idealized conditions. The encoder prepares the input for the decoder, which can keep working after the input has been processed.
The authors prove that a Transformer can reproduce the state updates of a recurrent neural network, whose computational power under arbitrary precision was already established. With explicit positional encodings, the decoder uses a position stored in its current vector to retrieve the next input symbol. With positional masking alone, it can see only a growing prefix of the input. Comparing symbol frequencies in successive prefixes tells it which symbol just arrived. The decoder can then retrieve the embedding for that symbol and carry out the same recurrent update. Both constructions use hard attention, which gives equal weight to all entries tied for the highest score and assigns zero weight to the others.
The proofs also explain why the placement of a residual connection matters. A residual connection adds a block’s input back to its output. Around the attention block that reads the encoder, this addition lets the decoder carry forward its current state while bringing in fresh information. Remove it and the block can convey the state only indirectly, through its choice among combinations of encoder values. For a fixed input, hard attention gives it a finite menu of such combinations. Other connections can be omitted in the proofs because a remaining path can pass the required information through.
The experiments show how these distinctions play out after training. Removing the residual connection around attention to the encoder leaves copying nearly intact but brings the counting score to 0.0 on the BLEU score metric. It also lowers translation scores on both language pairs tested. A separate copying experiment finds that a Transformer using masking alone can handle longer sentences than the version with absolute positional encodings, though its performance also deteriorates at greater lengths. These tests show that architecture choices can affect what training produces even when a proof establishes the same theoretical computational power.
Deep dive: On the Computational Power of Transformers and Its Implications in Sequence Modeling
How Transformers recover input order, carry computation across decoding steps, and behave when positional encodings or residual connections are removed. · about 38 minutes to read
The problem and its context
What an architecture can express
A low score on a sequence task leaves open several explanations. The architecture might lack a way to perform the required operation. It might have such a way, but training might fail to find it. Or the solution that training finds might work for examples like those seen during training and fail when a property such as input length changes. The paper takes up the first question through proofs, then uses experiments to examine how the other questions arise for particular Transformer variants.
The distinction mattered because self-attention had already become a practical basis for sequence processing. Attention allows a position to retrieve information from other positions through scores and weighted combinations of vectors. The original Transformer made this operation central to its encoder and decoder. The paper situates that architecture in work on machine translation, prediction of text, and question answering. It cites translation scaling experiments and BERT as examples of the wider success of architectures built around attention. Attention Is All You Need · Scaling Neural Machine Translation · BERT
The theory of recurrent neural networks offered a starting point. A recurrent network reads an input, combines it with a hidden state, and produces a new hidden state. The hidden state is the information passed from one computation step to the next. Siegelmann and Sontag had shown that a recurrent network with arbitrary numerical precision could simulate a Turing machine. The paper also cites a universality result for recurrent networks with rectified linear activations, along with work on more specific language-recognition abilities such as counting and matching brackets. This earlier work already distinguished a result about the full range of possible computations from an investigation of how a particular network handles a particular sequence pattern. Closing Brackets with Recurrent Neural Networks
Pérez and colleagues had already proved Turing completeness for a formalized Transformer using hard attention and arbitrary precision. That proof supplied a positive answer for the architecture as a whole. The question Bhattamishra and colleagues pursue is what can be learned by examining individual paths through it. A Transformer can use attention among input positions, attention among decoder positions, and attention from the decoder to the encoder. Each block can sit alongside a residual connection, and each layer also includes a feedforward network, a function that transforms a vector without maintaining recurrent state of its own. A universality proof that uses these parts leaves room to ask whether some of them can substitute for one another and whether some carry information no other path can supply.
How order reaches attention
An ordinary attention calculation scores each key against a query and combines the attached values. If the keys and their accompanying values are rearranged together, the resulting combination stays the same, provided the query sees the same collection and the vectors themselves stay fixed. This creates a problem for sequence processing. The order of input symbols matters, but their order in a list of otherwise unchanged keys and values does little by itself for an attention query. The architecture needs some route by which order can affect the computation.
Explicit positional encoding is one route. It supplies each vector with information derived from the position it occupies. After that addition, equal symbols at different positions can have different representations. Earlier work discussed by the authors had explored several ways of representing position, including relations between positions. The paper focuses on what happens when the explicit position information is omitted and attention is constrained by a mask instead.
A directional mask determines which positions can contribute to a calculation. For attention over an input prefix, a change in position changes which entries are visible. This gives the network access to an ordered progression of collections even if a single attention calculation still treats the visible keys and values as a collection. Earlier translation experiments by Yang and colleagues had found comparable performance with masking alone and with positional encodings. Tsai and colleagues had raised the resulting theoretical question of whether explicit position vectors are needed when a mask already imposes direction.
A second question from the earlier work concerned residual connections. A residual addition is frequently associated with training deep networks because information has a direct path through a block. For a proof about computational power, the more immediate issue is what that path carries. If the block is responsible for reading the input, its residual path can preserve the decoder’s current state during the read. If it merely needs to leave a vector intact, either a suitable attention calculation or a residual path might do the job. The paper treats these as questions about specific connections, since calling every skip path a residual connection says little about which information would disappear if a particular one were removed.
Why the decoder changes the question
The paper distinguishes its setting from earlier analyses of encoders. Hahn’s work addressed limitations involving regular and context-free languages, and Yun and colleagues studied universal approximation for sequence-to-sequence functions. As Bhattamishra and colleagues describe them, those analyses concerned encoder-only settings with fixed-length outputs. The calculation ended once the input had been processed. The full Transformer studied here can instead produce a variable-length sequence, and its decoder can continue to operate after the last input symbol.
That extra time is part of the computational resource. A recurrent network can finish reading a sequence and then continue updating its state. To simulate that behavior, the Transformer needs a way to keep taking steps and a rule for what it will read once it has used the input. These requirements explain why a terminal symbol figures prominently in both constructions. It signals that the input has ended while also providing a value the decoder can retrieve repeatedly during the remaining computation.
The target is also different from a benchmark that gives a network examples of a language and measures how well it classifies unseen strings. The proof starts with a recurrent network that already implements the computation of interest. The authors then build a Transformer with parameters and vectors chosen to reproduce that recurrence. The empirical part starts from training data and examines what parameter fitting produces. Keeping the two starting points in view makes it possible to read the proof as a claim about what can be built and the experiments as observations about what can be learned in their setups.
The method, step by step
What the Transformer has to reproduce
The authors reduce the problem to simulating a recurrent neural network, abbreviated RNN. The RNN receives the symbol embeddings in sequence. Its state at each step depends on the previous state and on the embedding supplied at that step. The Transformer is given all input embeddings in advance, so it has to turn simultaneous access to the input into the same succession of state updates. It must place the RNN’s state inside the decoder vector at the corresponding step and halt when the RNN halts.
The reduction relies on the earlier construction by Siegelmann and Sontag. In the paper’s account, the RNN state has space for the finite control state of a Turing machine and for rational quantities representing the contents of its tape. Those numerical quantities behave like stacks whose contents can be encoded and updated. Arbitrary precision lets a rational coordinate preserve the information required by a growing stack. The simulation follows an accepting computation into an accepting state. Where a partial computation is undefined and the Turing machine continues indefinitely, the simulating system also fails to reach its halting state. This is a statement about computations and their termination, as well as about the states encountered along the way.
The alphabet is denoted by Σ, and its size is m. The authors use the symbols named hash and dollar as the start and end markers. A base embedding gives each symbol a rational vector. The markers have zero base embeddings in the preliminaries, but the directional construction can still distinguish them because it also represents the identity of each symbol in a separate part of its vector.
xᵢ = fᵦ(sᵢ)
Here sᵢ is the input symbol at position i, fᵦ is the base embedding function, and xᵢ is the vector that represents the symbol at the RNN’s input. The base embedding has dimension dᵦ, meaning it has dᵦ coordinates. The coordinate values are drawn from ℚ, the rational numbers. In the Transformer constructions, the authors expand this embedding with additional coordinates for information such as state, symbol identity, or position. In the architecture equations below, xᵢ denotes that full input vector when referring to the Transformer.
hₜ = g(Wₕhₜ₋₁ + Wₓxₜ + b)
Here hₜ is the hidden state at step t, and hₜ₋₁ is the state from the preceding step. The matrix Wₕ transforms the earlier state, Wₓ transforms the current embedding xₜ, and b is a bias vector. The function g is a feedforward network that acts on their sum. The hidden state has dimension dₕ, and the recurrence starts from the initial state h₀ in the general RNN definition. The state coordinates can carry information from many earlier steps because every update receives the result of the preceding update.
After the RNN reads the last ordinary symbol, it receives the terminal embedding on each subsequent step until it halts. The Transformer cannot know in advance how many such steps to provide for. The authors therefore place one terminal marker at the end of its input and arrange for the decoder to keep retrieving it. This is an example of the reduction’s basic strategy. The input vectors and attention rules handle access to the symbol, while a feedforward block performs the update that the RNN would have carried out on seeing it.
How the Transformer simulates recurrent computation
The steps in order.
The operations used in both proofs
The feedforward blocks in the construction use a saturated linear activation. Below zero it returns zero. Between zero and one it leaves its input unchanged. Above one it returns one. The authors express it in terms of rectified linear units, which themselves return the input when it is positive and zero when it is negative.
σ(x) = ReLU(x) − ReLU(x − 1)
Here x is a scalar input, σ is the saturated activation, and ReLU is the rectified linear activation. The first ReLU discards negative inputs. The second removes any amount above the upper endpoint. When σ is applied to a vector in the construction, it acts on each coordinate separately. Among other uses, this lets the directional decoder keep the positive components of a frequency difference while discarding the nonpositive ones.
An attention block receives a query and a collection of keys and values. A key helps determine when an entry will be selected, and the value is the information retrieved if it is selected. This distinction lets the authors arrange for a key to represent a position or a symbol identity while its corresponding value carries an embedding. The query then addresses the embedding using whichever information the key supplies.
(α₁, …, αₙ) = ρ(fₐₜₜ(q, k₁), …, fₐₜₜ(q, kₙ))
Here n is the number of entries available to the query q. The vector kᵢ is the key at entry i, and fₐₜₜ gives the score of a query against a key. The function ρ turns the scores into the weights α₁ through αₙ. The paper uses hardmax for ρ. If the maximum score occurs r times, each of its occurrences gets weight 1/r and every other entry gets weight 0. Thus a unique winner supplies the entire result, while a tie produces an average of the winning values. This normalization preserves rational weights.
Att(q, K, V) = α₁v₁ + ⋯ + αₙvₙ
Here Att is the attention output for query q, K is the sequence of keys, and V is the sequence of paired values. The vector vᵢ is the value at entry i and αᵢ is its weight from the scoring and normalization calculation. This rule supports two different operations in the proofs. A single winning key can pick out the vector associated with a particular position. An intentional tie can turn a set of vectors into a summary, as when the directional construction builds a histogram by averaging one-hot symbol vectors.
The encoder transforms the input sequence and then supplies keys and values to the decoder. Inside an encoder layer, the query, key and value transformations are linear. The function Q constructs a query at a position, while K and V transform vectors into keys and values. Applied to a sequence, K and V transform its entries individually. The encoder’s attention output is added to the original vector at that position.
aᵢ = Att(Q(xᵢ), K(X), V(X)) + xᵢ
Here X is the encoder layer’s input sequence, xᵢ is the vector at position i, and aᵢ is the result after the attention block and its residual addition. The notation Q(xᵢ) identifies the query derived from xᵢ. A full encoder attention block can draw on the sequence X. In the directional architecture, the available list ends at position i, so that the keys and values come from the prefix Xᵢ.
zᵢ = O(aᵢ) + aᵢ
Here O is the encoder layer’s feedforward network and zᵢ is the layer output at position i. The residual addition preserves a direct route from aᵢ to zᵢ. Several encoder layers can be composed by passing the complete sequence of layer outputs to the next layer. The final encoder transformations create the key sequence Kᵉ and the value sequence Vᵉ for use in the decoder. The superscript e distinguishes these encoder outputs from keys and values formed within a decoder layer.
The decoder receives the encoder’s keys and values as well as the decoder sequence available so far. Its first attention block operates over decoder positions. It uses a mask so that a position can use its own vector and earlier vectors. The next block uses the result as a query over the encoder. The feedforward operation acts after these two reads.
pₜ = Att(Q(yₜ), K(Yₜ), V(Yₜ)) + yₜ
Here yₜ is the input vector at decoder position t, Yₜ is the decoder prefix through that position, and pₜ is the output of decoder self-attention with its residual addition. The functions Q, K and V are the decoder layer’s own transformations. The prefix restriction is what the paper calls positional masking in this block. It prevents a contribution from a later decoder position.
aₜ = Att(pₜ, Kᵉ, Vᵉ) + pₜ
Here aₜ is the output of attention from the decoder to the encoder, including the residual addition. The query is pₜ, while Kᵉ and Vᵉ contain the information made available by the encoder. In the directional architecture, the mask restricts this block to the encoder prefix exposed at that step. Once the terminal position is reached, that prefix remains the full sequence. The addition of pₜ preserves the query vector’s contents beside the retrieved value. The proofs use this addition to make the old state and the current input simultaneously available to the following block.
zₜ = O(aₜ) + aₜ
Here zₜ is the output at decoder position t and O is the decoder layer’s feedforward network. This is where the constructions compute the new recurrent state. With several decoder layers, each layer acts on a sequence of vectors. After the final layer, the transformation F acts on its last vector, so the full decoder call returns a single vector. The proofs assign F the identity function where the vector already has the form needed for feedback.
ỹₜ₊₁ = TDec(TEnc(X), (y₀, …, yₜ))
Here TEnc is the full encoder, TDec is the full decoder, X is the input sequence, and y₀ is the decoder’s seed. The parenthesized vectors form the sequence available at step t. The vector ỹₜ₊₁ is the next decoder result before any positional vector is added. In the architecture with positional encodings, the decoder adds the encoding for the next position to obtain yₜ₊₁. In the directional architecture, yₜ₊₁ is the decoder result itself. A prescribed halting set specifies which vectors signal the end of computation. The recurrent state stored in the vectors lets the simulation preserve the RNN’s decision to halt.
Reading a symbol by its explicit position
The first construction uses one encoder layer, one decoder layer and one attention head. A head is one attention calculation with its own transformations. The encoder reserves different coordinates for the input embedding and the input position. Coordinates needed later for the recurrent state begin at zero. With these choices, the vectors can hold the state and the embedding in separate places when they are brought together in the decoder.
d = 2dₕ + dᵦ + 2
Here d is the Transformer vector width in the construction, dₕ is the RNN hidden-state width, and dᵦ is the base embedding width. The vector has two blocks of state width, one embedding block, and two scalar coordinates. The state blocks provide room for storing and manipulating the old and new recurrent quantities. The final coordinates are used for positional calculations.
xᵢ = [0ₕ, fᵦ(sᵢ), 0ₕ, i, 1]
Here square brackets concatenate the blocks into one vector. The symbol sᵢ occupies position i, fᵦ gives its base embedding, and 0ₕ denotes an all-zero block of width dₕ. The last coordinates contain the position i and a constant 1. They are the explicit position information used for lookup. The same ordinary symbol can therefore receive different full vectors at different positions.
The encoder makes its attention and feedforward outputs zero and lets the residual paths carry xᵢ through unchanged. A linear key transformation then places −1 and the input position in the final coordinates of the key, leaving the other coordinates zero. A separate value transformation keeps the symbol embedding and zeros the other blocks. The key says where to look, and the value delivers what to read. Decoder self-attention can also return its input unchanged by giving its attention branch zero values and using its residual path.
The decoder now needs the earlier state and a positional coordinate specifying what to read next. In the construction that labels the first lookup with position 1, the decoder vector yₜ carries the state hₜ and a position coordinate t + 1. The key and query interact only in their last coordinates, so the attention score is determined by the distance between the input position and the requested one.
fₐₜₜ(pₜ, kᵢᵉ) = −|⟨pₜ, kᵢᵉ⟩| = −|i − (t + 1)|
Here fₐₜₜ is the attention scoring function for the construction with positional encodings. The vector pₜ is the query at decoder step t, kᵢᵉ is the encoder key at position i, and ⟨pₜ, kᵢᵉ⟩ denotes their dot product. The vertical bars indicate absolute value. Taking its negative makes a closer position receive a larger score. When the requested position is available, that position is the unique winner. When the requested position extends past the input, the final position is closest. Its terminal embedding can therefore be retrieved again at later steps.
The cross-attention residual addition puts the old state next to the new embedding. The feedforward network computes the recurrent update and uses its output to correct what the residual path would otherwise leave in the vector. In the state block it returns the new state minus the old state. When the old state is added back, the new state is what remains. It also cancels the embedding that has already been consumed and clears the position coordinates used for the lookup. The next decoder vector receives its associated position information for the next read. The argument starts with a seed containing the required initial state and shows that one correct decoder vector leads to the next.
This construction changes the way the RNN receives its inputs while leaving the state update intact. The RNN would receive the next embedding directly. In the Transformer, the embedding comes from an encoder value chosen by a decoder query. Once the state and embedding enter the same feedforward computation, the decoder can reproduce the recurrence. The authors use this stepwise correspondence to obtain the universality result from the known computational power of the RNN.
Reading a symbol from a change in the prefix
The directional construction keeps the same objective but changes the source of position information. Input vectors contain the base embedding and a one-hot vector for the symbol. A one-hot vector has a 1 in the coordinate belonging to that symbol and zeros elsewhere. Two occurrences of the same symbol thus have equal input vectors. The encoder projects symbol identities into its keys, and it puts both the identity and the base embedding in its values, using separate coordinate blocks. The encoder can again perform these preparations with a single layer that mainly passes its inputs through.
The decoder has two layers. The first determines which symbol the mask has just exposed. The second retrieves that symbol’s embedding and updates the recurrent state. To see why the first layer can work, consider what the mask supplies as decoding advances. Each prefix contains all the symbols in the preceding prefix and the symbol at the new position. Averages over the prefixes can therefore differ even when the individual vectors contain no explicit positions.
ωₜ = (1/(t + 1)) ∑ⱼ₌₀ᵗ onehot(sⱼ)
Here ωₜ is the vector of symbol proportions in the prefix ending at t, with one coordinate for each member of Σ. The summation index j runs from the start position 0 to position t, and onehot(sⱼ) is the one-hot identity vector for the symbol sⱼ. Dividing by t + 1 turns counts into proportions. The preceding histogram is denoted ωₜ₋₁, with ω₋₁ set to the zero vector for the initial comparison. After the end of the input the available prefix stops growing and its histogram stays fixed.
The first decoder layer obtains this histogram by making all visible keys tie. The query has zero entries where those keys carry their symbol identities, so all their dot products are zero. Hardmax assigns every visible value the same weight. The average contains the histogram in the block that holds the one-hot vectors. Other blocks can contain quantities the layer has no further use for, such as the average of the base embeddings. The feedforward network can clear those blocks when it prepares a vector for the next layer.
The previous histogram arrives through the decoder state. The cross-attention residual connection keeps it present when attention supplies the new histogram. Comparing the two gives a way to identify the new symbol. Its count has increased by one, while the total length has also increased. A symbol whose count stays fixed can only keep or lose proportional share. The symbol whose count increases gains share whenever the previous prefix contained a different symbol. The unique start marker ensures that condition for the ordinary symbols. At the start step, comparing the first histogram with the all-zero initial histogram exposes the marker itself.
(ωₜ − ωₜ₋₁)ₖ = (t − φₜ₋₁,ₖ)/(t(t + 1)) if sₜ = βₖ
Here k denotes a coordinate of the histogram and βₖ is the corresponding alphabet symbol. The count φₜ₋₁,ₖ gives the number of occurrences of βₖ before position t. The equality applies to a growing prefix after the start step, when the newly exposed symbol sₜ is βₖ. The unique start symbol ensures that the earlier occurrences of the newly exposed symbol occupy fewer than t positions. The numerator and the resulting change are therefore positive.
(ωₜ − ωₜ₋₁)ₖ = −φₜ₋₁,ₖ/(t(t + 1)) if sₜ ≠ βₖ
Here the symbols have the same meanings and the condition refers to a coordinate whose symbol was not newly exposed. Its numerator is zero or negative because its count stayed fixed. The two expressions describe how the same averaging mechanism gives opposite sign conditions for the new symbol and the remaining ones.
Δₜ = σ(ωₜ − ωₜ₋₁)
Here Δₜ is the vector of changes after the coordinatewise saturated activation σ. The two ω vectors describe the current and previous prefixes. The activation retains the positive increase and discards the zero or negative differences. Its role is to prepare a query whose dot products with one-hot keys will single out the symbol that caused the increase.
The construction reserves a separate rule for the end marker so that the recurrent computation can continue after the prefix has stopped growing. The decoder keeps a positive scalar, halves it at each step, and uses the updated scalar as the end marker’s query coordinate. The first layer builds the query by taking the ordinary coordinates from the clipped difference and substituting that scalar for the terminal coordinate.
δₜ = (Δₜ,₁, …, Δₜ,ₘ₋₁, 1/2ᵗ⁺¹)
Here δₜ is the symbol-query block at step t and m is the alphabet size, with the terminal marker in its final coordinate. The entries Δₜ,₁ through Δₜ,ₘ₋₁ are the clipped changes for the symbols preceding the terminal marker in the alphabet. The quantity 1/2ᵗ⁺¹ is the positive terminal score at that step. The marker is outside the visible prefix until the end, so the positive coordinate supplies no competing key earlier. Once the marker becomes visible it can win, and it continues to win after the histogram ceases to change. Exact rational arithmetic lets the scalar stay positive through as many steps as the construction requires.
The second decoder layer uses this query to retrieve an embedding. Its scoring rule is the ordinary dot product. Since an encoder key contains the one-hot identity of its symbol in the relevant block, the score reads off the coordinate of δₜ for that symbol.
fₐₜₜ(pₜ⁽²⁾, kⱼᵉ) = ⟨δₜ, onehot(sⱼ)⟩
Here pₜ⁽²⁾ is the query in the second decoder layer at step t, kⱼᵉ is the encoder key at visible position j, and sⱼ is the symbol at that position. The superscript identifies the second layer. The dot product on the right uses the query’s symbol block δₜ and the key’s one-hot symbol block. For an ordinary decoding step, the positive score belongs to all visible occurrences of the newly exposed symbol. The other visible symbols receive zero. When the current step calls for the terminal marker, its coordinate supplies the winning score.
Several keys may win because the same symbol can appear repeatedly. In this construction their values agree, since the value transformation retains the base embedding and identity of the symbol without encoding its position. Averaging them recovers the same embedding as averaging a set with a single copy. The decoder can therefore feed the RNN the correct symbol even though the attention weights do not distinguish the most recent occurrence from earlier identical ones.
The last feedforward block combines that embedding with the recurrent state preserved by the residual path. As in the first proof, it computes the state update and cancels the blocks that should be empty before feedback. In this case it also preserves the latest histogram and the scalar used at the terminal coordinate. The next decoding step starts with the updated state and the information needed to repeat the prefix comparison. Induction supplies the same guarantee as in the explicit-position construction. If the decoder vector holds the right state and auxiliary quantities at the current step, the next one will hold their correctly updated forms.
From constructed weights to trained systems
The proofs specify attention transformations, embeddings and feedforward operations directly. The experiments use learned parameters. Their procedures therefore answer a different question about what happens when an architecture is trained on examples. The authors adapt an existing Transformer implementation for the synthetic residual-connection comparisons and use OpenNMT for translation. They release the study’s code under the repository name Transformer-Computation-Analysis.
The synthetic comparisons use a single encoder layer, a single decoder layer and a single attention head in each block. The trained variants share that layout and differ by which residual path is removed. For the translation experiments, the authors tune the learning rate, warmup step count, head count, embedding size, and feedforward embedding size while trying layer counts from one through four. Warmup concerns the initial part of the learning-rate schedule. The experiments use the noam optimizer. The directional copying comparison is based on Yang and colleagues’ implementation, with unidirectional masking in place of the bidirectional masking used in that earlier setup. The authors tune depth, learning rate, warmup and head count for that comparison.
Experiments and results
Copying sentences and extending a numerical sequence
The synthetic tasks are designed to put different demands on the decoder. The copy task uses the same sentence as both input and target. The word that should be emitted is already present in the source. If the decoder can locate that word at the relevant position, it can make progress by repeatedly reading and reproducing the input. The authors sample sentences of 5-12 words from Penn Treebank. They use a 40k-1k train-test split, with both parts in the same length range. This comparison measures copying when held-out sentences are drawn from the range of lengths seen in training.
For counting, a single number between 0 and 100 is presented to the encoder. The target is the next five numbers. Each successive output changes even though the source is the same. The task thus tests the decoder’s ability to use a calculation from an earlier step to produce a new result. The authors compare the vanilla Transformer, a variant without the residual connection around attention to the encoder, and a variant without the residual connection around decoder self-attention. The last variant tests whether removing a different skip path produces the same behavior.
The paper reports BLEU for both tasks, with higher scores indicating closer agreement with the target sequences. On held-out Penn Treebank copying, the vanilla Transformer scores 100.0 and each residual-removal variant scores 99.7. At these lengths, the variant that loses the residual around attention to the encoder can still recover and reproduce enough source material to score close to the intact system. This gives the counting comparison a baseline. The same variant can learn a source-dependent transduction under the copying conditions.
BLEU on the Penn Treebank copy test
Both residual-removal variants stay close to the intact Transformer on held-out sentences in the training length range.
The numbers
| System or setting | BLEU |
|---|---|
| Vanilla Transformer (this paper) | 100.0 |
| Without decoder–encoder residual | 99.7 |
| Without decoder self-attention residual | 99.7 |
The counting results separate the residual paths. The intact Transformer obtains 100.0 BLEU. The variant without the decoder self-attention residual obtains 99.8. The variant without the residual around attention to the encoder obtains 0.0. These figures describe the paper’s held-out counting comparison, in which a single input number specifies an output sequence that must change from one prediction to the next.
BLEU on the single-number counting task
Removing the residual around attention to the encoder destroys counting performance, while removing the self-attention residual has little effect.
The numbers
| System or setting | BLEU |
|---|---|
| Vanilla Transformer (this paper) | 100.0 |
| Without decoder–encoder residual | 0.0 |
| Without decoder self-attention residual | 99.8 |
The illustrative output makes the failure concrete. Given 42, the correct continuation is 43 44 45 46 47. The intact Transformer and the variant without the decoder self-attention residual both produce that continuation. The variant without the residual around attention to the encoder produces 27 27 27 27 27. Its generated sequence has repeated outputs, the behavior the proof associates with feeding the same encoder value through the rest of the decoder at every step. The example also gives a closer account of the failure than the aggregate score alone. The variant produces a sequence of the requested form in the sense of returning several numbers, while the content lacks the successive updates required by the task.
The reported copying and counting scores should be read with their input structures in mind. A sentence supplies several encoder positions, potentially with different associated values. This gives the decoder ways to alter its output by changing which source positions it reads. The counting task supplies one encoder input. A read from a single available value always retrieves that value. The design thereby makes it possible to observe how the different residual connections serve the decoder when the source offers little variation across output steps.
Translation with and without the residual paths
Translation combines source-dependent decisions with dependence on the sequence already generated. The authors describe it as a setting where the decoder can do much of its work by mapping source material to target words, while some decisions also make use of the computation at previous steps. It tests whether the residual comparisons matter beyond the deliberately simple counting setup.
The German-to-English task uses IWSLT’14. According to the paper, the training, development, and test sets contain roughly 153k, 7k, and 7k sentences, respectively. The data are preprocessed with a fairseq script. The authors obtain hyper-parameters for the vanilla Transformer from fairseq’s guidelines and tune the residual-removal baselines on the validation data. For IWSLT’15 English-to-Vietnamese, they follow Luong and Manning’s preprocessing and report about 133k training sentences. The validation set is tst2012, with 1.5k sentences, and the test set is tst2013, with 1.3k sentences.
On the German-to-English test, the intact Transformer scores 32.9 BLEU. The variant without the residual around attention to the encoder scores 24.1, and the variant without the decoder self-attention residual scores 30.6. The intact architecture has the highest score, and the removal around attention to the encoder has the larger effect of the two targeted changes.
Test BLEU on IWSLT’14 German-to-English translation
The intact Transformer scores highest, and removing the residual around attention to the encoder has the larger effect.
The numbers
| System or setting | BLEU |
|---|---|
| Vanilla Transformer (this paper) | 32.9 |
| Without decoder–encoder residual | 24.1 |
| Without decoder self-attention residual | 30.6 |
The ordering is the same on the IWSLT’15 English-to-Vietnamese test. The intact Transformer scores 28.8 BLEU, the one without the residual around attention to the encoder scores 21.8, and the one without the decoder self-attention residual scores 27.2. The variant with the larger loss still translates to a meaningful degree on both tests. The source contains multiple positions whose values the decoder can use at different times, which leaves some room for output variation even after the direct state path has been removed. The authors interpret the scores partly through the amount of work that can be done by mapping source material to the target.
The translation tests add a distinction that the short synthetic tasks could not supply by themselves. A residual that the proof can dispense with may still help a trained system. Removing the decoder self-attention residual changes the translation scores even though the corresponding path is dispensable in an existence proof. Conversely, the cross-attention residual has a concrete expressiveness role in the proof, yet a network without it can still provide competitive content for portions of a sequence where source information does much of the work. The aggregate BLEU scores capture the resulting translation quality across both kinds of decision.
Copying beyond the training lengths
The positional comparison asks whether a system trained on short sequences transfers its copying behavior to longer sequences. The training set is the same 5-12-word Penn Treebank set used before. The authors prepare 5 validation sets with 1k sentences each. The length ranges are 5-12, 13-15, 15-20, 21-25 and 26-30 words, as reported in the paper. The validation set in the original range supplies a comparison with conditions the systems have already encountered. The other ranges test what happens as the required copy extends farther.
The comparison is between a Transformer with absolute positional encodings and a directional Transformer given order through masking. The directional Transformer continues to copy at greater lengths than the absolute-position system. Its performance too deteriorates on the longest inputs. The paper’s analysis identifies a particular stopping behavior in the absolute-position system. It learns to treat the 13th token as terminal and, on longer evaluated inputs, never emits a sentence longer than 12. Its output can therefore be an accurate prefix of a longer sentence with the remainder missing.
The authors illustrate this behavior with an input of length 16. The directional Transformer reproduces the complete sentence. The absolute-position Transformer ends at length 12, after giving the beginning of the sentence correctly. This example clarifies what changed under length extrapolation. Continuing to read the source was part of the copying task, yet the learned stopping behavior instead followed a position that had been associated with the end of the training sequences. The example connects an error visible in an individual output with the trend across length groups.
The length comparison evaluates a specific difference in how the two trained architectures receive order information. The mask changes which source entries are visible as the decoder proceeds, and the input contains a terminal marker. Those features provide a route to a stopping rule that can follow the input. The directional proof gives a constructive example of such a route. The experimental evidence establishes the longer copying behavior and the stopping pattern of the absolute-position system. It leaves open the exact operations the learned directional system used to achieve its result.
What the ablations show
Why the cross-attention residual matters
The removal at the center of the paper acts at the boundary between the decoder’s current computation and the source information that conditions it. In the intact architecture, pₜ can hold a record of the earlier computation. Attention uses pₜ to choose among encoder values, and the residual adds pₜ itself to the selected value. This makes it possible for the feedforward network to use both the earlier state and the input symbol in the same update, as it does in the proofs.
With the residual removed, the earlier decoder computation still affects the query. It can affect which scores are highest, and thus which values are selected. The authors’ argument depends on how much information can cross the block by that route. Hardmax assigns equal weights to whichever keys attain the largest score. For a fixed input, the attended output is therefore one of the averages determined by nonempty subsets of the available values.
aₜ = ∑ᵢ₌₁ⁿ αᵢvᵢᵉ
Here aₜ is the vector delivered after cross-attention without its residual, n is the number of encoder values, and vᵢᵉ is the fixed encoder value at position i. Each αᵢ is the hardmax weight at that position for the current query, with equal positive weights for the winners and zeros for the rest. The earlier state can influence this choice through the query. The number of choices bounds how many different vectors aₜ can carry to the rest of the decoder for that source.
|A| ≤ 2ⁿ − 1
Here A is the set of possible cross-attention outputs for the fixed input, |A| is the size of that set, and n is the number of encoder entries. The expression counts the nonempty subsets of entries. Distinct subsets can yield the same average, so it is an upper bound. In the multilayer analysis, the last cross-attention block imposes the same kind of restriction if its residual has been removed along with the corresponding residuals below it. The ensuing feedforward calculation acts on the vector selected at that final block.
The authors illustrate the consequence with a task that asks for successive multiples of a supplied positive number Δ. Starting at zero, the output should continue as long as the multiples stay within the upper bound. With one encoder entry, every cross-attention call returns the same value. Adding a fixed number of auxiliary input entries, such as markers, increases the number of possible averages but keeps a finite bound determined by the resulting input length. By choosing a sufficiently small Δ, the task demands more distinct values than those averages can convey.
0, Δ, 2Δ, …, kΔ with kΔ ≤ 1
Here Δ is the input increment between 0 and 1, the listed terms are the required numerical outputs, and k is the largest integer for which kΔ remains within the bound. For a source with n entries including auxiliaries, the paper uses the condition Δ < 1/2ⁿ to exhibit the restriction. The discrete menu of choices serves the theoretical argument. The synthetic counting data use a different numerical task with the same central feature, since the next output must change while the encoder receives a single number.
This explains why the difference between counting and copying is informative. A decoder that can retrieve a different source word at a different step has a way to produce distinct copied words even with its residual path removed. The count continuation has no corresponding collection of source words to retrieve. The repeated-number example shows the loss associated with that setup. The translation results fall between these regimes in the authors’ interpretation, since translation can exploit the source and can also benefit from tracking the target computation.
Where information can take another path
The authors use the positive construction to identify places where removing a component can be compensated for. At several points the construction simply needs to preserve the vector entering a block. One way to do that is to let the attention values all be zero and rely on the residual addition. Another is to remove the residual and use position-sensitive attention to select the vector at the position being processed. For these blocks, the proof needs an identity operation and can realize it through either available mechanism. The analogous point for the encoder feedforward block is that either the block or its residual path can supply the required passthrough.
Attention from the decoder to the encoder has a distinct role. It is how the decoder obtains the source in the architecture the paper defines. The decoder feedforward network has a further role in the constructions, carrying out the state update once the previous state and the selected input have reached the same vector. These functions explain why an existence proof can make some attention blocks trivial while actively using others. The importance of a block follows from the information it must deliver and the other paths available to deliver it.
The decoder self-attention residual provides an empirical comparison for this analysis. Removing it leaves the counting score close to the intact architecture’s and leaves the copying score close as well. The corresponding translation scores are lower than the intact scores. This is consistent with a system retaining the capacity needed for the simple state update while losing a path that can help on a more demanding learning problem. The authors also discuss earlier work by Voita and colleagues, who found that decoder self-attention heads in lower layers mattered in translation and suggested a role in target-side prediction. Heads and residual paths are different interventions, but both observations support the paper’s distinction between being dispensable for a particular construction and being helpful in training.
The length comparison controls a different part of the architecture. It changes how the system can use sequence order and evaluates both choices against the same restricted training lengths. The stopping behavior gives a concrete interpretation of the absolute-position system’s failure, while the directional system’s longer outputs show that some of its copying behavior transfers. This analysis supports the paper’s claim that the representation of order can affect generalization even when both variants have universal computational power in the formal setting.
Limitations
Limits the authors state
The theoretical results use arbitrary precision. This matters both because the simulated RNN can encode an evolving tape in rational quantities and because the Transformer’s own bookkeeping can depend on values that require increasing precision. The directional construction keeps an exponentially decreasing terminal score strictly positive. The explicit-position construction needs usable representations of later positions. The authors note that practical implementations use fixed precision, and they leave a general characterization of finite-precision Transformers for future work. They use the RNN connection to suggest access to a large class of regular languages under finite precision, while identifying positional precision as a constraint on a claim about all regular languages.
The proofs also use hard attention. Its rational, exactly specified outputs make the construction and the residual bound possible. The paper contrasts this with softmax, which commonly appears in implementations and in general need not give rational outputs. The authors discuss earlier observations relating the practical behavior of soft attention to hard attention. The theorems themselves are stated for the formal attention operations they define. The counting behavior is an empirical point of contact with a practical architecture. It cannot by itself extend the theorem to arbitrary variants of soft attention.
The full encoder–decoder setting matters. The decoder can continue after the input ends, which the proof uses to complete computations whose running time depends on the input. The authors explicitly distinguish the result from results for encoder-only sequence architectures. Their appendix also explains that the presentation of simulation concentrates on preserving the RNN’s state and its halting behavior. The account of the earlier RNN result discusses producing a machine’s output explicitly, while the Transformer construction formulates its own obligation through the state that encodes the computation. This is the level at which the paper presents the simulation.
Finally, the authors treat the length experiment as evidence about the comparison they ran. They discuss relative positional encodings as a different design intended to deal with position-related problems, and cite earlier translation work that combined masking and encodings. The directional variant itself deteriorates at greater lengths in the copying experiment. The paper’s claim of equal expressiveness applies to the formal architectures, and the observation about extrapolation applies to the trained settings evaluated here.
Limits visible in the proof and experiments
The equality of computational power is an existence result. For each recurrent computation under consideration, the proof arranges parameters, coordinates and attention behavior to implement it. It establishes a feasible way to perform the update under its assumptions. The proof gives no estimate of how easily training examples would select those parameters, how quickly the simulation would run in practice, or how stable it would remain when the underlying arithmetic changes. The compactness of the constructed layers describes the shape of the network used in the proof. Computation can still require a long sequence of decoder steps.
The positional-mask construction depends on a specific information pattern. The decoder sees a growing source prefix, and its first layer can compare that prefix with the one summarized on the preceding step. A claim about recovering order from masking should be read with that pattern in mind. The controlled exposure of the next position supplies the change the proof measures. The distinct start marker supports the strict frequency increase for ordinary symbols, and the terminal marker has specialized handling after the end. These are parts of the construction’s argument, so a variant that changes the masking schedule or boundary conventions would need its own justification.
The negative result likewise depends on the location of the removed connection and the form of attention. Its bound counts distinguishable averages of fixed encoder values at the block from which the residual has been removed. That is the relevant bottleneck when the query can choose only a subset of tied winners. The counting example is especially diagnostic because one value is available throughout. Copying and translation can present the decoder with many values, so there is more variation available through selection. The theorem explains a restriction on a route for information. Predicting its effect on a task also requires knowing what the task demands from that route.
The synthetic tasks make that demand easier to inspect at the cost of covering a narrow range of behavior. The counting test uses a short continuation from a bounded set of input numbers. It gives no measurement of counting across substantially longer outputs. The copy test within the training length range measures reproduction of held-out Penn Treebank sentences, and the extended test moves along the particular axis of length. Success there does not measure recognition of a different grammar or performance on a separate language task. The longer outputs also leave open which learned procedure produced them. A hand-specified frequency calculation in a proof and a trained system’s behavior on held-out sentences are different kinds of evidence about how order can be used.
The translation experiments cover two data settings and report aggregate BLEU scores for architectural variants. They show the direction and size of the score changes on those tests. They do not locate which output decisions caused the difference, such as a decision primarily about what source word to translate or one that drew on an earlier target computation. The authors’ interpretation that source mapping accounts for part of the remaining performance follows the distinction that motivated the experiments. The aggregate scores leave the relative contributions of different translation decisions unresolved.
What came after
Subsequent citing work took up different parts of the problem. The closest continuation in subject is On the Ability and Limitations of Transformers to Recognize Formal Languages. It makes formal-language recognition the object of study, including where that ability reaches its limits. That focus connects to the computational-power paper’s distinction between a general simulation theorem and questions about the sequence patterns a Transformer can actually recognize. A language-recognition question fixes the strings the system must accept, giving a more specific target than a proof that starts with any recurrent computation.
Self-Attention Networks Can Process Bounded Hierarchical Languages narrows the formal-language question to bounded hierarchy. Hierarchy concerns how pieces of a sequence can be nested or grouped, while a bound limits how far that nesting can extend in the language under discussion. This changes the focus from the existence of a general simulator to the handling of a structured family of inputs. Such a focus makes it possible to ask about the resources needed for a particular form of sequence structure, a question left open by a general universality result.
Two other citing works approach capability through what must be represented or learned. Representing Numbers in NLP surveys numerical representation in natural language processing and sets out a vision for that area. This connects to the computational-power paper’s use of numerical quantities in two roles. Its proofs use rational numbers to hold state and control attention, while its counting experiment asks the decoder to produce numerical content. The survey’s stated subject concerns numerical representation in language systems more broadly.
What Can Transformers Learn In-Context? examines in-context learning through simple function classes. Its question concerns what a Transformer can learn from information in its current context. The contrast in experimental questions is informative here. Bhattamishra and colleagues start their proof with a known state update and build a Transformer to reproduce it. The later case study puts the emphasis on learning a function in context, making the class of functions part of the problem being studied.
The role of memory returns directly in Memory Augmented Large Language Models are Computationally Universal. That work places memory augmentation at the center of a universality claim. The earlier paper gets recurrent behavior from information that survives one decoding step and becomes available at the next, under its arithmetic and architecture assumptions. Memory augmentation changes the resources under discussion and returns to the question of when a sequence system can support general computation.
Beyond Memorization studies reasoning depth in connection with recurrence, memory and scaling the computation available at test time. Those are concrete ways to frame a question that the earlier simulation exposes. Reading an input can be only the beginning of a computation. Continuing to work requires both further steps and a way for information to survive between them. The later work’s focus on depth gives that question a more specific target than computational universality alone.
Cite
Cite as Satwik Bhattamishra, Arkil Patel and Navin Goyal. 2020. On the Computational Power of Transformers and Its Implications in Sequence Modeling. Proceedings of the 24th Conference on Computational Natural Language Learning.
@inproceedings{bhattamishra2020computational,
title = {{On the Computational Power of Transformers and Its Implications in Sequence Modeling}},
author = {Satwik Bhattamishra, Arkil Patel and Navin Goyal},
booktitle = {Proceedings of the 24th Conference on Computational Natural Language Learning},
year = {2020},
doi = {10.18653/v1/2020.conll-1.37},
url = {https://doi.org/10.18653/v1/2020.conll-1.37}
}This page in Markdown https://md.research.elamur.ai/free/en/papers/bhattamishra-2020-computational-power-transformers-its-implications/