artefactual.preprocessing.parse_top_logprobs#

artefactual.preprocessing.parse_top_logprobs(outputs)[source]#

Extract each token’s top-k logprobs, one entry per sampled sequence.

Parameters:

outputs (Any) – A completion response, as a mapping or an object, or a collection of them (list, tuple, 1-D object array, Series) parsed and concatenated in order.

Return type:

list[dict[int, list[float]]]

Returns:

One dict per sequence, mapping token position to that token’s candidate log-probabilities, most likely first. Ragged: a position whose top_logprobs was empty maps to an empty list, and the position is still counted so token indices track the generated text.

Raises:
  • TypeError – If the output matches no completion format, including a batch line whose body matches none.

  • ValidationError – If it matches one but carries an invalid field, named by the error pydantic raised.

  • ValueError – If a batch line carries no completion, because its request failed.