Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion src/lighteval/metrics/metrics_sample.py
Original file line number Diff line number Diff line change
Expand Up @@ -402,7 +402,8 @@ def compute(
else logprobs
)
probs = np.exp(normalized_log_probs)
return self.aggregation_function(probs)
gold_ixs = as_list(doc.gold_index)
return self.aggregation_function(probs[gold_ixs])


class Recall(SampleLevelComputation):
Expand Down
13 changes: 10 additions & 3 deletions tests/test_unit_base_metrics.py
Original file line number Diff line number Diff line change
Expand Up @@ -200,10 +200,17 @@ def test_prob(self):
result = prob_metric.compute_sample(doc=doc, model_response=model_response)
assert result[prob_metric.metric_name] == pytest.approx(0.7)

# Aggregation function test
model_response = ModelResponse(logprobs=np.log([0.7, 0.1]))
# Aggregation function test over multiple golds
doc_multi_gold = Doc(query="Test query", choices=["A", "B", "C"], gold_index=[0, 1], task_name="test")
model_response = ModelResponse(logprobs=np.log([0.7, 0.1, 0.05]))
prob_min_metric = ProbabilityMetric(aggregation_function=np.min)
result = prob_min_metric.compute_sample(doc=doc, model_response=model_response)
result = prob_min_metric.compute_sample(doc=doc_multi_gold, model_response=model_response)
assert result[prob_metric.metric_name] == pytest.approx(0.1)

# Gold is not the argmax: the metric must return the gold probability
doc_gold_not_argmax = Doc(query="Test query", choices=["A", "B", "C"], gold_index=1, task_name="test")
model_response = ModelResponse(logprobs=np.log([0.7, 0.1, 0.05]))
result = prob_metric.compute_sample(doc=doc_gold_not_argmax, model_response=model_response)
assert result[prob_metric.metric_name] == pytest.approx(0.1)

def test_mc_probability_metric(self):
Expand Down