Skip to content
data

TokenClassificationOutput

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

Output of any per-token classification head (NER, POS, chunking).

Attributes

logitsTensor
Per-token class logits, shape (B, T, num_labels).
loss(Tensor or None, optional)
Scalar cross-entropy loss over the non-ignored positions.
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}ForTokenClassification head. The logits have the same rank as a masked-LM head's, but the last axis is a label set rather than a vocabulary — the distinct type keeps the two from being confused.

Examples

>>> import lucid
>>> from lucid.models import TokenClassificationOutput
>>> out = TokenClassificationOutput(logits=lucid.zeros(1, 128, 9))
>>> out.logits.shape              # (B, T, num_labels)
(1, 128, 9)

Used by 4