scores.MarginScore

Top-two margin confidence score.

Usage

Source

scores.MarginScore()

Computes the difference between the top-two logits. A larger margin indicates higher confidence (lower score). Supports multiclass, binary (single/two-logit), and multilabel tasks.

Parameters

temperature: float or None = None

Optional initial temperature. If None, temperature is fitted if labels are provided to fit.

task: ("multiclass", "binary", "multilabel") = "multiclass"
Task type for score computation.

Examples

import torch
from seapig.scores.logits import MarginScore
logits = torch.randn(2, 3)
MarginScore().score(logits)

Attributes

Name Description
ident str(object=’’) -> str

ident

str(object=’’) -> str

ident: str = "margin"

str(bytes_or_buffer[, encoding[, errors]]) -> str

Create a new string object from the given object. If encoding or errors is specified, then the object must expose a data buffer that will be decoded using the given encoding and error handler. Otherwise, returns the result of object.__str__() (if defined) or repr(object). encoding defaults to sys.getdefaultencoding(). errors defaults to ‘strict’.

Methods

Name Description
score() Compute task-aware margin-based confidence score.

score()

Compute task-aware margin-based confidence score.

Usage

Source

score(query_logits)

For multiclass: negative top-two margin. For binary single-logit: negative absolute logit. For binary two-logit: negative top-two margin. For multilabel: negative min(|logit|).

Returns
torch.Tensor
1-D tensor of shape (M,) with scores (lower == more confident).

See Also