diff options
Diffstat (limited to 'rescore')
-rwxr-xr-x | rescore/rerank.pl | 25 | ||||
-rwxr-xr-x | rescore/rescore_inv_model1.pl | 2 |
2 files changed, 18 insertions, 9 deletions
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(<HYP>) { 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 { diff --git a/rescore/rescore_inv_model1.pl b/rescore/rescore_inv_model1.pl index 3ac86c46..4fc3cfcc 100755 --- a/rescore/rescore_inv_model1.pl +++ b/rescore/rescore_inv_model1.pl @@ -116,7 +116,7 @@ sub m1_prob { } sub usage { - print STDERR "Usage: $0 -m model_file.txt -h hypothesis.nbest -s source.txt\n Adds the back-translation probability under Model 1\n"; + print STDERR "Usage: $0 -m model_file.txt -h hypothesis.nbest -s source.txt\n Adds the back-translation probability under Model 1\n Use training/model1 to generate the required parameter file\n"; } |