From 64d728e37e9c2aa9abf8c748d7eab6c4c58cb499 Mon Sep 17 00:00:00 2001 From: Amartya Sanyal Date: Fri, 14 Jul 2017 21:18:57 -0700 Subject: [PATCH] Some changes for Rouge-S Minor fix minor fix --- measure.lua | 7 ++++--- utils.lua | 5 ++--- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/measure.lua b/measure.lua index cdc36e1..ccc192f 100644 --- a/measure.lua +++ b/measure.lua @@ -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 @@ -77,10 +78,10 @@ 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 @@ -88,7 +89,7 @@ function nn.get_rougeS(cand, ref, beta, dskip) 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 diff --git a/utils.lua b/utils.lua index e473ca4..7a792ea 100644 --- a/utils.lua +++ b/utils.lua @@ -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