artefactual.scoring.EntropyContributionsMixin#

class artefactual.scoring.EntropyContributionsMixin[source]#

Bases: object

Provides entropy_contributions to the transformers that reduce it.

Methods

entropy_contributions

Entropy contribution s_kj = -p_kj * ln(p_kj) for each candidate of each token.

static entropy_contributions(logprobs)[source]#

Entropy contribution s_kj = -p_kj * ln(p_kj) for each candidate of each token.

The contribution peaks at p = 1/e, so it is not monotonic in rank: a mid-ranked candidate contributes more than either a near-certain top rank or a negligible tail one.

Candidates are sorted by likelihood before the conversion, so callers need not supply them in order. NaN sorts to the end and propagates, keeping padded positions padded.

In nats, matching the ECIR2026 release the paper’s results were produced with. The paper writes the entropy in bits (Eq. 1 and 3); the two differ by a factor of ln 2, which a fitted coefficient absorbs, so the released convention is the one to follow – it is what the published weights were trained against.

Parameters:

logprobs (ndarray) – Natural-log probabilities, with the rank axis last. Any number of leading axes is allowed.

Return type:

ndarray

Returns:

Contributions in nats, same shape, NaN in the same positions.