From 2b1d7f881c19c4d4b5afae194e02d3300c7675d0 Mon Sep 17 00:00:00 2001 From: Patrick Simianer
Date: Tue, 5 Jul 2016 11:01:46 +0200 Subject: mv --- kbest-bleu-oracles | 51 +++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 51 insertions(+) create mode 100755 kbest-bleu-oracles (limited to 'kbest-bleu-oracles') diff --git a/kbest-bleu-oracles b/kbest-bleu-oracles new file mode 100755 index 0000000..a36c345 --- /dev/null +++ b/kbest-bleu-oracles @@ -0,0 +1,51 @@ +#!/usr/bin/env ruby + +require 'zipf' +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 + conf = 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 = conf[:debug] + n = conf[:n] + kbest_lists = read_kbest_lists conf[:kbest_lists] + references = ReadFile.readlines_strip conf[:references] + 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, conf[: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 + -- cgit v1.2.3