Added bleu prefix to return dict's key

#3
by alvations - opened
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
+