-
Notifications
You must be signed in to change notification settings - Fork 17
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Amartya Sanyal
committed
Jul 13, 2017
1 parent
ae3d409
commit f871177
Showing
5 changed files
with
74 additions
and
74 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
function nn.get_bleu(cand, ref, n) | ||
n = n or 4 | ||
local smooth = 1 | ||
if type(cand) ~= 'table' then | ||
cand = cand:totable() | ||
end | ||
if type(ref) ~= 'table' then | ||
ref = ref:totable() | ||
end | ||
local res = nn.utils.get_ngram_prec(cand, ref, n) | ||
local brevPen = math.exp(1-math.max(1, #ref/#cand)) | ||
local correct = 0 | ||
local total = 0 | ||
local bleu = 1 | ||
for i = 1, n do | ||
if res[i][1] > 0 then | ||
if res[i][2] == 0 then | ||
smooth = smooth*0.5 | ||
res[i][2] = smooth | ||
end | ||
local prec = res[i][2]/res[i][1] | ||
bleu = bleu * prec | ||
end | ||
end | ||
bleu = bleu^(1/n) | ||
return bleu*brevPen | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters