Welcome to mirror list, hosted at ThFree Co, Russian Federation.

wrapper.pl « scripts - github.com/marian-nmt/marian.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: 83cd2527d41ed8ef45e6efd01bec388cc0a6165b (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
#!/usr/bin/perl

use strict;
use POSIX;

my $PID = $$;

my $MOSES = "/work/mosesdecoder/bin/moses";
my $RESCORER = "/work/amunn/build/bin/rescorer";
my $RESCORER_WRAPPER = "/work/amunn/scripts/rescore.pl";

my $NMT = "/work/wmt16/work/mjd.en-ru.penn/work.en-ru/nmt.ru-en";

my $MODELS = join(" ", map { "-m $NMT/$_" } qw(model.iter510000.npz model.iter540000.npz model.iter570000.npz));
my ($SVCB, $TVCB) = map { "$NMT/$_" } qw(vocab.ru vocab.en);
my $FEATURES = join(" ", map { "-f $_" } qw(N0 N1 N2));

for(my $i = 0; $i < @ARGV; $i++) {
  if($ARGV[$i] =~ /weight-overwrite/) {
    $ARGV[$i+1] = "'". $ARGV[$i+1] . "'";
  }
}

my $opts = join(" ", @ARGV);

my ($nbest) = $opts =~ /-n-best-list (run.*?.best100.out)/;

if($opts =~ /-show-weights/) {
    exec("$MOSES $opts");
}
else {
  $opts =~ /-input-file (\S+)/;
  my $input = $1;
  print STDERR "OPTS: $opts\n";
  execute("$MOSES $opts");
  execute("$RESCORER_WRAPPER -r $RESCORER $MODELS $FEATURES -s $SVCB -t $TVCB -n $nbest -i $input -w features.list > $nbest.temp");
  rename("$nbest.temp", $nbest);
}

sub execute {
    my $command = shift;
    logMessage("Executing:\t$command");
    my $ret = system($command);
    if($ret != 0) {
        logMessage("Command '$command' finished with return status $ret");
        logMessage("Aborting and killing parent process");
        kill(2, $PID);
        die;
    }
}

sub logMessage {
    my $message = shift;
    my $time = POSIX::strftime("%m/%d/%Y %H:%M:%S", localtime());
    my $log_message = $time."\t$message\n"; 
    print STDERR $log_message;
}