summaryrefslogtreecommitdiff
path: root/kbest_bleu_oracles
diff options
context:
space:
mode:
authorPatrick Simianer <p@simianer.de>2014-02-04 15:59:57 +0100
committerPatrick Simianer <p@simianer.de>2014-02-04 15:59:57 +0100
commitaaca4353663e46ce46a64851dd8e21f5590f7c6c (patch)
tree37dace294654bd19e143721fd81c5ce26febc268 /kbest_bleu_oracles
parenta53f4a89d25766cbedf1d3a935346ef2b31a4f6a (diff)
kbest_bleu_oracles
Diffstat (limited to 'kbest_bleu_oracles')
-rwxr-xr-xkbest_bleu_oracles53
1 files changed, 53 insertions, 0 deletions
diff --git a/kbest_bleu_oracles b/kbest_bleu_oracles
new file mode 100755
index 0000000..1a41019
--- /dev/null
+++ b/kbest_bleu_oracles
@@ -0,0 +1,53 @@
+#!/usr/bin/env ruby
+
+require 'nlp_ruby'
+require 'trollop'
+
+
+def get_context kbest_lists, references, n
+ a = []
+ kbest_lists.each_index { |i|
+ a << BLEU::get_counts(kbest_lists[i][0].s, references[i], n, 1)
+ }
+ return a
+end
+
+def main
+ cfg = Trollop::options do
+ opt :kbest_lists, "kbest lists", :type => :string, :required => true
+ opt :references, "reference", :type => :string, :required => true
+ opt :n, "N for BLEU", :type => :int, :default => 4
+ opt :weight, "how much to weigh single translations", :type => :int, :default => 1
+ opt :debug, "debug mode", :type => :bool, :default => false
+ end
+ debug = cfg[:debug]
+ n = cfg[:n]
+ kbest_lists = read_kbest_lists cfg[:kbest_lists]
+ references = ReadFile.new(cfg[:references]).readlines_strip
+ context = get_context kbest_lists, references, n
+ kbest_lists.each_with_index { |kbest,j|
+ scores = []
+ max_score = -1.0/0
+ max_idx = -1
+ kbest.each_index { |i|
+ context_cp = context.dup
+ context_cp[j] = BLEU::get_counts kbest[i].s, references[j], n, cfg[:weight]
+ score = BLEU::hbleu(context_cp, n, debug)
+ scores << score
+ if score > max_score
+ max_score = score
+ max_idx = i
+ end
+ STDERR.write "#{i} #{kbest[i]}\t#{score}\n---\n" if debug
+ }
+ puts "#{references[j]}"
+ puts "BLEU=#{scores[0]} ||| #{kbest[0]}"
+ puts "BLEU=#{max_score} ||| #{kbest[max_idx]}"
+ puts
+ STDERR.write "\n" if debug
+ }
+end
+
+
+main
+