From 51da1d896f0b941f506fd3c74f614bfd0c688d46 Mon Sep 17 00:00:00 2001 From: redpony Date: Wed, 17 Nov 2010 02:22:07 +0000 Subject: changes git-svn-id: https://ws10smt.googlecode.com/svn/trunk@729 ec762483-ff6d-05da-a07a-a48fb63a330f --- rescore/rerank.pl | 25 +++++++++++++++++-------- 1 file changed, 17 insertions(+), 8 deletions(-) (limited to 'rescore/rerank.pl') diff --git a/rescore/rerank.pl b/rescore/rerank.pl index ce7a67bd..296ae6d5 100755 --- a/rescore/rerank.pl +++ b/rescore/rerank.pl @@ -7,11 +7,13 @@ use Getopt::Long; my $weights_file; my $hyp_file; my $help; +my $kbest; # flag to extract reranked list Getopt::Long::Configure("no_auto_abbrev"); if (GetOptions( "weights_file|w=s" => \$weights_file, "hypothesis_file|h=s" => \$hyp_file, + "kbest" => \$kbest, "help" => \$help, ) == 0 || @ARGV!=0 || $help || !$weights_file || !$hyp_file) { usage(); @@ -49,7 +51,7 @@ while() { die "Unweighted feature '$fname'" unless defined $weight; $tot += ($weight * $fval); } - $hyps{$hyp} = $tot; + $hyps{"$hyp ||| $feats"} = $tot; } extract_1best(\%hyps) if defined $cur; close HYP; @@ -57,15 +59,22 @@ close HYP; sub extract_1best { my $rh = shift; my %hyps = %$rh; - my $best_score = undef; - my $best_hyp = undef; - for my $hyp (keys %hyps) { - if (!defined $best_score || $hyps{$hyp} > $best_score) { - $best_score = $hyps{$hyp}; - $best_hyp = $hyp; + if ($kbest) { + for my $hyp (sort { $hyps{$b} <=> $hyps{$a} } keys %hyps) { + print "$hyp\n"; } + } else { + my $best_score = undef; + my $best_hyp = undef; + for my $hyp (keys %hyps) { + if (!defined $best_score || $hyps{$hyp} > $best_score) { + $best_score = $hyps{$hyp}; + $best_hyp = $hyp; + } + } + $best_hyp =~ s/ \|\|\|.*$//; + print "$best_hyp\n"; } - print "$best_hyp\n"; } sub usage { -- cgit v1.2.3