class
RoFormerForSequenceClassification
extends
PretrainedModelRoFormerForSequenceClassification(config: RoFormerConfig)RoFormer with a pooled-CLS sequence-classification head.
Wraps RoFormerModel with a dropout-regularised linear
classifier operating on the pooled first-token embedding. Pattern
mirrors BERTForSequenceClassification; use for GLUE-style
fine-tunes when the RoPE-based relative position bias is preferred.
Parameters
configRoFormerConfigHyperparameters.
config.num_labels sets the output dimension;
config.classifier_dropout (falling back to hidden_dropout)
sets the dropout applied before the linear.Attributes
roformerRoFormerModelUnderlying RoPE encoder trunk.
dropoutnn.DropoutDropout layer applied to the pooled first-token embedding.
classifiernn.LinearFinal linear of shape
(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).
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)