gpt_cls(pretrained: bool | str = False, weights: GPTWeights | None = None, overrides: object = {})Construct a GPT-1 model with a last-token sequence-classification head.
Same trunk as gpt (L=12, H=768, A=12), augmented with a linear
classifier on the last non-pad token's hidden state — the canonical
decoder-style pooling strategy. Use for GLUE-style classification when
you specifically want autoregressive features rather than bidirectional
BERT-style ones.
Model Size
Parameters
pretrainedbool or str= FalseEncoder-weight selector.
False → fully random init; True
→ loads the pretrained gpt decoder trunk
(GPTWeights.DEFAULT) into the .transformer submodule;
a tag string selects a specific encoder checkpoint. The
classifier head is always randomly initialised (fine-tuning
starting point — no GLUE-fine-tuned head ships).weights(GPTWeights, optional, keyword - only)= NoneExplicit encoder-weights enum member; takes precedence over
pretrained.**overridesobject= {}Optional
GPTConfig field overrides forwarded into the
underlying config. Pass num_labels=N to set the number of
output classes (default 2). Overrides that change the trunk shape
are incompatible with loading pretrained encoder weights.Returns
GPTForSequenceClassificationGPT-1 trunk wrapped with the last-token classifier head (encoder pretrained when requested; head random).
Notes
Reference: Radford et al., "Improving Language Understanding by Generative Pre-Training", OpenAI Technical Report, 2018, §3.3.
Pooling picks index (i.e. the rightmost real token) per row, then applies dropout + linear:
Examples
>>> import lucid
>>> from lucid.models.text.gpt import gpt_cls
>>> model = gpt_cls(num_labels=3).eval()
>>> input_ids = lucid.tensor([[101, 7592, 102]])
>>> out = model(input_ids)
>>> out.logits.shape # (B=1, num_labels=3)
(1, 3)