Some products shade parts of an answer the model was unsure about, so readers know what to double-check. With per-token log-probabilities, find those spans.
Implement:
low_confidence_spans(logprobs, threshold, max_gap=0): a token is low-confidence if exp(logprob) < threshold. Return half-open (start, end) index ranges of consecutive low-confidence tokens, merging two spans separated by at most max_gap confident tokens.span_texts(tokens, spans): the joined text of each span ("".join(tokens[start:end]))answer_confidence(logprobs): the geometric-mean token probability, exp(mean(logprobs)) (1.0 for an empty answer)