bert_base_cls(pretrained: bool | str = False, weights: BERTBaseWeights | None = None, overrides: object = {})Construct a BERT-Base model with a sequence-classification head.
Same trunk as bert_base (L=12, H=768, A=12), augmented with a
pooled-CLS linear classifier of output width config.num_labels. The
canonical fine-tuning recipe for GLUE-style single-sentence and
sentence-pair tasks (SST-2, MNLI, QQP, RTE, MRPC, STS-B).
Model Size
Parameters
pretrainedbool or str= FalseEncoder-weight selector.
False → fully random init; True
→ loads the pretrained bert_base encoder
(BERTBaseWeights.DEFAULT) into the .bert trunk; a tag
string selects a specific encoder checkpoint. The classification
head is always randomly initialised — this is the standard
fine-tuning starting point (no GLUE-fine-tuned head ships), so
train on a downstream task before inference.weights(BERTBaseWeights, optional, keyword - only)= NoneExplicit encoder-weights enum member; takes precedence over
pretrained.**overridesobject= {}Optional
BERTConfig field overrides forwarded into the
underlying config. Pass num_labels=N to set the number of
classes (default 2). Overrides that change the encoder shape are
incompatible with loading pretrained encoder weights.Returns
BERTForSequenceClassificationBERT-Base wrapped with the pooled classifier head (encoder pretrained when requested; head random).
Notes
Reference: Devlin, Chang, Lee, and Toutanova, "BERT: Pre-training of Deep Bidirectional Transformers for Language Understanding", NAACL 2019 (arXiv:1810.04805) §4.1.
Examples
>>> import lucid
>>> from lucid.models.text.bert import bert_base_cls
>>> model = bert_base_cls(num_labels=3).eval()
>>> input_ids = lucid.tensor([[101, 7592, 102]])
>>> out = model(input_ids)
>>> out.logits.shape # (1, num_labels=3)
(1, 3)