This is a work-in-progress implementation of Dual Learning for Machine Translation by He et al. published in NIPS 2016 (, It was developed in part by participants at the 3rd Machine Translation Marathon in the Americas (


This code is based on Nematus ( - please ensure you can run Nematus before proceeding.

The default language model is KenLM. You need both kenlm and the python wrapper (pip install

You need a version of python with

I used anaconda to install Theano and contextlib2.

Theano should be compiled for a GPU. Tested with CUDA v ?? and cuDNN 5.1, but probably best to use a newer version.


  1. Clone the repo
  2. Modify nematus/
    1. python_loc : The location of the python executable (2.7)
    2. cuda_loc : CUDA home (/usr/local/cuda)
    3. KENLM_PATH : Location of KenLM install (exclude bin from the path, included with moses, if you have moses installed, simply point to your moses dir)
    4. wmt16_systems_dir : Download this and point to the download location (wget -r --cut-dirs=2 -e robots=off -nH -np -R index.html*\_systems/ )
  3. Install the kenlm python wrapper : pip install --user
  4. Install other stuff : pip install --user contextlib2 Pyro4

Test Data:

Various tests/examples depend on Rico's wmt16 trained systems. Create a directory for the data, then cd into it and run the one of the following commands:

  1. Command for just en-de,de-en systems (required):
    • wget -r --cut-dirs=2 -e robots=off -nH -np -R index.html*
    • wget -r --cut-dirs=2 -e robots=off -nH -np -R index.html*
  2. If you wanted all of the language pairs (optional):
    • wget -r --cut-dirs=1 -e robots=off -nH -np -R index.html*


There are a number of files that need configuration.

An attempt was made to put all configuration items in nematus/ - put paths to your python, CUDA, etc here.

At the moment, configuring the training script requires changing values in nematus/ - put paths to your data, initialized Nematus models, and trained language models here.

The language model required here is a kenlm model with a small wrapper around it.

Testing the build:

./ (THIS WILL FAIL - data paths are all broken)

Running the code:


Originator Reference Number: RH-17-117200 Case Reviewer: Brian Brackens Case Number: 88ABW-2017-3032 The material was assigned a clearance of CLEARED on 20 Jun 2017.

This software and any accompanying documentation is released "as is."
The U.S. government makes no warranty of any kind, express or implied, concerning this software and any accompanying documentation, including, without limitation, any warranties of merchantability or fitness for a particular purpose. In no event will the U.S. government be liable for any damages, including any lost profits, lost savings or other incidental or consequential damages arising out of the use, or inability to use, this software or any accompanying documentation, even if informed in advance of the possibility of such damages.