← all repositories
ZhuiyiTechnology/roformer

Teaching Transformers to rotate for relative position

A pre-trained Chinese language model that replaces learned position embeddings with rotation matrices so attention naturally respects relative distance.

1.1k stars Python Language Models
roformer
Not currently ranked — collecting fresh signals.
star history

What it does RoFormer is a masked language model that encodes sequence order through Rotary Position Embedding (RoPE). Rather than adding position vectors to word embeddings, it applies rotation matrices to query and key vectors inside the attention mechanism. The result is that attention scores become a function of relative position, backed by a short geometric proof.

The interesting bit The authors note that RoPE is uniquely compatible with linear attention approximations, a property other relative encodings lack. The same trick later appeared in EleutherAI’s GPT-Neo and GPT-NeoX, confirming that a small rotation in Chinese BERT-style code could scale to large generative stacks.

Key highlights

  • Uses sinusoidal rotation matrices instead of additive absolute position vectors
  • Ships with several pre-trained Chinese checkpoints, including character-level and similarity-tuned variants
  • The core change is a minimal patch to standard self-attention (the README shows the logic in a handful of lines)
  • Downstream ports exist for PyTorch, x-transformers, GPT-Neo, and GPT-NeoX
  • Accompanied by a 2021 arXiv paper with formal derivations

Caveats

  • The provided code is tightly coupled to bert4keras 0.10.4; PyTorch users should follow the linked third-party implementations
  • All downloadable checkpoints are Chinese; no English pre-trained weights are hosted here

Verdict Grab it if you are researching position encodings or need a Chinese MLM baseline built on geometric intuition. Otherwise, import RoPE from your favorite modern framework—it has already traveled far beyond this repo.

Frequently asked

What is ZhuiyiTechnology/roformer?
A pre-trained Chinese language model that replaces learned position embeddings with rotation matrices so attention naturally respects relative distance.
Is roformer open source?
Yes — ZhuiyiTechnology/roformer is open source, released under the Apache-2.0 license.
What language is roformer written in?
ZhuiyiTechnology/roformer is primarily written in Python.
How popular is roformer?
ZhuiyiTechnology/roformer has 1.1k stars on GitHub.
Where can I find roformer?
ZhuiyiTechnology/roformer is on GitHub at https://github.com/ZhuiyiTechnology/roformer.

heatdrop uses Google Analytics to see which pages get read — nothing else. Your call. How we handle data.