fix BLEU for empty output

This commit is contained in:
Filip Gralinski 2017-10-04 21:56:17 +02:00 committed by Filip Gralinski
parent f289cafc03
commit c10f3579c6
5 changed files with 12 additions and 0 deletions

View File

@ -226,6 +226,7 @@ gevalCore' BLEU _ = gevalCoreWithoutInput (Prelude.map Prelude.words . DLS.split
bleuFuse (a1, a2, a3, a4, a5, a6, a7, a8, a9) (b1, b2, b3, b4, b5, b6, b7, b8, b9) = (a1+b1, a2+b2, a3+b3, a4+b4, a5+b5, a6+b6, a7+b7, a8+b8, a9+b9)
brevityPenalty c r
| c >= r = 1.0
| c == 0 && r > 0 = 0.0
| otherwise = exp (1.0 - (r /. c))
gevalCore' Accuracy _ = gevalCoreWithoutInput strip strip hitOrMiss averageC id

View File

@ -48,6 +48,8 @@ main = hspec $ do
runGEvalTest "bleu-complex" `shouldReturnAlmost` 0.6211
it "perfect translation" $
runGEvalTest "bleu-perfect" `shouldReturnAlmost` 1.0000
it "empty translation" $
runGEvalTest "bleu-empty" `shouldReturnAlmost` 0.0000
describe "Accuracy" $ do
it "simple example" $
runGEvalTest "accuracy-simple" `shouldReturnAlmost` 0.6

View File

@ -0,0 +1,4 @@

View File

@ -0,0 +1 @@
--metric BLEU

View File

@ -0,0 +1,4 @@
Litwo, Ojczyzno moja! ty jesteś jak zdrowie;
Ile cię trzeba cenić, ten tylko się dowie,
Kto cię stracił. Dziś piękność twą w całej ozdobie
Widzę i opisuję, bo tęsknię po tobie.
1 Litwo, Ojczyzno moja! ty jesteś jak zdrowie;
2 Ile cię trzeba cenić, ten tylko się dowie,
3 Kto cię stracił. Dziś piękność twą w całej ozdobie
4 Widzę i opisuję, bo tęsknię po tobie.