HackerPapers

arXiv:2104.09864cs.CL

RoFormer: Enhanced Transformer with Rotary Position Embedding

Jianlin Su, Yu Lu, Shengfeng Pan, Ahmed Murtadha, Bo Wen, Yunfeng Liu

Abstract

Position encoding recently has shown effective in the transformer architecture. It enables valuable supervision for dependency modeling between elements at different positions of the sequence. In this paper, we first investigate various methods to integrate positional information into the learning process of transformer-based language models. Then, we propose a novel method named Rotary Position Embedding(RoPE) to effectively leverage the positional information. Specifically, the proposed RoPE encodes the absolute position with a rotation matrix and meanwhile incorporates the explicit relative position dependency in self-attention formulation. Notably, RoPE enables valuable properties, including the flexibility of sequence length, decaying inter-token dependency with increasing relative distances, and the capability of equipping the linear self-attention with relative position encoding. Finally, we evaluate the enhanced transformer with rotary position embedding, also called RoFormer, on various long text classification benchmark datasets. Our experiments show that it consistently overcomes its alternatives. Furthermore, we provide a theoretical analysis to explain some experimental results. RoFormer is already integrated into Huggingface: \url{https://huggingface.co/docs/transformers/model_doc/roformer}.

arXiv comments
fixed some typos
Journal reference
DOI
Subjects
cs.CLComputation and Language cs.AIArtificial Intelligence cs.LGMachine Learning

On Hacker News

Linked by 7 identifiable commenters in 7 comments across 7 threads, from Mar 2023 to Aug 2025.

Comments linking this paper, per year.

Discussed in comments7 threads

  1. Open models by OpenAI 1 comment
    • All the Llamas have done it (well, 2 and 3, and I believe 1, I don't know about 4). I think they have a citation for it, though it might just be the RoPE paper (https://arxiv.org/abs/2104.09864). I'm not actually aware of any model that doesn't do positional embeddings on a…

      spottView on HNParent context

  2. Llama 4 Now Live on Groq 1 comment
    • Not sure what you mean by summary paper, its a pretty dense topic that assumes a fair amount of prior knowledge of the fundamentals. But maybe the Meta blog post may suffice for that? Otherwise yes there are lots of papers on this and related topics, a few dozen in fact. But…

      spmurrayzzzView on HNParent context

  3. The Llama 4 herd 1 comment
    • the large context windows generally involve RoPE[0] which is a trick that allows the training window to be smaller but expand larger during inference. it seems like they have a new "iRoPE" which might have better performance? [0]https://arxiv.org/pdf/2104.09864

      jimmyl02View on HNParent context

  4. Multi-Token Attention 1 comment
    • LLaMa 3 already has RoPE encoding which can handle arbitrarily long contexts (within reason) https://arxiv.org/abs/2104.09864 The difference RoPE makes vs traditional positional encoding is that you just care about relative distances between tokens, and we can attenuate the…

      EGregView on HNParent context

    • Cool, there are also additional issues with the RoPEAttention you might want to fix as well : The reference paper for rotary embedding is Roformer https://arxiv.org/pdf/2104.09864v4.pdf First you shouldn't rotate the values, only keys and queries. This is wrong : v_out =…

      GistNoesisView on HNParent context

    • Sinusoidal positional embeddings have always seemed a bit mysterious - even more so since papers don't tend to delve much into the intuition behind them. For example, from Vaswani et al., 2017: > That is, each dimension of the positional encoding corresponds to a sinusoid. The…

      mfnView on HNParent context

    • It doesn't really use them, it uses something called RoPE which is hardcoded rather than learned and is applied multiplicatively at every layer to both the key and the value. https://arxiv.org/abs/2104.09864

      sebzim4500View on HNParent context

Submitted to Hacker News

Connected through shared HN threads, not inferred similarity or a recommendation.