mean and stdev
Browse files
gleu.py
CHANGED
@@ -18,6 +18,7 @@ import datasets
|
|
18 |
from collections import Counter
|
19 |
from math import log, exp
|
20 |
from random import seed, randint
|
|
|
21 |
|
22 |
|
23 |
# TODO: Add BibTeX citation
|
@@ -49,7 +50,8 @@ Args:
|
|
49 |
references: Reference for each prediction. Each reference should be a string with tokens separated by spaces.
|
50 |
predictions: list of predictions to score. Each prediction should be a string with tokens separated by spaces.
|
51 |
Returns:
|
52 |
-
|
|
|
53 |
|
54 |
Examples:
|
55 |
|
@@ -57,15 +59,15 @@ Examples:
|
|
57 |
>>> references=["We may in actual fact be communicating with a hoax Facebook acccount of a cyberfriend , which we assume to be real but in reality , it is a fake account ."]
|
58 |
>>> results = my_new_module.compute(references=references, predictions=["We may of actual fact communicating with a hoax Facebook acccount of a cyber friend , which we assumed to be real but in reality , it is a fake account ."])
|
59 |
>>> print(results)
|
60 |
-
{'
|
61 |
|
62 |
>>> results = my_new_module.compute(references=references, predictions=["We may be in actual fact communicating with a hoax Facebook acccount of a cyber friend , we assume to be real but in reality , it is a fake account ."])
|
63 |
>>> print(results)
|
64 |
-
{'
|
65 |
|
66 |
>>> results = my_new_module.compute(references=references, predictions=["We may in actual fact communicating with a hoax Facebook account of a cyber friend , which we assume to be real but in reality , it is a fake accounts ."])
|
67 |
>>> print(results)
|
68 |
-
{'
|
69 |
|
70 |
"""
|
71 |
|
@@ -239,6 +241,7 @@ class gleu(evaluate.Metric):
|
|
239 |
|
240 |
iter_stats[j] = [sum(scores) for scores in zip(iter_stats[j], this_stats)]
|
241 |
|
242 |
-
|
243 |
-
|
244 |
-
|
|
|
|
18 |
from collections import Counter
|
19 |
from math import log, exp
|
20 |
from random import seed, randint
|
21 |
+
from numpy import mean, std, round
|
22 |
|
23 |
|
24 |
# TODO: Add BibTeX citation
|
|
|
50 |
references: Reference for each prediction. Each reference should be a string with tokens separated by spaces.
|
51 |
predictions: list of predictions to score. Each prediction should be a string with tokens separated by spaces.
|
52 |
Returns:
|
53 |
+
mean_gleu_score: Average gleu_score over all predictions.
|
54 |
+
SD: standard deviation
|
55 |
|
56 |
Examples:
|
57 |
|
|
|
59 |
>>> references=["We may in actual fact be communicating with a hoax Facebook acccount of a cyberfriend , which we assume to be real but in reality , it is a fake account ."]
|
60 |
>>> results = my_new_module.compute(references=references, predictions=["We may of actual fact communicating with a hoax Facebook acccount of a cyber friend , which we assumed to be real but in reality , it is a fake account ."])
|
61 |
>>> print(results)
|
62 |
+
{'mean_gleu_score': 0.6}
|
63 |
|
64 |
>>> results = my_new_module.compute(references=references, predictions=["We may be in actual fact communicating with a hoax Facebook acccount of a cyber friend , we assume to be real but in reality , it is a fake account ."])
|
65 |
>>> print(results)
|
66 |
+
{'mean_gleu_score': 0.62}
|
67 |
|
68 |
>>> results = my_new_module.compute(references=references, predictions=["We may in actual fact communicating with a hoax Facebook account of a cyber friend , which we assume to be real but in reality , it is a fake accounts ."])
|
69 |
>>> print(results)
|
70 |
+
{'mean_gleu_score': 0.64}
|
71 |
|
72 |
"""
|
73 |
|
|
|
241 |
|
242 |
iter_stats[j] = [sum(scores) for scores in zip(iter_stats[j], this_stats)]
|
243 |
|
244 |
+
sent_scores = [gleu_calculator.compute_gleu(stats) for stats in iter_stats]
|
245 |
+
mean_score = round(mean(sent_scores),2)
|
246 |
+
std_score = round(std(sent_scores),2)
|
247 |
+
return {"mean_gleu_score": mean_score, 'SD': std_score}
|