Home

Awesome

XMUNMT

An open source Neural Machine Translation toolkit developed by the NLPLAB of Xiamen University.

Features

Tutorial

This tutorial describes how to train an NMT model on WMT17's EN-DE data using this repository.

Prerequisite

You must install TensorFlow (>=1.4.0) first to use this library.

Download Data

The preprocessed data can be found at here.

Data Preprocessing

  1. Byte Pair Encoding
python subword-nmt/learn_joint_bpe_and_vocab.py --input corpus.tc.en corpus.tc.de -s 32000 -o bpe32k --write-vocabulary vocab.en vocab.de
python subword-nmt/apply_bpe.py -c bpe32k --vocabulary vocab.en --vocabulary-threshold 50 < corpus.tc.en > corpus.bpe32k.en
python subword-nmt/apply_bpe.py -c bpe32k --vocabulary vocab.de --vocabulary-threshold 50 < corpus.tc.de > corpus.bpe32k.de
python subword-nmt/apply_bpe.py -c bpe32k --vocabulary vocab.en --vocabulary-threshold 50 < newstest2016.tc.en > newstest2016.bpe32k.en
python subword-nmt/apply_bpe.py -c bpe32k --vocabulary vocab.de --vocabulary-threshold 50 < newstest2016.tc.de > newstest2016.bpe32k.de
python subword-nmt/apply_bpe.py -c bpe32k --vocabulary vocab.en --vocabulary-threshold 50 < newstest2017.tc.en > newstest2017.bpe32k.en
  1. Environment Variables
PYTHONPATH=/PATH/TO/XMUNMT:$PYTHONPATH
  1. Build vocabulary
cat corpus.bpe32k.en corpus.bpe32k.de > corpus.bpe32k.all
python XMUNMT/xmunmt/scripts/build_vocab.py corpus.bpe32k.all vocab.shared32k.txt
  1. Shuffle corpus
python XMUNMT/xmunmt/scripts/shuffle_corpus.py --corpus corpus.bpe32k.en corpus.bpe32k.de --seed 1234

Training

python XMUNMT/xmunmt/bin/trainer.py
  --model rnnsearch
  --output train 
  --input corpus.bpe32k.en.shuf corpus.bpe32k.de.shuf
  --vocabulary vocab.shared32k.txt vocab.shared32k.txt
  --validation newstest2016.bpe32k.en
  --references newstest2016.bpe32k.de
  --parameters=device_list=[0],eval_steps=5000,train_steps=75000,
               learning_rate_decay=piecewise_constant,
               learning_rate_values=[5e-4,25e-5,125e-6],
               learning_rate_boundaries=[25000,50000]

Decoding

python XMUNMT/xmunmt/bin/translator.py
  --models rnnsearch
  --checkpoints train/eval
  --input newstest2017.bpe32k.en
  --output test.txt
  --vocabulary vocab.shared32k.txt vocab.shared32k.txt

Benchmark

The benchmark is performed on 1 GTX 1080Ti GPU with default parameters.

DatasetBLEUBLEU (cased)
WMT17 En-De22.8122.30
WMT17 De-En29.0127.69

Contact

This code is written by Zhixing Tan. If you have any problems, feel free to send an <a href="mailto:playinf@stu.xmu.edu.cn">email</a>.

LICENSE

BSD