artefactual.scoring.epr_reduction#
- artefactual.scoring.epr_reduction(x, axis)[source]#
Entropy Production Rate: the truncated entropy, averaged over tokens.
The paper’s Eq. 6 – the mean over the sequence of the top-K entropy estimate H~_K = -sum_k p_k ln p_k (Eq. 3). So the rank axis is summed, not averaged: the result is an entropy, on the same scale as H(q) itself, in nats as the ECIR2026 release computes it.
A token whose candidates are entirely NaN is padding rather than data, and is excluded from the token mean rather than contributing the 0 that nansum would give it.
A fully padded sequence is an expected input, not an anomaly: EntropyTransformer.transform detects it and raises EmptySequenceWarning, which names the condition. numpy’s “Mean of empty slice” reports the same thing a second time from a frame that points here, so it is silenced inside this reduction only, and a caller-supplied reduction keeps its own warnings.
- Parameters:
x (ndarray of shape (..., n_tokens, k)) – Entropy contributions, NaN-padded; the last axis is the rank axis.
axis (int) – The token axis to average over.
- Returns:
Shape (n_sequences, 1): one value per sequence, NaN where the sequence has no token.
- Return type:
ndarray