alvations commited on
Commit
36b4a23
1 Parent(s): fbd1de8

Added bleu prefix to return dict's key

Browse files

Sometimes when using `evaluate.combine()` it's unclear which sub-metrics, the keys are from, e.g. https://www.kaggle.com/code/alvations/huggingface-evaluate-for-mt-evaluations, being explicit would help. Also added the individual ngrams values in the results so that tensorboard picks it up properly.

Files changed (1) hide show
  1. bleu.py +15 -6
bleu.py CHANGED
@@ -123,11 +123,20 @@ class Bleu(evaluate.Metric):
123
  reference_corpus=references, translation_corpus=predictions, max_order=max_order, smooth=smooth
124
  )
125
  (bleu, precisions, bp, ratio, translation_length, reference_length) = score
126
- return {
 
127
  "bleu": bleu,
128
- "precisions": precisions,
129
- "brevity_penalty": bp,
130
- "length_ratio": ratio,
131
- "translation_length": translation_length,
132
- "reference_length": reference_length,
133
  }
 
 
 
 
 
 
 
 
 
123
  reference_corpus=references, translation_corpus=predictions, max_order=max_order, smooth=smooth
124
  )
125
  (bleu, precisions, bp, ratio, translation_length, reference_length) = score
126
+
127
+ results = {
128
  "bleu": bleu,
129
+ "bleu_precisions": precisions,
130
+ "bleu_brevity_penalty": bp,
131
+ "bleu_length_ratio": ratio,
132
+ "bleu_translation_length": translation_length,
133
+ "bleu_reference_length": reference_length,
134
  }
135
+
136
+ # Add explicit floats values for precisions,
137
+ # so that tensorboard scalars automatically picks it up.
138
+ for n, p in enumerate(precisions, 1):
139
+ results[f'bleu_{n}gram_precisions'] = p
140
+
141
+ return results
142
+