Skip to content
data

QuestionAnsweringOutput

extendsModelOutput
QuestionAnsweringOutput(start_logits: Tensor, end_logits: Tensor, loss: Tensor | None = None, hidden_states: tuple[Tensor, ...] | None = None, attentions: tuple[Tensor, ...] | None = None)

Output of any extractive span-prediction head.

Attributes

start_logitsTensor
Per-position start-of-span logits, shape (B, T).
end_logitsTensor
Per-position end-of-span logits, shape (B, T).
loss(Tensor or None, optional)
Mean of the start and end cross-entropy terms when both start_positions and end_positions were supplied.
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}ForQuestionAnswering head. The two logit tensors are kept separate rather than fused into a single (B, T, 2) tensor: a caller that wants the best span argmaxes each independently, and a fused tensor forces every one of them to remember which trailing index means "start".

Examples

>>> import lucid
>>> from lucid.models import QuestionAnsweringOutput
>>> out = QuestionAnsweringOutput(
...     start_logits=lucid.zeros(1, 384),
...     end_logits=lucid.zeros(1, 384),
... )
>>> out.start_logits.shape, out.end_logits.shape
((1, 384), (1, 384))

Used by 3