Skip to content
data

MaskedLMOutput

extendsModelOutput
MaskedLMOutput(logits: Tensor, loss: Tensor | None = None, hidden_states: tuple[Tensor, ...] | None = None, attentions: tuple[Tensor, ...] | None = None)

Output of any masked-LM head (BERT, RoFormer, …).

Attributes

logitsTensor
Per-position vocabulary logits, shape (B, T, vocab_size).
loss(Tensor or None, optional)
Scalar cross-entropy loss reduced over masked positions only (ignore_index=-100 for non-masked tokens).
hidden_states(tuple[Tensor, ...] or None, optional)
Per-layer hidden states.
attentions(tuple[Tensor, ...] or None, optional)
Per-layer attention weights.

Notes

Returned by every {Family}ForMaskedLM registration — BERTForMaskedLM, RoFormerForMaskedLM, and future encoder LM heads. Loss is computed via MaskedLMMixin.compute_lm_loss.

Examples

>>> import lucid
>>> from lucid.models import MaskedLMOutput
>>> out = MaskedLMOutput(logits=lucid.zeros(1, 128, 30522))
>>> out.logits.shape              # (B, T, vocab)
(1, 128, 30522)

Used by 3