in src/epam/auto_llm_eval/evaluator.py [0:0]
def set_probabilities(self, top_logprobs: List[dict]) -> None:
"""
Set probabilities from the LLM response metadata.
Processes the log probabilities from the LLM response, converting them
to probabilities for scores 1-5. Ignores tokens that are not in this
range or have very low probabilities.
Args:
top_logprobs (List[dict]): A list of dictionaries containing token
and logprob information.
"""
for logprob in top_logprobs:
token: str = logprob["token"]
try:
token_int: int = int(token)
if token_int not in [1, 2, 3, 4, 5]:
raise ValueError("Token is not in the range 1-5")
except ValueError:
break
logprob_value: float = logprob["logprob"]
probability: float = np.round(np.exp(logprob_value), 2)
if probability < 0.01: # Ignore tokens with low probability
break
self.probabilities.append((token_int, probability))