Skip to content

Commit

Permalink
Some changes for Rouge-S
Browse files Browse the repository at this point in the history
Minor fix

minor fix
  • Loading branch information
Amartya Sanyal committed Jul 15, 2017
1 parent def0758 commit 64d728e
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 6 deletions.
7 changes: 4 additions & 3 deletions measure.lua
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@ function nn.get_rougeN(cand, ref, n, weight)
end

function nn.get_rougeS(cand, ref, beta, dskip)
local eps = 0.00000001
local beta = beta or 1
beta = beta * beta

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

for bigram, freq in pairs(ref_skip_bigrams) do
local actual
if cand_skip_bigrams[bigram] == nil then
if cand_skip_bigrams[tostring(bigram)] == nil then
actual = 0
else
actual = cand_skip_bigrams[bigram]
actual = cand_skip_bigrams[tostring(bigram)]
end
correct = correct + math.min(actual, freq)
end
local total_skip_bigrams_ref = (dskip - 1)*(2 * #ref - dskip)/2
local total_skip_bigrams_cand = (dskip - 1)*(2 * #cand - dskip)/2
local rskip2 = correct/total_skip_bigrams_cand
local pskip2 = correct/total_skip_bigrams_ref
local rouge = (1 + beta)*rskip2*pskip2/(rskip2 + beta*pskip2)
local rouge = (1 + beta)*rskip2*pskip2/(rskip2 + beta*pskip2 + eps)
return rouge
end

5 changes: 2 additions & 3 deletions utils.lua
Original file line number Diff line number Diff line change
Expand Up @@ -313,12 +313,11 @@ end

function nn.utils.get_skip_bigrams(sent, ref, count, dskip)
local skip_bigrams = {}
ref = ref or sent
for beg = 1, #sent do
if ref[sent[beg]] then
if ref[tostring(sent[beg])] then
local temp_token = sent[beg]
for last= beg+1, math.min(beg + dskip-1, #sent) do
if ref[sent[last]] then
if ref[tostring(sent[last])] then
skip_bigram = temp_token..sent[last]
if not count then
skip_bigrams[skip_bigram] = 1
Expand Down

0 comments on commit 64d728e

Please sign in to comment.