summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorredpony <redpony@ec762483-ff6d-05da-a07a-a48fb63a330f>2010-11-17 02:22:07 +0000
committerredpony <redpony@ec762483-ff6d-05da-a07a-a48fb63a330f>2010-11-17 02:22:07 +0000
commit51da1d896f0b941f506fd3c74f614bfd0c688d46 (patch)
tree19c6e8b75b29a2e167e12020c8cbe7af299efc5e
parent29ecb53257429d242d86b4814b795e5fef449785 (diff)
changes
git-svn-id: https://ws10smt.googlecode.com/svn/trunk@729 ec762483-ff6d-05da-a07a-a48fb63a330f
-rwxr-xr-xrescore/rerank.pl25
-rwxr-xr-xrescore/rescore_inv_model1.pl2
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";
}