diff options
author | redpony <redpony@ec762483-ff6d-05da-a07a-a48fb63a330f> | 2010-11-17 02:22:07 +0000 |
---|---|---|
committer | redpony <redpony@ec762483-ff6d-05da-a07a-a48fb63a330f> | 2010-11-17 02:22:07 +0000 |
commit | 6cc55d924d704641db7aa110ac1faa47de870eb5 (patch) | |
tree | c772588f93675d15272ccd5c700e40d94a92e552 /rescore | |
parent | 84c2e539c5713cc9ed59942f22d73f3c40152d19 (diff) |
changes
git-svn-id: https://ws10smt.googlecode.com/svn/trunk@729 ec762483-ff6d-05da-a07a-a48fb63a330f
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"; } |