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

run-me.sh « training-basics-spm - github.com/marian-nmt/marian-examples.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: 62da8dd257145091289c4d71dd59c9d53b89d8a4 (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
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
#!/bin/bash -v

MARIAN=../..

# set chosen gpus
GPUS=0
if [ $# -ne 0 ]
then
    GPUS=$@
fi
echo Using GPUs: $GPUS

if [ ! -e $MARIAN/build/marian ]
then
    echo "marian is not installed in $MARIAN/build, you need to compile the toolkit first"
    exit 1
fi

# get our fork of sacrebleu
git clone https://github.com/marian-nmt/sacreBLEU

if [ ! -e "data/corpus.ro" ]
then
    cd data

    # create dev set
    ../sacreBLEU/sacrebleu.py -t wmt16/dev -l ro-en --echo src > newsdev2016.ro
    ../sacreBLEU/sacrebleu.py -t wmt16/dev -l ro-en --echo ref > newsdev2016.en

    # create test set
    ../sacreBLEU/sacrebleu.py -t wmt16 -l ro-en --echo src > newstest2016.ro
    ../sacreBLEU/sacrebleu.py -t wmt16 -l ro-en --echo ref > newstest2016.en

    # get En-Ro training data for WMT16
    wget -nc http://www.statmt.org/europarl/v7/ro-en.tgz
    wget -nc http://opus.lingfil.uu.se/download.php?f=SETIMES2/en-ro.txt.zip -O SETIMES2.ro-en.txt.zip
    wget -nc http://data.statmt.org/rsennrich/wmt16_backtranslations/ro-en/corpus.bt.ro-en.en.gz
    wget -nc http://data.statmt.org/rsennrich/wmt16_backtranslations/ro-en/corpus.bt.ro-en.ro.gz

    # extract data
    tar -xf ro-en.tgz
    unzip SETIMES2.ro-en.txt.zip
    gzip -d corpus.bt.ro-en.en.gz corpus.bt.ro-en.ro.gz

    # create corpus files
    cat europarl-v7.ro-en.en SETIMES2.en-ro.en corpus.bt.ro-en.en > corpus.en
    cat europarl-v7.ro-en.ro SETIMES2.en-ro.ro corpus.bt.ro-en.ro > corpus.ro

    # clean
    rm ro-en.tgz SETIMES2.* corpus.bt.* europarl-*
    cd ..
fi

# create the model folder
mkdir -p model

# train model
if [ ! -e "model/model.npz.best-bleu-detok.npz" ]
then
    $MARIAN/build/marian \
        --devices $GPUS \
        --type s2s \
        --model model/model.npz \
        --train-sets data/corpus.ro data/corpus.en \
        --vocabs model/vocab.roen.spm model/vocab.roen.spm \
        --sentencepiece-options '--normalization_rule_tsv=data/norm_romanian.tsv' \
        --dim-vocabs 32000 32000 \
        --mini-batch-fit -w 5000 \
        --layer-normalization --tied-embeddings-all \
        --dropout-rnn 0.2 --dropout-src 0.1 --dropout-trg 0.1 \
        --early-stopping 5 --max-length 100 \
        --valid-freq 10000 --save-freq 10000 --disp-freq 1000 \
        --cost-type ce-mean-words --valid-metrics ce-mean-words bleu-detok \
        --valid-sets data/newsdev2016.ro data/newsdev2016.en \
        --log model/train.log --valid-log model/valid.log --tempdir model \
        --overwrite --keep-best \
        --seed 1111 --exponential-smoothing \
        --normalize=1 --beam-size=6 --quiet-translation
fi

# translate dev set
cat data/newsdev2016.ro \
    | $MARIAN/build/marian-decoder -c model/model.npz.best-bleu-detok.npz.decoder.yml -d $GPUS -b 6 -n1 \
      --mini-batch 64 --maxi-batch 10 --maxi-batch-sort src > data/newsdev2016.ro.output

# translate test set
cat data/newstest2016.ro \
    | $MARIAN/build/marian-decoder -c model/model.npz.best-bleu-detok.npz.decoder.yml -d $GPUS -b 6 -n1 \
      --mini-batch 64 --maxi-batch 10 --maxi-batch-sort src > data/newstest2016.ro.output

# calculate bleu scores on dev and test set
sacreBLEU/sacrebleu.py -t wmt16/dev -l ro-en < data/newsdev2016.ro.output
sacreBLEU/sacrebleu.py -t wmt16 -l ro-en < data/newstest2016.ro.output