Your Transformer May Not be as Powerful as You Expect
Abstract
Relative Positional Encoding (RPE), which encodes the relative distance between any pair of tokens, is one of the most successful modifications to the original
Transformer.
As far as we know, theoretical understanding of the RPE-based
Transformers is largely unexplored.
In this work, we mathematically analyze the power of RPE-based Transformers regarding whether the model is capable of approximating any continuous sequence-to-sequence functions.
One may naturally assume the answer is in the affirmative—RPE-based Transformers are universal function approximators.
However, we present a negative result by showing there exist continuous sequence-to-sequence functions that RPE-based Transformers cannot approximate no matter how deep and wide the neural network is.
One key reason lies in that most RPEs are placed in the softmax attention that always generates a right stochastic matrix.
This restricts the network from capturing positional information in the RPEs and limits its capacity.
To overcome the problem and make the model more powerful, we first present sufficient conditions for RPE-based Transformers to achieve universal function approximation.
With the theoretical guidance, we develop a novel attention module, called Universal
RPE-based (URPE) Attention, which satisfies the conditions.
Therefore, the corresponding URPE-based Transformers become universal function approximators.
Extensive experiments covering typical architectures and tasks demonstrate that our model is parameter-efficient and can achieve superior performance to strong baselines in a wide range of applications.
The code will be made publicly available at https://github.com/lsj
/URPE .
Introduction
Transformer [61] is well acknowledged as a powerful neural network in modeling sequential data [12, 42].
Relative Positional Encoding (RPE) is one of the most successful modifications to the Transformer model [49].
Unlike the originally designed Absolute Positional Encoding (APE) that encodes each position as an embedding vector, RPE encodes the relative distance between any pair of tokens and is usually placed in the softmax exponentiation in the self-attention module.
Empirically, many studies show that RPE-based Transformers can achieve impressive performance on various language tasks [54, 10] and have better extrapolation ability on longer sequences [52].
Another point worth noting is that RPE makes Transformer easily be extended to other data modalities, such as image [14, 43] and graph [67], as the relative distance naturally preserves invariant properties for several important transformations like rotation and translation.
In this paper, we first investigate the theoretical aspect of the RPE-based Transformers.
In particular, we study their expressive power which describes models’ ability to approximate any continuous functions.
Recently, Yun et al.
[69] proved that the APE-based Transformers are universal approximators of continuous sequence-to-sequence functions on a compact domain, and one may expect that
the
RPE-based Transformers enjoy the same property.
However, we provide a surprising theoretical finding which shows that widely-used Transformers with RPE are not universal function approximators, i.e., there exist continuous sequence-to-sequence functions that the models cannot approximate no matter how deep and wide the model is.
One key observation is that the RPEs are placed inside the softmax in the attention module.
The softmax operator always generates a right stochastic matrix, which fails to reflect enough positional information encoded in RPE to the output.
Synthetic tasks are conducted to support this mathematical claim.
To design a more powerful RPE-based Transformer, we delve into the limitation of the model and theoretically derive two sufficient conditions to achieve universal function approximation: the attentive condition and position-aware condition .
Both conditions together state that the RPE-based attention function class should cover some special cases of the originally designed attention and break the right-stochastic-matrix limitation.
With such theoretical guidance, we develop a new attention module called Universal RPE-based (URPE) Attention that satisfies the above conditions.
Therefore, the Transformers with URPE-based Attention, called URPE-based Transformers , are universal function approximators.
We show our proposed architecture is easy to implement and parameter-efficient via extensive experiments covering typical model architectures [54, 10, 67] and tasks (synthetic tasks, language modeling, and graph learning).
Our model brings consistent performance gains compared with existing RPE-based Transformers on a wide range of tasks.
The paper is organized as follows.
In Section 2, we introduce background on the Transformer architecture and positional encoding approaches.
In Section 3, we prove that the widely-used RPE-based
Transformers are not universal function approximators.
In Section 4, we further present sufficient conditions for RPE-based Transformers to achieve universal approximation, and develop a new attention module, URPE-based Attention, to build a universal RPE-based Transformer.
Experiments are presented in Section 5 to demonstrate the effectiveness of Transformers with our proposed
URPE-based Attention.
Related works and the conclusion are discussed in the last two sections.
Preliminary
The Transformer architecture is composed of stacked Transformer blocks [61, 12].
A Transformer block is a sequence-to-sequence mapping from R n × d to R n × d , where n is the sequence length and d is the dimension of token embedding.
A Transformer block consists of two layers: a self-attention layer followed by a feed-forward layer, with both layers having normalization (e.g., LayerNorm [1],
RMSNorm [71]) and skip connections.
For an input X ∈ R n × d , the self-attention layer and feed-forward layer are defined as follows:
[Equation]
where W hO ∈ R d H × d , W hQ , W hK , W hV ∈ R d × d H , W 1 ∈ R d × r , W 2 ∈ R r × d .
H is the number of attention heads, d H is the dimension of each head, and r is the dimension of the hidden layer.
A h ( X ) is usually referred to as the attention matrix .
Given pre-defined H , d H and r , we refer to the function class of the Transformer blocks as T _ blocks( H, d H , r ) .
Transformer with Absolute Positional Encoding.
Self-attention layers and feed-forward layers defined in Eq.(2) and (3) are entirely invariant to sequence order.
Therefore, purely stacked Transformer blocks cannot distinguish information at different positions.
The original Transformer [61] proposes Absolute Positional Encoding (APE) to endow Transformer networks with the ability to capture positional information.
In particular, a (learnable) real-valued embedding e i ∈
R
d is assigned to each position i , leading to an Absolute Positional Encoding matrix E =
[ e 1 , · · · , e n ] ⊤ , which will be added to the input sequence.
Formally speaking, the function class represented by APE-based
Transformers is
[Equation]
APE essentially enhances the expressive power of Transformers.
Yun et al.
[69] proved the following theoretical result, which shows that APE-based Transformers can approximate any continuous sequence-to-sequence function in a compact domain.
Theorem 1 (informal [69]) .
Given n, d ∈ N ∗ , the function class of Transformers with APE, Ω 2 , 1 , 4 APE , is a universal approximator for continuous functions that map a compact domain in R n × d to R n × d .
Though Transformers with APE are conceptionally simple and enjoy good theoretical properties, they have a few known shortcomings.
For example, Press et al.
[52] showed that APE-based Transformers usually generalize poorly to longer sequences, as those positional embeddings for large indexes are hardly trained.
Many works [58, 10, 54, 33, 26] employ Relative Positional Encoding (RPE), which becomes increasingly popular as a powerful way to encode positional information for Transformers and largely overcomes the disadvantages of APE.
Transformer with Relative Positional Encoding.
Different from APE that assigns an embedding e i for each position i , Relative Positional Encoding (RPE) encodes relative distance i − j for each position pair ( i, j ) .
With the relative positional encoding, most previous works modified the attention computation defined in Eq.(1) as follows:
[Equation]
where B is an n × n matrix.
The ( i, j ) -th entry of B , denoted by b ij , models the interaction between the i -th and j -th position.
Different parameterizations of B lead to different model architectures.
A few well-known examples include:
• Shaw’s RPE [58]: b ij =
X i W hQ r ⊤ i − j , where r i − j are learnable vectors.
• T5 [54]: b ij = m i − j , where m i − j are learnable scalars,
i
e., B is parameterized as a Toeplitz matrix [22, 45].
• DeBERTa
[25]: b ij =
X i W hQ r ⊤ i − j
+ s i − j
( X j W hK ) ⊤ , where r i − j
and s i − j are learnable vectors.
• Transformer-XL
[10]: b ij =
X i W hQ ( r i − j ˜ W hK ) ⊤ + u ( X j W hK )
⊤ + v ( r i − j ˜ W hK ) ⊤ , where u , v and ˜ W hK are all learnable vectors/matrix, and r i − j are sinusoidal positional encoding vectors fixed during training.
Several interesting phenomena suggest that RPE-based Transformers have many advantages compared to their APE-based counterparts.
Press et al.
[52] demonstrated that RPE-based Transformers generalize better on longer sequences.
T5 [54] and Transformer-XL [10] show that Transformers with RPE can achieve strong performance in language understanding and language generation tasks.
Recently, RPEs are also popularly used in other domains to encode translation/rotation-invariant structural signals.
Typical examples include Swin Transformer [43] and Graphormer [67], both of which use RPE and achieve state-of-the-art performance in image and graph representation learning.
Transformers with RPE are not Universal Approximators
We are interested in the expressive power of Transformers with RPE and investigate whether this architecture is as powerful as the original APE-based Transformers.
To make comparison, we similarly define the function class of the Transformer blocks with RPE-based attention (Eq.(4)) as
T _ blocks RPE ( H, d H , r ) , in which the relative positional encoding matrix B is assumed to be an arbitrary parameterized mapping from the input X to an n × n matrix.
The function class represented by Transformers with RPE is defined as:
[Equation]
Surprisingly, we present a negative theoretical result: we prove that the function class of Transformers with RPE, Ω H,d H ,r RPE , is not a universal approximator for sequence-to-sequence functions.
Theorem 2.
Given n > 2 , d and D ⊆ R n × d , assume that the all-zero matrix 0 ∈ D .
For any M > 0 , there exists a continuous function ˜
g M : D → R n × d , such that
[Equation]
holds for any g ∈ Ω H,d H ,r RPE , where H, d H , r ∈ N ∗ .
Proof.
Without loss of generality, we prove the theorem for d = 1 .
The proof can be easily extended to d > 1 settings.
Given M > 0 , we consider a specific sequence-to-sequence function as target: ˜ g M : X (cid:55)→ (2 M, 0 , · · · , 0) ⊤ .
To show sup X ∈D ∥
˜ g M ( X ) − g ( X ) ∥
F > M holds for any g ∈ Ω H,d H ,r RPE , we pick up an input X ∗ , which is composed of n identical row vectors in R d , i.e., the sequence consists of n identical tokens.
Since the function A h RPE ( X ) outputs a right stochastic matrix, it is easy to check that Attn( X ) =
X
+ (cid:80)
Hh =1 A h ( X ) XW hV W hO is also composed of n identical row vectors in R d .
Note that FFN( X ) and normalizations operate identically on each row vector, we can obtain that the final output of a Transformer block with RPE-based attention is still composed of n identical row vectors in R d .
Since g is a composition of multiple Transformer blocks in T _ blocks RPE ( H, d H , r ) and 0 is composed of n identical row vectors in R d , we conclude from the analysis above that g ( 0 ) is also composed of n identical row vectors in R d , i.e., there exists c ∈ R d such that g ( 0 )
=
c 1 ⊤ n .
Therefore, by applying Cauchy-Schwartz Inequality we obtain
[Equation]
M
[Equation]
which completes the proof.
Discussions.
The key observation in Theorem 2 is that A RPE ( X ) always outputs a right stochastic matrix.
Even if RPE carries rich positional information, such signal will be suppressed to satisfy
A RPE ( X ) 1 = 1 for arbitrary X ∈ R n × d , where 1 is an all-one n-dimensional vector.
As a result, the attention module fails to reflect enough positional information encoded in RPE to the output, which restricts the model capacity.
The problem will be significant when the target function ˜
g is very position-sensitive (in the extreme case, ˜ g only depends on the position indexes).
We also conduct experiments on simple sequence-to-sequence tasks using synthetic data to support this mathematical claim in Section 5.1.
One may expect that simply removing the denominator in the softmax can break the limitation.
However, this modification brings significant optimization instability in practice.
Given that RPE has many advantages 3 compared to APE, it’s appealing to design an RPE-based
Transformer variant that is a universal approximator of sequence-to-sequence functions and easy to optimize.
This is what we precisely work on in the next section.
Making RPE-based Transformers Universal Approximators
This section contains two sub-sections.
In the first sub-section, we provide a sufficient condition for the RPE-based Transformers to achieve universal approximation.
In the second sub-section, we offer a practical instantiation of the Transformer with RPE that satisfies the requirement and is parameter-efficient.
example, RPE empirically performs well in generalization to longer sequences, while the theoretical analysis of approximation capability focuses on functions with bounded input lengths (See Theorem 1 where n is given).
Our goal is to design an RPE variant with the same expressiveness as APE in the theoretical setting and enjoys its usefulness in practical scenarios.
4.1 A Sufficient Condition to Achieve Universal Approximation
Motivated by formulation (1) and (4), we consider a general form A hU : R n × d → R n × n and define the corresponding attention layer as
[Equation]
We further define the function class of the corresponding Transformer block as T _ blocks U ( H, d H , r ) , and define the function class of Transformers composed of stacked T _ blocks U ( H, d H , r ) as:
[Equation]
H,
[Equation]
H ,r U
[Equation]
Our goal is to investigate the requirements on A h U under which the induced function class Ω H,r U can become universal approximators of continuous sequence-to-sequence functions.
We provide one sufficient condition in the following theorem.
Following Yun et al.
[69] and many other previous theoretical works [44, 24, 70], we study the expressiveness of a simplified version of Transformer in which normalization layers are omitted, as it is widely believed that normalization mainly helps optimization but does not hurt the expressive power of the network [32, 1].
Theorem 3.
Given n, d ∈ N ∗ , p ∈ [1 , + ∞ ) , ε > 0 , a compact set D ⊆ R n × d , and a continuous sequence-to-sequence function f : D → R n × d .
Assume that A hU satisfies the following conditions:
• Attentive condition.
For any u ∈ R d × 1 and c ∈ R , there exists a parametrization of A hU , such that A hU ( X ) = softmax (cid:0)
Xu
( Xu − c 1 ) ⊤ (cid:1) .
• Position-aware condition.
There exists a parametrization of A hU and a vector v ∈ R n whose entries are all distinct, such that A hU ( X ) 1 = v for any X ∈ R n × d .
Then there exists a Transformer network g ∈ Ω 2 , 1 , 4 U such that (cid:0)(cid:82) D ∥
f
( X
[Equation]
− g
[Equation]
X
[Equation] [Equation]
<
[Equation]
, where ∥ · ∥ p denotes the entry-wise ℓ p norm for matrices.
The detailed proof of Theorem 3 can be found in Appendix A. Theorem 3 presents two conditions to make RPE-based Transformers become universal approximators.
Intuitively, the attentive condition states that A h U should contain a special case of the original attention matrix in Eq.(1), where W Q =
W K ∈ R d H × d and d H = 1 .
The position-aware condition states that A hU needs to break the limitation of A ( X ) being a right stochastic matrix (i.e., A ( X ) 1 = 1 for all X ∈ R n × d ).
We will present a concrete example satisfying these conditions in the next subsection.
4.2 A Universal RPE-based Transformer
We develop a new Transformer variant which satisfies the conditions above.
In particular, we multiply the softmax attention matrix with another matrix, and obtain
[Equation]
where ⊙ denotes entry-wise product.
B can take any form described in Section 2.
We refer to this attention variant as Universal RPE-based Attention (URPE-based attention).
To make URPE-based attention rely relative positional information, we set C ∈ R n × n to be a learnable Toeplitz matrix in which each element on the descending diagonal from left to right has the same value.
Note that a Toeplitz matrix of shape n × n has 2 n − 1 degrees of freedom.
Therefore, we only need 2 n − 1 new parameters for each C .
It can be proved that URPE-based Attention satisfies the two conditions in Theorem 3 and the proof can be found in Appendix B.
Proposition 4.
URPE-based Attention defined in Eq.(8) satisfies the conditions in Theorem 3.
Consequently, given n, d ∈ N ∗ , Transformers using this form of attention are universal approximators of continuous sequence-to-sequence functions that map a compact domain in R n × d to R n × d .
To further improve parameter efficiency, we set C to be shared across different layers but to be unique for each attention head.
As an example, in Transformer-XL (see Section 5.2), we introduce only about
[Figure] [Figure]
4K new parameters, which is negligible compared to the 151M parameters of the Transformer-XL model but still leads to non-trivial improvements.
We make two more discussions for our designed URPE-based attention.
The first one is about applying URPE-based attention in the causal setting.
Causal attention is important in language generation tasks.
URPE-based Attention is compatible with it as one can set the ( i, j ) -th entry of C to be 0 for i > j .
The second one is on the initialization of C .
In practice, the matrix C can be initialized as an all-one matrix.
Therefore, the model behaves identically to the original RPE-based model at initialization, and the additional parameters in C are learned gradually.
We can also fine-tune any well-trained RPE-based Transformer to its URPE-based counterpart by setting C as an all-one matrix and further fine-tuning the model to learn C .
Experiments
In this section, we empirically study the effectiveness of the proposed model.
In particular, we aim at answering the following questions through experiments:
• Question 1 :
Can the theoretical results on the approximation capability of RPE-based Transformer and URPE-based Transformer be reflected in certain experiments?
• Question 2 : With different RPE methods (the matrix B in Eq.(8)), can URPE-based Transformer outperform its RPE-based counterpart in real-world applications?
• Question 3 : Can URPE-based Attention serve as a versatile module to improve the general Transformers beyond language tasks?
We will answer each question with carefully designed experiments in the following sub-sections.
Due to space limitation, we only present results on representative model architectures, task types, and data modalities in the main body of the paper.
More results are presented in the appendix.
All codes are implemented based on the official codebases of Fairseq [50] and Graphormer [67] in PyTorch [51].
5.1 Synthetic Tasks
To empirically verify our theoretical results on the approximation capability of RPE-based Transformer and URPE-based Transformer, we design two synthetic tasks: 1) Position Identification; 2)
Even Token Prediction.
[Table]
Both Position Identification (PI) task and Even Token Prediction (ETP) task are sequence-to-sequence prediction tasks.
Given a sequence of tokens s = ( w 1 , w 2 , · · · , w n ) , the PI task is to predict the position index of each token in the sequence, i
[Table]
e., the target sequence-to-sequence function f to approximate can be defined as
[Equation]
The ETP task is defined as follows: for the first half of positions in a sequence, the task requires the model to output the input tokens at positions with even number index; for the remaining half of positions, the task requires the model to output the special token End-Of-Sentence (EOS),
i
[Table]
e., f ETP ( w 1 , w 2 , · · ·
[Equation]
) = (
[Equation] [Equation]
n
[Equation]
EOS
[Equation]
EOS) (10)
Both tasks require the model to accurately encode the positional information, which would be difficult for RPE-based Transformers to capture.
For both tasks, we use synthetic datasets with randomly generated sequences.
In detail, we vary the token vocabulary size from [10, 1000, 10000] and set the sequence length to 128.
We choose the vanilla Transformer as the base model and compare the following ways to encode positional information: 1) no positional encodings (noPE); 2) T5-style relative positional encoding (RPE) [54]; 3) URPE with T5-style RPE backbone Transformer.
The number of layers and the number of attention heads are set to 3 and 12, respectively.
The hidden dimension is set to 768.
Results.
We use token-level accuracy as the evaluation metric.
The experimental results are shown in Figure 1.
From the figure, it can be easily seen that the Transformer without PE and the
Transformer with T5-style RPE cannot perfectly solve the synthetic tasks (less than 60% accuracy).
On the contrary, the URPE-based Transformer achieves 100% accuracy on both tasks.
Firstly, this result clearly indicates that our proposed model outperforms the backbone T5-style RPE-based
Transformer by a large margin.
Furthermore, we can see that even for such simple tasks, the
Transformer with T5-style RPE sometimes fails, while the URPE-based Transformer succeeds and approximates the target function well, which is consistent with our theoretical findings.
Lastly, we provide visualizations of the learned Universal RPE (Eq.(8)) on both tasks in Figure 2, which show that the matrix B and C capture different aspects of positional information.
5.2 Language Modeling
We use language modeling to study the effectiveness of the proposed URPE-based Attention.
Language modeling is an important practical application which usually requires the modelling of longterm dependency between tokens.
We conduct experiments on the WikiText-103 dataset [47], which contains 103M training tokens from 28K articles, with an average length of 3.6K tokens per article.
Relative positional encoding methods are popularly used in language modelling.
We choose
Transformer-XL model [10] as the backbone model of our URPE-based Transformer.
Following [10], the number of layers and the number of attention heads are set to 16 and 10 respectively.
The dimension of hidden layers and feed-forward layers are set to 410 and 2100.
The detailed descriptions of the baselines and training settings are presented in the appendix.
[Table] [Table]
Results.
We show the perplexity scores on both validation and test set of different models in Table 1.
It can be easily seen that the Transformer-XL equipped with our URPE-based attention achieves 22.4 and 23.2 valid and test perplexity scores, respectively, which are 0.7 and 0.8 lower than the backbone Transformer-XL model and also significantly better than other baselines.
First, the results suggest that our proposed URPE-based attention can be well applied to Transformer-XL in real-world applications.
Together with the observations in Section 5.1, we believe our URPE can be used in other RPE-based architectures, such as [58, 26].
It is worth noting that our model has negligible more parameters (about 4k) compared to the backbone Transformer-XL.
Thus, the improvement in the perplexity should be mostly attributed to the stronger expressiveness of the model.
5.3 Graph Learning
We further examine whether the proposed URPE-based Attention can serve as a versatile module to improve the general RPE-based Transformers beyond language tasks.
The Transformer-based models have become increasingly popular in the graph learning area [67, 37, 15].
Among those models, the recently proposed Graphormer [67] achieves state-of-the-art performance in many graph learning tasks [68, 59].
In Graph Transformers, RPE is used rather than APE since RPE only calculates distances between nodes, which naturally preserves many invariant and equivariant properties.
The attention computation in Graphormer also follows the Eq.(4) in Section 2.
Specifically,
Graphormer calculates the shortest-path distance between any pair of nodes and encodes this information as a bias term in the softmax attention to reflect the relative position of any node in the
[Table] [Table]
graph.
We refer the readers to [67] for the detailed description of Graphormer.
Similar to previous experiments, we adapt the URPE-based Attention to the Graphormer and compare them on two benchmark datasets covering graph representation learning tasks from small to large scale datasets:
ZINC from Benchmarking-GNNs [16] and PCQM4M from Open Graph Benchmark Large Scale
Challenge (OGB-LSC) [29].
For both tasks, we choose several competitive Transformer based models and GNNs as our baselines.
Details of the experimental settings are presented in the appendix.
ZINC.
ZINC is a real-world dataset which consists of 250K molecular graphs.
The task is to predict the constrained solubility of a molecule which is an important chemical property for drug discovery.
We train our models on both the ZINC-Full and ZINC-Subset (12K selected graphs following [16]).
To demonstrate the power of our method and for fair comparison, we set the parameter budget of the model to be less than 500K following [16, 67].
We build on the Graphormer [67] model which consists of 12 layers.
The dimension of hidden layers and feed-forward layers are set to 80.
The number of attention heads are set to 32.
PCQM4M. PCQM4M is a quantum chemistry regression task in OGB-LSC [29].
The PCQM4M dataset contains more than 3.8 million molecular graphs in total, which is currently the largest graph-level prediction dataset.
The state-of-the-art architecture for this task is the Graphormer model introduced above.
We still follow [67] to set the hyper-parameters in the Graphromer model and equip it with URPE.
In detail, our Graphormer with URPE-based Attention consists of 6 layers and 32 attention heads.
The dimension of hidden layers and feed-forward layers are set to 512.
Results.
The experimental results on ZINC and PCQM4M are shown in Table 2 and 3, where the score is averaged over four experiments with different seeds.
It can be easily seen that the
Graphormer model equipped with our URPE-based Attention consistently outperforms the backbone
Graphormer model on both ZINC and PCQM4M tasks.
In particular, our URPE-based Attention enables the Graphormer model to reduce more than 40% relative mean absolute error on the test set of
ZINC-Subset and ZINC-Full.
On the PCQM4M task, the improvement is around 0.003 mean absolute error which is also a significant improvement under the quantum chemistry precision.
It is worth noting that our Graphormer model with URPE-based Attention achieves competitive performance compared to the Graphormer Base model with 48.3M parameters reported in [67].
Therefore, we believe our proposed architecture significantly improves the expressive power of the Transformer backbones and can be well extended to practical scenarios beyond language tasks.
5.4 More Analyses
URPE-based Attention consistently improves the performance of models of different sizes.
We conduct ablation experiments on the Language Modeling task and vary the number of layers in [4, 8, 16] to investigate different model sizes.
Following the experiment settings in Section 5.2, the number of attention heads is set to 10.
The hidden dimension is set to 41.
The dimension of the feed-forward layer is set to 2100.
The results are presented in Table 4.
It can be easily seen that our URPE-based
Attention consistently reduces the perplexity scores of Transformer-XL models of different sizes, which indeed demonstrates the versatility of our URPE-based Attention.
Runtime and Memory Usage Evaluation.
We further conduct memory and time costs profiling experiments on our URPE-based Transformers.
We choose the vanilla Transformer as the backbone model.
The number of layers and the hidden dimension are set to 12 and 768 respectively.
The number of attention heads is set to 12.
The batch size is set to 32.
We vary the sequence length from [128, 256, 512].
We run profiling of all the models on a 16GB NVIDIA Tesla V100 GPU.
Following
Combiner [55], we compare the inference speed and memory costs of the vanilla Transformer with
RPE and our URPE.
The results are presented in Table 5, which show that our URPE only increases minor computational costs.
Summary.
In this section, we design a series of experiments to answer the questions on the effectiveness and applicability of the proposed URPE-based Attention.
All the experimental results suggest that our theoretical findings are convincing, and Transformers with our modification are effective, powerful, and widely applicable across different tasks.
Related Work
Expressive power of Neural Networks.
Quantifying the capacity of neural networks is an important research direction in the literature on deep learning.
[9, 19, 27, 4] showed that a neural network with one hidden layer and unbounded width can approximate arbitrary continuous functions on compact support with arbitrarily small error.
Many works also studied the width efficiency on the expressive power of neural networks [44, 24, 40] and proved that ReLU networks with a bounded width but unlimited depth can achieve universal function approximation.
Recently, there has been increasing interest in the theoretical understanding of Transformer models.
Yun et al.
[69] theoretically showed that Transformers can approximate any continuous sequence-to-sequence functions (i.e., universal approximation) on a compact domain by proving that stacking of self-attention layers can compute contextual mappings of the input embeddings.
Dong et al.
[13] analyzed the limitations of attentiononly Transformers without considering FFN blocks, normalizations, and skip connections.
Hron et al.
[28] analyzed the behavior of multi-head attention and connect it with the Gaussian process when the number of heads tends to be infinity.
In [7], it is proved that a multi-head attention layer with enough heads is at least as expressive as any convolution layer.
All works above consider Transformers with absolute positional encoding, which is the main difference between them and our work.
Positional encoding methods in Transformers.
In [61], the vanilla Transformer encodes the positional information via the absolute positional encoding (APE).
Shaw et al.
[58] is the first to introduce relative positional encoding (RPE) to Transformer.
From then on, many works explored different RPE strategies based on [58].
Transformer-XL [10] re-parameterizes the self-attention to integrate relative positional encoding and enables long sequence modelling.
T5 [54] simplifies the vector representations of relative positions to scalars.
Kitaev et al.
[36] disentangles the positional and content information in the Transformer encoder, which leads to an improved constituency parser.
Ke et al.
[33] further shows that such disentanglement also improves Transformer in general language pre-training and achieves superior performance on various downstream tasks.
There are also works that encodes the positional information via other tools like trees [60], complex numbers [63], dynamic systems [41], Fourier features [39].
Compared to most previous works inspired by practical scenarios, our URPE-based attention is theoretically motivated by investigating the expressive power of RPE-based Transformers in a principled way.
Conclusion
In this paper, we first investigate the theoretical aspect of the RPE-based Transformers.
In particular, we study their expressive power and provide a surprising theoretical finding which shows that widelyused Transformers with RPE are not universal function approximators.
To design a more powerful
RPE-based Transformer
, we present sufficient conditions on the attention module to achieve universal function approximation and develop a novel Universal RPE-based Transformer using a new relative positional encoding approach.
We conduct carefully designed experiments on synthetic sequence data, natural language, and graphs to show that our model brings consistent performance gains compared with existing RPE-based Transformers.
In the future, we will benchmark our Universal RPE on other RPE-based Transformers and typical tasks to further verify its versatility as a basic module for
Transformer-based models.
Acknowledgements
We thank Tianle Cai and Jianlin Su for the helpful discussions.
We also thank all the anonymous reviewers for the very careful and detailed reviews as well as the valuable suggestions.
Their help has further enhanced our work.
This work is supported by National Science Foundation of China (NSFC62276005), The Major Key Project of PCL (PCL2021A12), Exploratory Research Project of
Zhejiang Lab (No. 2022RC0AN02), and Project 2020BD006 supported by PKUBaidu Fund
Checklist
For all authors... (a) Do the main claims made in the abstract and introduction accurately reflect the paper’s contributions and scope?
[Yes] (b) Did you describe the limitations of your work?
[Yes] see Section(c)
Did you discuss any potential negative societal impacts of your work?
[No] (d) Have you read the ethics review guidelines and ensured that your paper conforms to them?
[Yes] 2.
If you are including theoretical results... (a) Did you state the full set of assumptions of all theoretical results?
[Yes] (b) Did you include complete proofs of all theoretical results?
[Yes] 3.
If you ran experiments... (a) Did you include the code, data, and instructions needed to reproduce the main experimental results (either in the supplemental material or as a URL)?
[Yes] (b) Did you specify all the training details (e.g., data splits, hyperparameters, how they were chosen)?
[Yes] (c) Did you report error bars (e.g., with respect to the random seed after running experiments multiple times)?
[Yes] (d) Did you include the total amount of compute and the type of resources used (e.g., type of GPUs, internal cluster, or cloud provider)?
[Yes] 4.
If you are using existing assets (e.g., code, data, models) or curating/releasing new assets... (a) If your work uses existing assets, did you cite the creators?
[Yes] (b) Did you mention the license of the assets?
[Yes] (c) Did you include any new assets either in the supplemental material or as a URL?
[No] (d) Did you discuss whether
and how consent was obtained from people whose data you’re using/curating?
[No] (e) Did you discuss whether the data you are using/curating contains personally identifiable information or offensive content?
[No] 5.
If you used crowdsourcing or conducted research with human subjects... (a) Did you include the full text of instructions given to participants and screenshots, if applicable?
[N/A] (b) Did you describe any potential participant risks, with links to Institutional Review Board (IRB) approvals, if applicable?
[N/A] (c) Did you include the estimated hourly wage paid to participants and the total amount spent on participant compensation?
[N/A]
A Proof of Theorem
In this section, we provide the proof of the Theorem 3.
First, we define a modified version of
Transformer blocks, which will be used in the subsequent proof.
Then we present a few technical lemmas.
Finally, this section is completed with the proof of Theorem 3.
A.1 Modified Transformer blocks
Following [69, 70], we use a modified version of Transformer blocks in our construction first, and show that such modified Transformer blocks can be approximated by the originally defined
T _ blocks U up to arbitrary precision.
Definition 5 (Modified Transformer blocks) .
A modified Transformer block is defined as a composition of modified self-attention layer Attn m and modified feed-forward layer FFN m , where
[Equation]
In Eq.(11), the attention matrix A hU ( X ) = hardmax (cid:0)
Xu
( Xu − c 1 ) ⊤ (cid:1) , where u ∈ R d × 1 and c ∈ R are learnable parameters.
Thus it expresses the hard attention operation .
In Eq.(12), the activation ϕ is a (possibly discontinuous) piece-wise linear function with at most three pieces.
We denote the function class of modified Transformer blocks by T _ blocks m ( H, d H , r ) .
A nice property of the modified Transformer blocks is that compositions of modified Transformer blocks can be approximated by compositions of the originally defined T _ blocks U up to arbitrary precision, which is proved in Lemma 9 of [69].
Another important property of the modified Transformer blocks is that they can implement the following “selective shift” operator:
Lemma 6.
For any real numbers a, b Q and b ′ Q satisfying b Q < b ′ Q and a vector z ∈ R d , there exists g ∈ T _ blocks m (2 , 1 , 1) such that g ( X ) =
X + a Ψ
( X ; b Q , b ′ Q ) , where
[Equation]
Q
[Equation] [Equation]
and X k denotes the k -th row of X .
The proofs of Lemma 6 can be found in [69].
A.2 Input quantization
In this subsection, we show how to quantize any input X ∈ [0 , 1] n × d to a δ -grid point in { 0 , δ, . . . , n − δ } n × d .
In fact, the quantization procedure can be conducted with dδ modified Transformer blocks.
Lemma 7. Consider an entry-wise quantization mapping defined as g entry1 ( t ) =
δ ⌊ tδ ⌋ .
There exists a function g 1 : [0 , 1] d × n → R d × n composed of dδ modified Transformer blocks in T _ blocks m (2 , 1 , 1) , which implements the entry-wise quantization mapping g entry1 over each entry of its input.
Proof.
For each column in the input X ∈ R n × d , we show how to use 1 δ stacked modified feedforward layers to quantize it while keeping all the other columns untouched.
For the r -th row, we useδ layers of the following form, in which the k -th layer is:
[Equation]
) where e ( r ) = (0 , · · · , 0 , 1 , 0 , · · · ) ⊤ is the r -th d -dimensional one-hot vector and ϕ ( t ) = − t 1 0 ≤ t<δ is a piece-wise linear activation function.
Therefore, we can construct dδ modified Transformer blocks, where the modified self-attention layers express the identity mapping, and the (cid:0) r − 1 δ + k (cid:1) -th modified feed-forward layer is defined as Eq.(15), to implements the entry-wise quantization mapping g entry1 .
A.3 Injecting positional information with the position-aware condition
In this subsection, we introduce new techniques to leverage the position-aware condition defined in
Theorem 3 and inject positional information into the Transformer block.
Note that the new techniques we use are non-trivial since we do not rely on any explicit absolute positional encoding in the definition of the position-aware condition.
Lemma 8.
Assume H, d H , r ∈
N
∗ and that A hU satisfies the position-aware condition defined in Theorem 3.
Then there exists u = ( u 1 · · · u n ) ⊤ ∈ R n and a Transformer block g 2 ∈ T _ blocks U (2 , 1 , 4) such that
• | u i − u
j | > 1 for any i ̸ =
j ; • g 1 ( X ) =
X + U , where U = u 1 ⊤ d and 1 d is a d -dimensional all-one vector.
Proof.
By leveraging the position-aware condition, we can construct a self-attention layer such that the attention matrix in each head satisfies A hU ( X ) 1 = v , where v ∈ R n is a row vector with n distinct entries.
We rewrite the generalized self-attention layer (Eq.(6)) with explict bias term as
[Equation]
where W hV ∈ R
d × 1 , W hO ∈ R 1 × d , c hV ∈ R and c
h ⊤ O ∈ R d (note that d H = 1 and H = 2 in this lemma).
To obtain the desired mapping g 2 , we set
[Equation]
Assume that u = ( u 1 · · · u n ) ⊤ =
Hc 1 V v .
Then u is an n -dimensional vector in which | u i − u
j | >for any i ̸
=
j .
Besides, we have
[Equation]
Finally, we set all the learnable parameters in the subsequent feed-forward layer to be 0.
In this case, the feed-forward layer is equivalent to an identity mapping due to the skip connection.
Therefore, g 2 ( X ) =
FFN(Attn U ( X ))
=
X + U .
With the position-aware condition satisfied, the Lemma 8 indeed shows that the positional information can be injected into the (quantized) input X and further be fed into the subsequent Transformer blocks, since U is composed of n distinct rows which help to distinguish each position.
A.4 Contextual mapping with the attentive condition
In this subsection, we follow [69, 70] to show that the modified attention layer with the (hard) attentive condition can implement “contextual mapping” defined in [69] and achieves universal approximation.
The concept of “contextual mapping” is defined as below.
Definition 9 (Contextual mapping [69]) .
Consider a finite set L ⊂ R n × d .
A map q : L → R n defines a contextual mapping over L if and only if the map satisfies the following properties:
• For any L ∈ L , the entries of q ( L ) are all distinct.
For
any L , L ′ ∈ L satisfying L ̸
= L
all entries of q ( L ) and q ( L ′ ) are distinct
With this concept, we present the following lemma:
Lemma 10.
Assume n
and δ − 1 are two positive integers and that n, δ − 1 ≥ 2 .
Suppose that the matrix U =
u 1 ⊤ d , where u is an n -dimensional vector satisfying | u
i − u
j | > 1 for any i ̸
=
j .
Then, there exist a function g 3 : { 0 , δ, 2 δ, · · · , 1 } n × d → R n × d composed of stacked modified attention blocks, and a vector z ∈ R d , such that the mapping q ( X ) =
g 3 ( X + U )
z is a contextual mapping over { 0 , δ, 2 δ, · · · , 1 } n × d .
Proof.
This proof mainly follows and extends the technique in [69].
We sort the entries in u and define u (1) < · · · < u ( n ) to be a permutation of ( u 1 , · · · , u n ) .
Without the loss of generality, we assume that u ( n ) = u n .
Define z
=
(1 , δ − 1 , · · · , δ − d ) ⊤ and s r = u ( r )
[Equation]
By leveraging Lemma 6, we construct nδ − d modified Transformer blocks, where the ( rδ − d + k ) - th block express the mapping X (cid:55)→ X + Ψ (cid:0) X ; s r + kδ − δ 2 , s r + kδ + δ 2 (cid:1) for 0 ≤ r < n and 0 ≤ k < δ − d .
Given an input X , we denote the output of these stacked layers by ˜ X .
With a similar argument to that in Lemma 6 of [69], one can show that the mapping from ( X 1 z
X 2 z
[Equation]
n z ) to ˜ X n z is one-to-one.
Finally, we add an extra modified Transformer block, in which the modified feed-forward layer expresses an identity mapping, and the modified self-attention layer is
[Equation]
Note that we only use one attention head here and all the parameters in the other attention head are set to 0.
This block shifts all the layers by nδ − ( n +1)
d − 1 ˜ X n z , and ensures that any input X would be mapped to a unique number q ( X ) , thus implementing a contextual mapping.
A.5 Function value mapping via FFN
Once obtaining a contextual mapping, we can use stacked feed-forward layers to implement the function value mapping and obtain the desired sequence-to-sequence function.
Lemma 11 (Lemma 8 in [70]) .
Given δ > 0 a mapping h : R n × d → R n × d and assume there exists a vector u such that the mapping q ( X )
= h ( X ) z is a contextual mapping over { 0 , δ, 2 δ, · · · , 1 } n × d .
Then for any f : R n × d → R n × d , there exists a function g 4 : R n × d → R n × d which is compositions of modified Transformer blocks in T _ blocks m (2 , 1 , 1) , such that
[Equation]
A.6 Finishing the Proof of Theorem
With the preparations in the previous subsections, we present the proof of Theorem 3.
Proof.
Without the loss of generality, assume that D ⊆ [0 , 1] n × d .
Applying the Tietze extension theorem [18], one obtain an extended mapping f : [0 , 1] n × d → R n × d .
Therefore, it suffices to prove the theorem for any continuous sequence-to-sequence f : [0 , 1] n × d → R n × d .
Suppose δ is a positive real number such that δ − 1 ∈ Z .
Applying Lemma 7, Lemma 8, Lemma 10 and Lemma 11, we obtain ˜ g
(the quantization mapping), g 2 (the positional mapping), ˜ g 3 (the contextual mapping) and ˜ g 4 (the function value mapping), such that
[Equation]
[Equation]
Note that g 2 is an originally defined generalized Transformer blocks in T _ blocks U (2 , 1 , 4) , while ˜ g 1 , ˜ g 3 and ˜ g 4 are all compositions of modified Transformer blocks in T _ blocks m (2 , 1 , 1) .
Applying
Lemma 9 in [69], there exist compositions of originally defined generalized Transformer blocks g 1 , g 3 and g 4 , such that
[Equation]
[Equation]
where g = g 4 ◦ g 3 ◦ g 2 ◦ g 1 ∈ Ω 2 , 1 , 4 U and ˜ g
= ˜
g 4 ◦ ˜
g 3 ◦ g 2 ◦ ˜
g 1 .
Define ˜ g as a piece-wise linear approximation of f , such that f ( X ) =
¯ f ( X ) for any X ∈ { 0 , δ, 2 δ, · · · , 1 } n × d .
Then, by choosing δ to be sufficiently small, we have
[Equation]
The proof is completed by combining Eq.(20) and (21).
B Proof of Proposition
Proof.
Recall that the Universal RPE-based Attention is defined as
[Equation]
[Equation]
where 1 is an n -dimensional all-one vector and 1 c ⊤ K is the omitted bias term in Eq.(8).
It suffices to show that A U defined in Eq.(22) satisfies the two conditions in Theorem 3.
Attentive condition.
Note that the all-one matrix 11 ⊤ is a Toeplitz matrix by definition.
Therefore, we can set W Q = W K = u , c K = c and C = 11 ⊤ , and obtain A hU ( X ) = softmax (cid:0)
Xu
( Xu − c 1 ) ⊤ (cid:1) .
Position-aware condition.
First we set C as a upper triangular Toeplitz matrix:
[Equation] [Equation]
Then we set W Q =
W K = c
K = 0 .
It’s also easy to see that for any parametrization of B descibed in Section 2, we can force B = 0 by properly setting all the learnable parameters to 0.
In this case, for any X ∈ R n × d we have
[Equation]
To sum up, A U defined in Eq.(22) satisfies the two conditions in Theorem 3, which completes the proof.
C Experiments C.1 Synthetic Tasks
[Figure]
Baselines.
We choose the vanilla Transformer as the base model and compare the following ways to encode positional information: (1) no positional encodings (noPE); (2) T5-style relative positional encoding (RPE) [54]; (3) URPE with T5-style RPE backbone Transformer.
Settings.
For both the Position Identification (PI) and Even Token Prediction (ETP) tasks mentioned in Section 5.1, we use synthetic datasets with randomly generated sequences.
In detail, we vary the token vocabulary size from [10, 1000, 10000] and set the sequence length to 128.
The number of layers and the number of attention heads are set to 3 and 12, respectively.
The hidden dimension is set to 768.
We use Adam [34] as the optimizer, and set its hyperparameters ϵ to 1 e − 8 and ( β 1 , β 2 ) to (0 . 9 , 0 . 999) .
The peak learning rate is set to 7 e − 5 with a 6K-step warm-up stage.
After the warm-up stage, the learning rate decays linearly to zero.
The model is trained for 40K steps in total with the batch size as 512.
We set the dropout probability, gradient clip norm and weight decay to 0.0.
All models are trained on 4 NVIDIA Tesla V100 GPUs.
Ablation Study on the length of input sequences.
To comprehensively investigate the approximation capability of RPE-based Transformer and our URPE-based Transformer, we vary the sequence length in [256, 512] on the Position Identification task.
The results are presented in Figure 3.
Together with the results in Figure 1, we can see that our URPE-based Transformer consistently achieves 100% accuracy, while the Transformer without PE and the Transformer with T5-style RPE perform worse when the task becomes more difficult (i.e., the input sequences become longer).
The above results serve as further evidences that our URPE-based Transformer is consistent with our theoretical findings in Section 4.
C.2 Language Modeling Baselines.
We choose the Transformer-XL as the base model and compare the following ways to encode positional information: (1) Transformer-XL style relative positional encoding [10]; (2)
URPE with Transformer-XL style RPE backbone model.
Besides, we also include results of several competitive sequence models: (1) LSTM [21]; (2) Temporal Convolutional Network (TCN) [2]; (3) Gated Convolutional Neural Network (GCNN)
[11]; (4) LSTM with Neural Cache [21]; (5)
Quasi-Recurrent Neural Network [46]; (6) Hebbian Learning with Neural Cache [53].
Settings.
We conduct experiments on the WikiText-103 dataset [47], which contains 103M training tokens from 28K articles, with an average length of 3.6K tokens per article, which allows testing the ability of long-term dependency modeling.
We build our model based on the Transformer-XL Base model which consists of 16 decoder layers.
The number of attention head is set to 10.
The hidden dimension is set to 41.
The dimension of feed-forward layer is set to 2100.
The dropout ratio and the weight decay are set to 0.1 and 0.01, respectively.
We use Adam [34] as the optimizer, and set its hyperparameters ϵ to 1e
C.3 Graph Learning
We conduct experiments on three benchmark datasets covering graph and node representation learning tasks from small to large scale datasets: ZINC from Benchmarking-GNNs [16], PCQM4M and MAG24M from Open Graph Benchmark Large-Scale Challenge (OGB-LSC) [29].
C.3.1 ZINC
ZINC is a real-world dataset which consists of 250K molecular graphs.
The task is to predict the constrained solubility of a molecule which is an important chemical property for drug discovery.
We train our models on both the ZINC-Full and ZINC-Subset (12K selected graphs following [16]).
Baselines.
To demonstrate the power of our method and for fair comparison, we set the parameter budget of the model to be less than 500K following [16, 67].
We include results of several competitive GNNs: (1) Graph Isomorphism Network (GIN) [66]; (2) GraphSAGE [23]; (3) Graph
Attention Network (GAT) [62]; (4) Graph Convolutional Network [35]; (5) Mixture Model Network (MoNet) [48]; (6) Gated Graph Convolutional Network [5] with Positional Encodings [16] (GatedGCN-PE); (7) Message Passing Neural Network (MPNN(sum))
[20]; (8) Hierarchical Inter
Message Passing (HIMP) [17]; (9) Principal Neighbourhood Aggregation (PNA) [8].
Two representative Transformer-based models GraphTransformer (GT) [15] and Spectral Attention Network (SAN) [37] are also compared.
Settings.
We build on the Graphormer [67] model which consists of 12 layers.
The dimension of hidden layers and feed-forward layers are set to 80.
The number of attention heads are set to 32.
The batch size is selected from [128, 256, 512].
We use Adam [34] as the optimizer, and set its hyperparameter ϵ to 1e − 8 and ( β 1 , β 2 ) to (0.9, 0.999).
The peak learning rate is selected from [ 4e − 4 , 5e − 4 ].
The model is trained for 600k and 800k steps with a 60K-step warm-up stage for
ZINC-Subset and ZINC-Full
respectively.
After the warm-up stage, the learning rate decays linearly to zero.
The dropout ratio is selected from [0.0, 0.1].
The weight decay is selected from [0.0, 0.01].
All models are trained on 4 NVIDIA Tesla V100 GPUs.
C.3.2 PCQM4M
PCQM4M is a quantum chemistry regression task in OGB-LSC [29].
The PCQM4M dataset contains more than 3.8 million molecular graphs in total, which is currently the largest graph-level prediction dataset.
The state-of-the-art architecture for this task is the Graphormer [67] model introduced above.
Baselines.
Following [67], we include results of several competitive baselines: (1) Graph Convolutional Network [35]; (2) Graph Isomorphism Network (GIN) [66]; (3) Graph Convolutional
Network [35] with Virtual Node [20]; (4) Graph Isomorphism Network [66] with Virtual Node [20]; (5) Graph Isomorphism Network with Edge feature and Virtual Node (GINE-VN) [6, 20]; (6) Deeper
Graph Convolutional Network (DeeperGCN) [38]; (7) GraphTransformer [15].
Settings.
To demonstrate the power of our method and for fair comparison, We set the parameter budget of the model to be
less than 12.5M.
We still follow [67] to set the hyper-parameters in the
Graphromer model and equip it with URPE.
In detail, our Graphormer with URPE-based Attention consists of 6 layers and 32 attention heads.
The dimension of hidden layers and feed-forward layers are set to 512.
The batch size is 512.
We use Adam [34] as the optimizer, and set its hyperparameters ϵ to 1e − 8 and ( β 1 , β 2 ) to (0.9, 0.999).
The peak learning rate is set to 3e − 4 .
The model is trained for 1M steps with a 60k-step warm-up stage.
After the warm-up stage, the learning rate decays linearly to zero.
The dropout ratio for the input embedding, attention matrix and the hidden representation are set to 0.0, 0.1, 0.0 respectively.
The weight decay is set to 0.0.
All models are trained on 8 NVIDIA
Tesla V100 GPUs.
C.3.3 MAG240M
The MAG240M dataset contains a large-scale heterogeneous academic graph with more thanmillion nodes and 1.7 billion edges.
This giant graph is extracted from the Microsoft Academic
Graph (MAG) [64].
Given arXiv papers situated in the heterogeneous graph, the task requires the model to automatically annotate the topics of those papers, i.e., predicting the primary subject area of each arXiv paper.
Thus, it can be formulated as a node representation learning task.
[Table]
Settings.
To demonstrate the power of our method and for fair comparison, We set the parameter budget of the model to be less than 12.5M.
We build on the Graphormer [67] model which consists of 6 layers.
The dimension of hidden layers and feed-forward layers are set to 512.
The number of attention heads are set to 32.
The batch size is 1024.
We use Adam [34] as the optimizer, and set its hyperparameter ϵ to 1e − 8 and ( β 1 , β 2 ) to (0.9, 0.999).
The peak learning rate is set to 3e − 4 .
The model is trained for 100k steps with a 6k-step warm-up stage.
After the warm-up stage, the learning rate decays linearly to zero.
The dropout ratio and the weight decay is set to 0.5 and 0.01 respectively.
We also employ the stochastic depth [30] and set the probability to 0.1.
We follow the sub-graph sampling strategy from [29].
All models are trained on 32 NVIDIA Tesla V100 GPUs.
Results Table 6 summarizes performance comparisons on MAG240M dataset.
It can also be easily seen that the URPE-based Attention consistently improve the performance of the Graphormer model on the MAG240M node classification task.
The validation accuracy of the Graphormer model is improved by 0.06, which is currently the state-of-the-art single model performance on the leaderboard of MAG240M dataset.
C.4 URPE-based Transformers v.s. Transformers with both APE and RPE
We conduct experiments on the Language Pre-training task to evaluate different positional encoding strategies.
It is worth noting that in some competitive pre-training methods like UniLMv2 [3], APE and RPE have already been used together.
Thus, we choose this task as the benchmark.
We mainly test three model variants: Transformers with both APE and RPE, Transformers with RPE only, and our URPE-based Transformers.
For all the models, RPE is set to the T5 [54] version, following
UniLMv2.
We roughly keep the number of parameters of different models to the same and train the models in the BERT-base setting using the same hyper-parameters.
We choose the validation loss (masked language modeling loss after 1M iterations on a hold-out validation set) in the pre-training stage as the metric.
We observed that the validation losses of the Transformers with both APE and RPE, Transformers with RPE only, our URPE-based Transformers are 1.86, 1.94, and 1.87, respectively.
The results show that our URPE Transformer is competitive with Transformers with both APE and RPE and is much better than Transformers with RPE only.
Together with the above observations on the synthetic dataset in Section 5.1, we can see that URPE is competitive or even superior to previous APE and RPE or their combinations.