class
RoFormerForTokenClassification
extends
PretrainedModelMaskedLMMixinRoFormerForTokenClassification(config: RoFormerConfig)RoFormer with a per-token classification head.
Wraps RoFormerModel with a dropout-regularised linear
classifier applied independently at every sequence position. Pattern
mirrors BERTForTokenClassification — used for sequence-
labelling tasks (NER / POS / chunking) on RoPE-trained encoders.
Parameters
configRoFormerConfigHyperparameters.
config.num_labels sets the per-position output
dimension; config.classifier_dropout (falling back to
hidden_dropout) sets the dropout applied before the linear.Attributes
roformerRoFormerModelUnderlying RoPE encoder trunk.
dropoutnn.DropoutDropout applied to the full sequence hidden states.
classifiernn.LinearFinal linear of shape
(hidden_size, num_labels) mapping each
token's hidden state to 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 masked cross-entropy inherited
from MaskedLMMixin:
where is the set of positions with label != -100.
Examples
>>> import lucid
>>> from lucid.models.text.roformer import (
... RoFormerConfig, RoFormerForTokenClassification,
... )
>>> cfg = RoFormerConfig(num_labels=9, num_hidden_layers=2,
... hidden_size=128, num_attention_heads=2,
... intermediate_size=512)
>>> model = RoFormerForTokenClassification(cfg).eval()
>>> input_ids = lucid.tensor([[101, 7592, 2088, 102]])
>>> out = model(input_ids)
>>> out.logits.shape # (B=1, T=4, num_labels=9)
(1, 4, 9)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)