Skip to content

Commit 64d728e

Browse files
author
Amartya Sanyal
committed
Some changes for Rouge-S
Minor fix minor fix
1 parent def0758 commit 64d728e

File tree

2 files changed

+6
-6
lines changed

2 files changed

+6
-6
lines changed

measure.lua

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,7 @@ function nn.get_rougeN(cand, ref, n, weight)
5757
end
5858

5959
function nn.get_rougeS(cand, ref, beta, dskip)
60+
local eps = 0.00000001
6061
local beta = beta or 1
6162
beta = beta * beta
6263

@@ -77,18 +78,18 @@ function nn.get_rougeS(cand, ref, beta, dskip)
7778

7879
for bigram, freq in pairs(ref_skip_bigrams) do
7980
local actual
80-
if cand_skip_bigrams[bigram] == nil then
81+
if cand_skip_bigrams[tostring(bigram)] == nil then
8182
actual = 0
8283
else
83-
actual = cand_skip_bigrams[bigram]
84+
actual = cand_skip_bigrams[tostring(bigram)]
8485
end
8586
correct = correct + math.min(actual, freq)
8687
end
8788
local total_skip_bigrams_ref = (dskip - 1)*(2 * #ref - dskip)/2
8889
local total_skip_bigrams_cand = (dskip - 1)*(2 * #cand - dskip)/2
8990
local rskip2 = correct/total_skip_bigrams_cand
9091
local pskip2 = correct/total_skip_bigrams_ref
91-
local rouge = (1 + beta)*rskip2*pskip2/(rskip2 + beta*pskip2)
92+
local rouge = (1 + beta)*rskip2*pskip2/(rskip2 + beta*pskip2 + eps)
9293
return rouge
9394
end
9495

utils.lua

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -313,12 +313,11 @@ end
313313

314314
function nn.utils.get_skip_bigrams(sent, ref, count, dskip)
315315
local skip_bigrams = {}
316-
ref = ref or sent
317316
for beg = 1, #sent do
318-
if ref[sent[beg]] then
317+
if ref[tostring(sent[beg])] then
319318
local temp_token = sent[beg]
320319
for last= beg+1, math.min(beg + dskip-1, #sent) do
321-
if ref[sent[last]] then
320+
if ref[tostring(sent[last])] then
322321
skip_bigram = temp_token..sent[last]
323322
if not count then
324323
skip_bigrams[skip_bigram] = 1

0 commit comments

Comments
 (0)