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
7 changes: 5 additions & 2 deletions src/lighteval/metrics/metrics_corpus.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
import logging
import math
from abc import ABC, abstractmethod
from itertools import zip_longest
from typing import Literal

import numpy as np
Expand Down Expand Up @@ -152,8 +153,10 @@ def compute_corpus(self, items: list[GenerativeCorpusMetricInput]) -> float:
)
preds.append(pred[0])

if self.metric_type == "bleu":
golds = [[gold[0] for gold in golds]]
# sacrebleu expects references in [ref_id][sent_id] shape, but golds is
# collected as [sent_id][ref_id]. Transpose so each inner list is one
# reference stream across all hypotheses.
golds = [list(refs) for refs in zip_longest(*golds, fillvalue=None)]

corpus_score = metric.corpus_score(hypotheses=preds, references=golds)
score = corpus_score.score
Expand Down
16 changes: 8 additions & 8 deletions tests/unit/metrics/test_cases/chrf.json
Original file line number Diff line number Diff line change
Expand Up @@ -79,9 +79,9 @@
"text": ["Das Wetter ist schön"]
}
],
"expected_output": 100.0,
"expected_output": 89.16,
"tolerance": 0.1,
"description": "High similarity - minor character differences (CHRF ≈ 88.0)"
"description": "High similarity - minor character differences (CHRF ≈ 89.0)"
},
{
"name": "CHRF - Word Order Changes",
Expand Down Expand Up @@ -119,9 +119,9 @@
"text": ["Lernen Maschinelles"]
}
],
"expected_output": 78.84,
"expected_output": 82.21,
"tolerance": 0.1,
"description": "Word order changes - same characters, different order (CHRF ≈ 75.0)"
"description": "Word order changes - same characters, different order (CHRF ≈ 82.0)"
},
{
"name": "CHRF - Moderate Similarity",
Expand Down Expand Up @@ -159,9 +159,9 @@
"text": ["Die Sterne"]
}
],
"expected_output": 37.68,
"expected_output": 34.85,
"tolerance": 0.1,
"description": "Moderate similarity - partial character overlap (CHRF ≈ 50.0)"
"description": "Moderate similarity - partial character overlap (CHRF ≈ 35.0)"
},
{
"name": "CHRF - Low Similarity",
Expand Down Expand Up @@ -199,9 +199,9 @@
"text": ["Es sehr heiß"]
}
],
"expected_output": 7.7,
"expected_output": 6.83,
"tolerance": 0.1,
"description": "Low similarity - minimal character overlap (CHRF ≈ 20.0)"
"description": "Low similarity - minimal character overlap (CHRF ≈ 7.0)"
}
]
}
14 changes: 7 additions & 7 deletions tests/unit/metrics/test_cases/chrf_plus.json
Original file line number Diff line number Diff line change
Expand Up @@ -79,9 +79,9 @@
"text": ["Das Wetter ist schön"]
}
],
"expected_output": 100.0,
"expected_output": 88.07,
"tolerance": 0.1,
"description": "High similarity - minor character differences (CHRF++ ≈ 85.0)"
"description": "High similarity - minor character differences (CHRF++ ≈ 88.0)"
},
{
"name": "CHRF Plus - Moderate Similarity",
Expand Down Expand Up @@ -119,9 +119,9 @@
"text": ["ML"]
}
],
"expected_output": 58.82,
"expected_output": 24.45,
"tolerance": 0.1,
"description": "Moderate similarity - significant character omissions (CHRF++ ≈ 45.0)"
"description": "Moderate similarity - significant character omissions (CHRF++ ≈ 24.0)"
},
{
"name": "CHRF Plus - Low Similarity",
Expand Down Expand Up @@ -159,9 +159,9 @@
"text": ["Es heiß"]
}
],
"expected_output": 15.0,
"tolerance": 10.0,
"description": "Low similarity - minimal character overlap (CHRF++ ≈ 15.0)"
"expected_output": 2.73,
"tolerance": 0.1,
"description": "Low similarity - minimal character overlap (CHRF++ ≈ 2.7)"
}
]
}
8 changes: 4 additions & 4 deletions tests/unit/metrics/test_cases/ter.json
Original file line number Diff line number Diff line change
Expand Up @@ -79,9 +79,9 @@
"text": ["Das Wetter ist schön"]
}
],
"expected_output": 0.0,
"tolerance": 0.05,
"description": "Minor edits - small word differences"
"expected_output": 9.09,
"tolerance": 0.1,
"description": "Minor edits - one missing word across 3 sentences"
},
{
"name": "TER - Major Edits",
Expand Down Expand Up @@ -159,7 +159,7 @@
"text": ["Es ist sehr heiß"]
}
],
"expected_output": 80.0,
"expected_output": 100.0,
"tolerance": 0.1,
"description": "Completely different translations - maximum edit distance"
}
Expand Down