roformer(pretrained: bool | str = False, weights: RoFormerWeights | None = None, overrides: object = {})Construct a RoFormer encoder trunk.
Canonical RoFormer architecture from Su, Lu, Pan, Murtadha, Wen, and Liu, 2024: transformer layers, hidden, attention heads, intermediate width 3072 — same shape as BERT-base, but with absolute learned position embeddings replaced by rotary position embedding (RoPE) applied to and inside every self-attention layer. Max sequence length is extended from 512 to 1536 to exercise RoPE's length-extrapolation property.
Model Size
Parameters
pretrainedbool= FalseReserved for future weight registration; currently a no-op.
weights(RoFormerWeights, optional, keyword - only)= NoneExplicit weights enum member; takes precedence over
pretrained.**overridesobject= {}Optional
RoFormerConfig field overrides (e.g.
vocab_size=..., rotary_base=...,
max_position_embeddings=...) forwarded into the underlying
config.Returns
RoFormerModelEncoder trunk configured with the paper defaults plus any overrides.
Notes
Reference: Su, Lu, Pan, Murtadha, Wen, and Liu, "RoFormer: Enhanced Transformer with Rotary Position Embedding", Neurocomputing, vol. 568, 2024, article 127063 (arXiv:2104.09864).
Rotary rotation matrix per pair:
Examples
>>> import lucid
>>> from lucid.models.text.roformer import roformer
>>> model = roformer().eval()
>>> input_ids = lucid.tensor([[101, 7592, 2088, 102]])
>>> out = model(input_ids)
>>> out.last_hidden_state.shape, out.pooler_output.shape
((1, 4, 768), (1, 768))