diff options
-rwxr-xr-x | rescore/generate_zmert_params_from_weights.pl | 26 | ||||
-rwxr-xr-x | rescore/rerank.pl | 12 |
2 files changed, 32 insertions, 6 deletions
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(<HYP>) { 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(<HYP>) { } $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 <<EOT; -Usage: $0 -w weights.txt -h hyp.nbest.txt - Reranks n-best lists with new weights, extracting the new 1-best entries. +Usage: $0 -w weights.txt -h hyp.nbest.txt [--kbest] + Reranks n-best lists with new weights, extracting the new 1/k-best entries. EOT } |