From 3805267d002401f74ab860e9bc759d45de1b6f4d Mon Sep 17 00:00:00 2001 From: Boulea7 <145515129+Boulea7@users.noreply.github.com> Date: Thu, 3 Dec 2026 04:55:37 +0800 Subject: [PATCH] Allow METEOR to return one score per prediction --- metrics/meteor/README.md | 9 +++++++++ metrics/meteor/meteor.py | 10 +++++++--- 2 files changed, 16 insertions(+), 3 deletions(-) diff --git a/metrics/meteor/README.md b/metrics/meteor/README.md index 4d4f21c74..325019b8e 100644 --- a/metrics/meteor/README.md +++ b/metrics/meteor/README.md @@ -54,6 +54,8 @@ It also has several optional parameters: `gamma`: The relative weight assigned to fragmentation penalty. The default is `0.5`. +`use_aggregator`: If `True` (the default), return the mean score. If `False`, return one score per prediction, in input order. + Refer to the [METEOR paper](https://aclanthology.org/W05-0909.pdf) for more information about parameter values and ranges. ```python @@ -70,6 +72,13 @@ The metric outputs a dictionary containing the METEOR score. Its values range fr {'meteor': 0.9999142661179699} ``` +To get the individual scores: + +```python +>>> meteor.compute(predictions=["red", "blue sky"], references=["red", "blue sky"], use_aggregator=False) +{'meteor': [0.5, 0.9375]} +``` + ### Values from popular papers The [METEOR paper](https://aclanthology.org/W05-0909.pdf) does not report METEOR score values for different models, but it does report that METEOR gets an R correlation value of 0.347 with human evaluation on the Arabic data and 0.331 on the Chinese data. diff --git a/metrics/meteor/meteor.py b/metrics/meteor/meteor.py index bc023a8e2..c35fd6600 100644 --- a/metrics/meteor/meteor.py +++ b/metrics/meteor/meteor.py @@ -75,8 +75,9 @@ alpha: Parameter for controlling relative weights of precision and recall. default: 0.9 beta: Parameter for controlling shape of penalty as a function of fragmentation. default: 3 gamma: Relative weight assigned to fragmentation penalty. default: 0.5 + use_aggregator: Return the mean score if True (default), or one score per prediction if False. Returns: - 'meteor': meteor score. + 'meteor': the mean score or a list of scores in prediction order. Examples: >>> meteor = evaluate.load('meteor') @@ -85,6 +86,9 @@ >>> results = meteor.compute(predictions=predictions, references=references) >>> print(round(results["meteor"], 4)) 0.6944 + + >>> meteor.compute(predictions=["red", "blue sky"], references=["red", "blue sky"], use_aggregator=False) + {'meteor': [0.5, 0.9375]} """ @@ -127,7 +131,7 @@ def _download_and_prepare(self, dl_manager): if NLTK_VERSION >= version.Version("3.6.6"): nltk.download("omw-1.4") - def _compute(self, predictions, references, alpha=0.9, beta=3, gamma=0.5): + def _compute(self, predictions, references, alpha=0.9, beta=3, gamma=0.5, use_aggregator=True): multiple_refs = isinstance(references[0], list) if NLTK_VERSION >= version.Version("3.6.5"): # the version of METEOR in NLTK version 3.6.5 and earlier expect tokenized inputs @@ -167,4 +171,4 @@ def _compute(self, predictions, references, alpha=0.9, beta=3, gamma=0.5): for ref, pred in zip(references, predictions) ] - return {"meteor": np.mean(scores)} + return {"meteor": np.mean(scores) if use_aggregator else scores}