bert_base_qa(pretrained: bool | str = False, weights: BERTBaseQAWeights | None = None, overrides: object = {})Construct a BERT-Base extractive-QA model (SQuAD v1.1).
Same trunk as bert_base (L=12, H=768, A=12), augmented with a
2-way linear head producing start- and end-position logits over each
input token.
Model Size
Parameters
pretrainedbool or str= FalseWeight selector.
False → random init; True → the SQuAD v1.1
fine-tuned checkpoint (BERTBaseQAWeights.SQUAD_V1, from
csarron/bert-base-uncased-squad-v1) — an inference-ready
extractive-QA model (EM ≈ 80.9 / F1 ≈ 88.1). Tokenize with the
uncased BERTTokenizer.weights(BERTBaseQAWeights, optional, keyword - only)= NoneExplicit weights enum member; takes precedence over
pretrained.**overridesobject= {}Optional
BERTConfig field overrides forwarded into the
underlying config. num_labels is ignored by this head.
Overrides that change the encoder shape are incompatible with the
pretrained checkpoint.Returns
BERTForQuestionAnsweringBERT-Base wrapped with the span-prediction head (fully fine-tuned
on SQuAD when pretrained is requested).
Notes
Reference: Devlin, Chang, Lee, and Toutanova, "BERT: Pre-training of Deep Bidirectional Transformers for Language Understanding", NAACL 2019 (arXiv:1810.04805) §4.2.
Examples
>>> import lucid
>>> from lucid.models.text.bert import bert_base_qa
>>> model = bert_base_qa().eval()
>>> # question + context (CLS q [SEP] c [SEP]) ids
>>> input_ids = lucid.tensor([[101, 2040, 102, 1045, 2572, 102]])
>>> out = model(input_ids)
>>> out.logits.shape # (1, T=6, 2) — last dim is (start, end)
(1, 6, 2)