incerto.llm.TopKConfidence#

class incerto.llm.TopKConfidence[source]#

Bases: object

Confidence based on probability mass in top-k tokens.

Measures what fraction of probability mass is concentrated in the top k most likely tokens. Higher values indicate lower uncertainty (more concentrated distribution).

__init__()#

Methods

__init__()

compute(logits[, k, dim])

Compute top-k probability mass.

static compute(logits, k=5, dim=-1)[source]#

Compute top-k probability mass.

Parameters:
  • logits (Tensor) – Token logits of shape (…, vocab_size)

  • k (int) – Number of top tokens to consider

  • dim (int) – Dimension to compute over (default: -1)

Return type:

Tensor

Returns:

Top-k probability mass of shape (…,)