MCPcopy Create free account
hub / github.com/OpenSparseLLMs/MoM / loglikelihood_rolling

Method loglikelihood_rolling

lm-eval-harness/lm_eval/api/model.py:57–96  ·  view source on GitHub ↗

Compute full log-likelihood of a string, with no truncation, for perplexity computation - We will use the full max context length of the model. - For inputs that exceed the max context length, we divide the tokenized string into chunks of up to the max context length.

(self, requests)

Source from the content-addressed store, hash-verified

55
56 @abc.abstractmethod
57 def loglikelihood_rolling(self, requests) -> List[Tuple[float, bool]]:
58 """Compute full log-likelihood of a string, with no truncation, for perplexity computation
59 - We will use the full max context length of the model.
60 - For inputs that exceed the max context length, we divide the tokenized string into chunks of up to
61 the max context length.
62 - IMPORTANT: Each document's loglikelihood/perplexity is computed *separately*, unlike other implementations
63 which may simply concatenate multiple documents together.
64 - IMPORTANT: We maximize the amount of context for each prediction. Specifically, for inputs that we break into
65 multiple chunks, the last input will still a full-sized context.
66 Example:
67 Input tokens: [ 0 1 2 3 4 5 6 7 8 9 ]
68 Prefix: EOT
69 Max context length: 4
70 Resulting input/prediction pairs:
71
72 INPUT: EOT 0 1 2
73 PRED: 0 1 2 3
74
75 INPUT: 3 4 5 6
76 PRED: 4 5 6 7
77
78 INPUT: 5 6 7 8
79 PRED: 8 9
80
81 Observe that:
82 1. Each token is predicted exactly once
83 2. For the last pair, we provide the full context, but only score the last two tokens
84
85 :param requests: list[Instance]
86 A list of Instance objects with property `args` which returns a tuple (context, continuation).
87 string: str
88 String for which we are computing per-token loglikelihood
89 :return: list[tuple[float, bool]]
90 A list of pairs (logprob, isgreedy)
91 logprob: float
92 The log probability of `continuation`
93 isgreedy:
94 Whether `continuation` would be generated by greedy sampling from `context`
95 """
96 pass
97
98 # TODO: Add an optional max length
99 @abc.abstractmethod

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected