summaryrefslogtreecommitdiff
path: root/rescore/rerank.pl
diff options
context:
space:
mode:
authorChris Dyer <cdyer@cs.cmu.edu>2012-02-02 17:19:40 -0500
committerChris Dyer <cdyer@cs.cmu.edu>2012-02-02 17:19:40 -0500
commitf63027cecd0649b4d30e3f288e1311f9f27f1b5b (patch)
treefb2d6e643f513d579cbd89b146c3b01fb1a2dfd7 /rescore/rerank.pl
parentf58dcd65153967e1c0b2841ff07e94ad4ed0fe3d (diff)
remove some dead code to clean things up
Diffstat (limited to 'rescore/rerank.pl')
-rwxr-xr-xrescore/rerank.pl86
1 files changed, 0 insertions, 86 deletions
diff --git a/rescore/rerank.pl b/rescore/rerank.pl
deleted file mode 100755
index 4a0c5750..00000000
--- a/rescore/rerank.pl
+++ /dev/null
@@ -1,86 +0,0 @@
-#!/usr/bin/perl -w
-
-use strict;
-use utf8;
-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();
- exit(1);
-}
-
-open W, "<$weights_file" or die "Can't read $weights_file: $!";
-my %weights;
-while(<W>) {
- chomp;
- next if /^#/;
- next if /^\s*$/;
- my ($fname, $w) = split /\s+/;
- $weights{$fname} = $w;
-}
-close W;
-
-my $cur = undef;
-my %hyps = ();
-open HYP, "<$hyp_file" or die "Can't read $hyp_file: $!";
-while(<HYP>) {
- chomp;
- my ($id, $hyp, $feats) = split / \|\|\| /;
- unless (defined $cur) { $cur = $id; }
- if ($cur ne $id) {
- extract_1best($cur, \%hyps);
- $cur = $id;
- %hyps = ();
- }
- my @afeats = split /\s+/, $feats;
- my $tot = 0;
- for my $featpair (@afeats) {
- my ($fname,$fval) = split /=/, $featpair;
- my $weight = $weights{$fname};
- die "Unweighted feature '$fname'" unless defined $weight;
- $tot += ($weight * $fval);
- }
- $hyps{"$hyp ||| $feats"} = $tot;
-}
-extract_1best($cur, \%hyps) if defined $cur;
-close HYP;
-
-sub extract_1best {
- my ($id, $rh) = @_;
- my %hyps = %$rh;
- if ($kbest) {
- for my $hyp (sort { $hyps{$b} <=> $hyps{$a} } keys %hyps) {
- print "$id ||| $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";
- }
-}
-
-sub usage {
- print <<EOT;
-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
-}
-