RoFormerForSequenceClassification
_RoFormerInitMixinSequenceClassificationModelRoFormerForSequenceClassification(config: RoFormerConfig)RoFormer with a pooled-CLS sequence-classification head.
Wraps RoFormerModel (built without its pooler, which this head
never reads) with the reference's own classification head: the raw CLS
hidden state passes through dropout, a hidden_size -> hidden_size
dense, the configured activation, dropout again, and finally the
num_labels projection. Use for GLUE-style fine-tunes when the
RoPE-based relative position bias is preferred.
Parameters
configRoFormerConfigconfig.num_labels sets the output dimension;
config.classifier_dropout (falling back to hidden_dropout)
sets the dropout applied before the linear.Attributes
roformerRoFormerModelclassifiernn.Moduleclassifier.dense
(hidden_size -> hidden_size), activation, dropout, then
classifier.out_proj (hidden_size -> num_labels) producing
per-class logits.Notes
Reference: Su, Lu, Pan, Murtadha, Wen, and Liu, "RoFormer: Enhanced Transformer with Rotary Position Embedding", Neurocomputing, vol. 568, 2024 (arXiv:2104.09864).
Checkpoints saved before the head was nested (top-level dense.* /
classifier.*, plus an unused roformer.pooler.*) are migrated on
load_state_dict.
Loss (when labels is provided) is the standard softmax
cross-entropy:
Examples
>>> import lucid
>>> from lucid.models.text.roformer import (
... RoFormerConfig, RoFormerForSequenceClassification,
... )
>>> cfg = RoFormerConfig(num_labels=3, num_hidden_layers=2,
... hidden_size=128, num_attention_heads=2,
... intermediate_size=512)
>>> model = RoFormerForSequenceClassification(cfg).eval()
>>> input_ids = lucid.tensor([[101, 7592, 102]])
>>> out = model(input_ids)
>>> out.logits.shape # (B=1, num_labels=3)
(1, 3)Used by 2
Constructors
1Instance methods
1forward(input_ids: Tensor, attention_mask: Tensor | None = None, token_type_ids: Tensor | None = None, labels: Tensor | None = None)Override in subclasses to define the computation.