Update negbleurt.py
Browse files- negbleurt.py +3 -2
negbleurt.py
CHANGED
@@ -24,7 +24,7 @@ Examples:
|
|
24 |
>>> negBLEURT = evaluate.load('MiriUll/negbleurt')
|
25 |
>>> predictions = ["Ray Charles is a legend.", "Ray Charles isn’t legendary."]
|
26 |
>>> reference = "Ray Charles is legendary."
|
27 |
-
>>> results =
|
28 |
>>> print(results)
|
29 |
{'negBLERUT': [0.8409, 0.2601]}
|
30 |
"""
|
@@ -63,10 +63,11 @@ class NegBLEURT(evaluate.Metric):
|
|
63 |
):
|
64 |
single_ref = isinstance(references, str)
|
65 |
if single_ref:
|
|
|
66 |
references = [references] * len(predictions)
|
67 |
|
68 |
scores_negbleurt = []
|
69 |
-
for i in
|
70 |
tokenized = self.tokenizer(references[i:i+batch_size], candidates[i:i+batch_size], return_tensors='pt', padding=True, max_length=512, truncation=True)
|
71 |
scores_negbleurt += self.model(**tokenized).logits.flatten().tolist()
|
72 |
return {'negBLEURT': scores_negbleurt}
|
|
|
24 |
>>> negBLEURT = evaluate.load('MiriUll/negbleurt')
|
25 |
>>> predictions = ["Ray Charles is a legend.", "Ray Charles isn’t legendary."]
|
26 |
>>> reference = "Ray Charles is legendary."
|
27 |
+
>>> results = negBLEURT.compute(predictions=predictions, references=reference)
|
28 |
>>> print(results)
|
29 |
{'negBLERUT': [0.8409, 0.2601]}
|
30 |
"""
|
|
|
63 |
):
|
64 |
single_ref = isinstance(references, str)
|
65 |
if single_ref:
|
66 |
+
print("single reference")
|
67 |
references = [references] * len(predictions)
|
68 |
|
69 |
scores_negbleurt = []
|
70 |
+
for i in range(0, len(references), batch_size):
|
71 |
tokenized = self.tokenizer(references[i:i+batch_size], candidates[i:i+batch_size], return_tensors='pt', padding=True, max_length=512, truncation=True)
|
72 |
scores_negbleurt += self.model(**tokenized).logits.flatten().tolist()
|
73 |
return {'negBLEURT': scores_negbleurt}
|