Spaces:
Running
Running
Update Space (evaluate main: e4a27243)
Browse files- meteor.py +33 -10
- requirements.txt +1 -1
meteor.py
CHANGED
@@ -13,6 +13,8 @@
|
|
13 |
# limitations under the License.
|
14 |
""" METEOR metric. """
|
15 |
|
|
|
|
|
16 |
import datasets
|
17 |
import numpy as np
|
18 |
from datasets.config import importlib_metadata, version
|
@@ -82,13 +84,28 @@ Examples:
|
|
82 |
"""
|
83 |
|
84 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
85 |
@evaluate.utils.file_utils.add_start_docstrings(_DESCRIPTION, _KWARGS_DESCRIPTION)
|
86 |
class Meteor(evaluate.Metric):
|
87 |
-
|
|
|
|
|
|
|
|
|
88 |
return evaluate.MetricInfo(
|
89 |
description=_DESCRIPTION,
|
90 |
citation=_CITATION,
|
91 |
inputs_description=_KWARGS_DESCRIPTION,
|
|
|
92 |
features=[
|
93 |
datasets.Features(
|
94 |
{
|
@@ -119,7 +136,7 @@ class Meteor(evaluate.Metric):
|
|
119 |
if NLTK_VERSION >= version.Version("3.6.6"):
|
120 |
nltk.download("omw-1.4")
|
121 |
|
122 |
-
def _compute(self, predictions, references
|
123 |
multiple_refs = isinstance(references[0], list)
|
124 |
if NLTK_VERSION >= version.Version("3.6.5"):
|
125 |
# the version of METEOR in NLTK version 3.6.5 and earlier expect tokenized inputs
|
@@ -128,16 +145,20 @@ class Meteor(evaluate.Metric):
|
|
128 |
meteor_score.meteor_score(
|
129 |
[word_tokenize(ref) for ref in refs],
|
130 |
word_tokenize(pred),
|
131 |
-
alpha=alpha,
|
132 |
-
beta=beta,
|
133 |
-
gamma=gamma,
|
134 |
)
|
135 |
for refs, pred in zip(references, predictions)
|
136 |
]
|
137 |
else:
|
138 |
scores = [
|
139 |
meteor_score.single_meteor_score(
|
140 |
-
word_tokenize(ref),
|
|
|
|
|
|
|
|
|
141 |
)
|
142 |
for ref, pred in zip(references, predictions)
|
143 |
]
|
@@ -147,15 +168,17 @@ class Meteor(evaluate.Metric):
|
|
147 |
meteor_score.meteor_score(
|
148 |
[[word_tokenize(ref) for ref in group] for group in references][0],
|
149 |
word_tokenize(pred),
|
150 |
-
alpha=alpha,
|
151 |
-
beta=beta,
|
152 |
-
gamma=gamma,
|
153 |
)
|
154 |
for ref, pred in zip(references, predictions)
|
155 |
]
|
156 |
else:
|
157 |
scores = [
|
158 |
-
meteor_score.single_meteor_score(
|
|
|
|
|
159 |
for ref, pred in zip(references, predictions)
|
160 |
]
|
161 |
|
|
|
13 |
# limitations under the License.
|
14 |
""" METEOR metric. """
|
15 |
|
16 |
+
from dataclasses import dataclass
|
17 |
+
|
18 |
import datasets
|
19 |
import numpy as np
|
20 |
from datasets.config import importlib_metadata, version
|
|
|
84 |
"""
|
85 |
|
86 |
|
87 |
+
@dataclass
|
88 |
+
class MeteorConfig(evaluate.info.Config):
|
89 |
+
|
90 |
+
name: str = "default"
|
91 |
+
|
92 |
+
alpha: float = 0.9
|
93 |
+
beta: float = 3.0
|
94 |
+
gamma: float = 0.5
|
95 |
+
|
96 |
+
|
97 |
@evaluate.utils.file_utils.add_start_docstrings(_DESCRIPTION, _KWARGS_DESCRIPTION)
|
98 |
class Meteor(evaluate.Metric):
|
99 |
+
|
100 |
+
CONFIG_CLASS = MeteorConfig
|
101 |
+
ALLOWED_CONFIG_NAMES = ["default", "multilabel"]
|
102 |
+
|
103 |
+
def _info(self, config):
|
104 |
return evaluate.MetricInfo(
|
105 |
description=_DESCRIPTION,
|
106 |
citation=_CITATION,
|
107 |
inputs_description=_KWARGS_DESCRIPTION,
|
108 |
+
config=config,
|
109 |
features=[
|
110 |
datasets.Features(
|
111 |
{
|
|
|
136 |
if NLTK_VERSION >= version.Version("3.6.6"):
|
137 |
nltk.download("omw-1.4")
|
138 |
|
139 |
+
def _compute(self, predictions, references):
|
140 |
multiple_refs = isinstance(references[0], list)
|
141 |
if NLTK_VERSION >= version.Version("3.6.5"):
|
142 |
# the version of METEOR in NLTK version 3.6.5 and earlier expect tokenized inputs
|
|
|
145 |
meteor_score.meteor_score(
|
146 |
[word_tokenize(ref) for ref in refs],
|
147 |
word_tokenize(pred),
|
148 |
+
alpha=self.config.alpha,
|
149 |
+
beta=self.config.beta,
|
150 |
+
gamma=self.config.gamma,
|
151 |
)
|
152 |
for refs, pred in zip(references, predictions)
|
153 |
]
|
154 |
else:
|
155 |
scores = [
|
156 |
meteor_score.single_meteor_score(
|
157 |
+
word_tokenize(ref),
|
158 |
+
word_tokenize(pred),
|
159 |
+
alpha=self.config.alpha,
|
160 |
+
beta=self.config.beta,
|
161 |
+
gamma=self.config.gamma,
|
162 |
)
|
163 |
for ref, pred in zip(references, predictions)
|
164 |
]
|
|
|
168 |
meteor_score.meteor_score(
|
169 |
[[word_tokenize(ref) for ref in group] for group in references][0],
|
170 |
word_tokenize(pred),
|
171 |
+
alpha=self.config.alpha,
|
172 |
+
beta=self.config.beta,
|
173 |
+
gamma=self.config.gamma,
|
174 |
)
|
175 |
for ref, pred in zip(references, predictions)
|
176 |
]
|
177 |
else:
|
178 |
scores = [
|
179 |
+
meteor_score.single_meteor_score(
|
180 |
+
ref, pred, alpha=self.config.alpha, beta=self.config.beta, gamma=self.config.gamma
|
181 |
+
)
|
182 |
for ref, pred in zip(references, predictions)
|
183 |
]
|
184 |
|
requirements.txt
CHANGED
@@ -1,2 +1,2 @@
|
|
1 |
-
git+https://github.com/huggingface/evaluate@
|
2 |
nltk
|
|
|
1 |
+
git+https://github.com/huggingface/evaluate@e4a2724377909fe2aeb4357e3971e5a569673b39
|
2 |
nltk
|