From 69e918e3e090d3fc28864d0eb77d521f6682a593 Mon Sep 17 00:00:00 2001 From: redpony Date: Wed, 17 Nov 2010 02:52:04 +0000 Subject: zmert support git-svn-id: https://ws10smt.googlecode.com/svn/trunk@730 ec762483-ff6d-05da-a07a-a48fb63a330f --- rescore/generate_zmert_params_from_weights.pl | 26 ++++++++++++++++++++++++++ rescore/rerank.pl | 12 ++++++------ 2 files changed, 32 insertions(+), 6 deletions(-) create mode 100755 rescore/generate_zmert_params_from_weights.pl diff --git a/rescore/generate_zmert_params_from_weights.pl b/rescore/generate_zmert_params_from_weights.pl new file mode 100755 index 00000000..a9287896 --- /dev/null +++ b/rescore/generate_zmert_params_from_weights.pl @@ -0,0 +1,26 @@ +#!/usr/bin/perl -w + +my %defaults; +$defaults{'LanguageModel'} = "Opt\t0\t10\t0\t2.5"; +$defaults{'EgivenF'} = "Opt\t-5\t0.5\t-3\t0.5"; +$defaults{'LexEGivenF'} = "Opt\t-5\t0.5\t-3\t0.5"; +$defaults{'LexFGivenE'} = "Opt\t-5\t0.5\t-3\t0.5"; +$defaults{'PassThrough'} = "Opt\t-Inf\t+Inf\t-10\t0"; +$defaults{'WordPenalty'} = "Opt\t-Inf\t2\t-5\t0"; +my $DEFAULT = "Opt\t-Inf\t+Inf\t-1\t+1"; + +while(<>) { + next if /^#/; + chomp; + next if /^\s*$/; + s/^\s+//; + s/\s+$//; + my ($a,$b) = split /\s+/; + next unless ($a && $b); + my $line = $DEFAULT; + if ($defaults{$a}) { $line = $defaults{$a}; } + print "$a\t|||\t$b\t$line\n"; +} + +print "normalization = none\n"; + diff --git a/rescore/rerank.pl b/rescore/rerank.pl index 296ae6d5..4a0c5750 100755 --- a/rescore/rerank.pl +++ b/rescore/rerank.pl @@ -39,7 +39,7 @@ while() { my ($id, $hyp, $feats) = split / \|\|\| /; unless (defined $cur) { $cur = $id; } if ($cur ne $id) { - extract_1best(\%hyps); + extract_1best($cur, \%hyps); $cur = $id; %hyps = (); } @@ -53,15 +53,15 @@ while() { } $hyps{"$hyp ||| $feats"} = $tot; } -extract_1best(\%hyps) if defined $cur; +extract_1best($cur, \%hyps) if defined $cur; close HYP; sub extract_1best { - my $rh = shift; + my ($id, $rh) = @_; my %hyps = %$rh; if ($kbest) { for my $hyp (sort { $hyps{$b} <=> $hyps{$a} } keys %hyps) { - print "$hyp\n"; + print "$id ||| $hyp\n"; } } else { my $best_score = undef; @@ -79,8 +79,8 @@ sub extract_1best { sub usage { print <