# OpenNMT: Open-Source Toolkit for Neural Machine Translation

OpenNMT offers an open-source neural machine translation toolkit that balances efficiency and readability

Guillaume Klein, Yoon Kim, Yuntian Deng, Jean Senellart, Alexander M. Rush · arXiv · 2017-1-10

- **Problem** Many industry NMT systems are closed, and many open alternatives were built as research code with little support for production users. Researchers wanting an open and usable toolkit to benchmark, learn from and extend NMT had no good option.
- **Method** OpenNMT keeps the translation core small and readable and moves optimizations into separate modules. It also reuses GPU memory by sharing buffers between network clones, found by walking the network graph before training.
- **Results** With the default model size, memory reuse saved 70% of GPU memory. On English-to-German at a 32k BPE setting, OpenNMT trained at 5254 tokens per second, compared to 3221 for Nematus.

## Why open NMT toolkits fall short

Many industry NMT systems are closed source and unlikely to be released under unrestricted licenses. Many open alternatives were built as research code, so they offer little support to production users. That leaves researchers who want to benchmark against, learn from and extend NMT without a toolkit that is both open and usable.

Nematus, from the University of Edinburgh, is the open option the authors call most promising. It offers high accuracy, many options and clear documentation, and the authors wanted to build on those strengths while adding documentation and functionality. The open question is whether a toolkit can be efficient enough for production and still serve as a shared base for research.

## A modular toolkit built around three aims

The central idea is to keep the translation core small and readable, and to move optimizations and new features into separate modules. Readability for non-experts is a stated goal, and tutorial documentation sits inside the code. Three aims shape the project: training and test efficiency, model modularity and readability, and research extensibility.

OpenNMT succeeds seq2seq-attn, which was developed at Harvard, and it was rewritten for efficiency and readability. Its base covers attention, gating, stacking, input feeding, regularization and beam search, which the authors consider necessary for state-of-the-art performance. The main version is written in Lua on Torch, and a PyTorch version by Adam Lerer of Facebook Research follows the same API.

The Lua version, with preprocessing, is roughly 4K lines, compared to over 100K lines for the Moses SMT framework including language modeling. These are sizes of different frameworks, so the comparison shows how small the NMT code is, not that the two offer the same features. A small codebase is the argument for why newcomers can understand the whole system.

## How the attention encoder-decoder learns to translate

The model treats translation as conditional language modeling, scoring a target sentence one word at a time given the source sentence. The probability of the whole target sentence is a product over target positions: \\\[ p(w\_{1:T}\\mid x)=\\prod\_{t=1}^{T} p(w\_t\\mid w\_{1:t-1},x;\\theta) \\\]

An encoder RNN turns each source word into a word vector and then into a sequence of hidden vectors h1 to hS. The decoder mixes its own recurrent state, built from the words already produced, with attention over those source vectors, and a softmax turns the result into a next-word distribution. Attention weights each source word by its expected contribution to the next prediction, so the source vectors don't all count equally.

Training fits all of these parameters end-to-end, so one loss drives the encoder, the attention and the decoder together. That loss is the negative log-likelihood of the training corpus, so minimizing it pushes the model to give reference translations high probability. Four practical additions improve this base model, and each one targets a specific weakness.

A gated RNN such as an LSTM or GRU helps the model learn long-term features, and translation usually calls for stacked RNNs with 2-16 layers at each time step. Input feeding passes the previous attention vector back into the input along with the predicted word, which the authors say helps translation. Beam search at test time keeps several hypothesis predictions alive at each step, and implementing these pieces correctly is hard.

## Shared buffers and multi-GPU training for faster training

Training time depends on batch size, and GPU memory limits how large a batch can be. Toolkits such as Torch often spend extra memory for speed and simpler declarations, and OpenNMT was meant to keep both. The external memory sharing system uses the known time-series control flow of NMT to let network clones share internal buffers.

Shareable buffers are found by walking the network graph before training starts. With the default model size, this memory reuse saved 70% of GPU memory. That saving was measured only for the default model size, so it doesn't show how the saving scales to other sizes.

In multi-GPU training, each GPU holds a replica of the master parameters and processes its own batches. In synchronous mode, the GPUs finish their batches, aggregate gradients into the master parameters and resynchronize before the next batch. In asynchronous mode each GPU adds its gradients to the master copy without waiting, and asynchronous SGD is known to converge faster (Dean et al., 2012).

With 8 GPUs, an epoch ran 6× faster, at the cost of a slight loss in training efficiency. When training to a similar loss, the total training time gave a 3.5× speed-up. The per-epoch and total figures measure different things, so they shouldn't be merged into one speed-up number.

## Separate decoders for different deployments

Training needs substantial code for fast back-propagation through time, while deployment needs only forward passes and a simpler beam search. OpenNMT provides three decoding paths: a batched CPU/GPU version for quickly translating large sets, a single-instance version for mobile devices, and a C version. The C version reads the network structure and uses the Eigen package for the linear algebra needed in decoding, which suits standard CPU production environments.

The batched version is the research path, since it lets a user add constraints on the feasible output set and mechanisms such as pointer networks and copy. The C path is faster than the Torch CPU path in all four batch and beam rows of that table, but the GPU path stays ahead at these settings. These runs used an Intel i7 with a GTX 1080.

## Changing inputs, outputs and attention as modules

Factored translation generates a word together with features such as case, so both the decoder input and the decoder output must change. In OpenNMT the input network and the output generator are separate, so factored translation only swaps in a feature-aware input network and a generator that makes several conditionally independent predictions.

The paper gives no accuracy numbers for this case, so the evidence here is about how the code is organized.

Global attention is the default, while local, sparse-max and hierarchical attention are alternatives that fit as modules. A structured attention method from the Harvard group uses graphical model inference and can replace standard attention through the Torch interface, although it is computationally complex.

An image-to-text system for mathematical OCR replaces the source RNN with a deep convolution over the image. Apart from preprocessing, that adaptation needed less than 500 lines of extra code. A speech-to-text system based on Chan et al. (2015) was also built by replacing the source encoder, and no accuracy numbers are given for either case study.

## EN→DE comparison with Nematus

Both systems use 2x500 RNNs with embedding size 300, 13 epochs, batch size 64 and beam size 5. The test is English-to-German on WMT15 data, scored on newstest2014 at a 50k vocabulary and at a 32k BPE setting. The benchmarks ran on an Intel i7-5930K CPU with one GTX 1080 GPU.

Because the 50k gap is smaller, the stronger accuracy evidence comes from the 32k setting.

At 32k, OpenNMT trained at 5254 tokens per second, compared to 3221 for Nematus, and translated at 457 tokens per second, compared to 252. These speeds come from the benchmark hardware the authors describe, for the Nematus revisions named in the comparison footnote, 907824 and 75c6ab1.

Under these settings OpenNMT scored higher BLEU in both vocabulary settings and was faster in both training and translation. The evidence covers one language pair, one test set and one BLEU value per setting, with no confidence intervals.

## Multilingual and other task results

One model was trained to translate among French, Spanish, Portuguese, Italian and Romanian. Its 4M training sentences come from Europarl, GlobalVoices and Ted, and each sentence has a translation in the other four languages. The text is tokenized with shared 32k BPE.

Table 2 compares this one model with 20 separately trained single-pair models. Each entry shows the BLEU of the multilingual model and its gain over the pair's own model, and the gains range from +3.3 to +10.4. The authors read the consistent gains as evidence that each pair benefits from training jointly with the others.

OpenNMT replicated the sentence summarization results of Chopra et al. (2016) on Gigaword and got a ROUGE-1 score of 33.13. This number replicates that prior work rather than giving a head-to-head comparison in the same setup. The OpenSubtitles model was trained on 14 million sentences and gave a perplexity described as comparable to that of the prior work of Vinyals and Le.

## Limitations

The head-to-head accuracy and speed comparison covers only Nematus, only English-to-German, and one hardware setup. The memory saving was measured only at the default model size. The multi-GPU speed-ups come from 8 GPUs and were measured per epoch and to a similar loss.

The sentence summarization result has no same-setup baseline in the paper, and the OpenSubtitles model has no perplexity value. The factored, structured attention and speech case studies report no accuracy numbers. The authors expect performance and memory usage to improve with further development.

The code-size comparison sets a toolkit against an SMT framework, so it doesn't test equal functionality.

## Paper info

- **Authors**: Guillaume Klein, Yoon Kim, Yuntian Deng, Jean Senellart, Alexander M. Rush
- **Venue**: arXiv · Preprint
- **First published**: 2017-1-10
- **Added**: 2026-11-12
- **Updated**: 2017-3-6
- **Version**: v2
- **arXiv**: 1701.02810
- **Category**: cs.CL · cs.AI · cs.NE
- **Original paper terms**: [arXiv non-exclusive 1.0](https://arxiv.org/licenses/nonexclusive-distrib/1.0/)
- **What we show**: Paper info and commentary

[Original paper ↗](https://arxiv.org/abs/1701.02810v2) · [PDF ↗](https://arxiv.org/pdf/1701.02810v2)

AI commentary is a separate explanation from the original paper and may contain errors. The original paper and figures follow each source's terms of use and any rights noted separately.

## Quote from the paper

Guillaume Klein, Yoon Kim, Yuntian Deng, Jean Senellart, Alexander M. Rush (2017). OpenNMT: Open-Source Toolkit for Neural Machine Translation. arXiv:1701.02810v2. https://arxiv.org/abs/1701.02810v2

**BibTeX**

```
@misc{klein2017opennmt,
  title = {{OpenNMT: Open-Source Toolkit for Neural Machine Translation}},
  author = {Guillaume Klein and Yoon Kim and Yuntian Deng and Jean Senellart and Alexander M. Rush},
  year = {2017},
  eprint = {1701.02810},
  archivePrefix = {arXiv},
  url = {https://arxiv.org/abs/1701.02810v2}
}
```

## Other paper commentary

- [FEVER: a large-scale dataset for Fact Extraction and VERification](https://refivu.com/en/papers/59763d9c-0c11-477a-89ee-abea10ff28a0-fever-a-large-scale-dataset-for-fact-extraction.md)
- [Google's Multilingual Neural Machine Translation System: Enabling Zero-Shot Translation](https://refivu.com/en/papers/0924ecf7-d413-4972-9e1d-36ae4961169c-google-s-multilingual-neural-machine-translation-system.md)
- [Text Summarization with Pretrained Encoders](https://refivu.com/en/papers/7b8e7251-bfcc-4cab-9359-040ecd948516-text-summarization-with-pretrained-encoders.md)
- [SpanBERT: Improving Pre-training by Representing and Predicting Spans](https://refivu.com/en/papers/11f04ed9-a517-4d5d-a835-58a3e13f7118-spanbert-improving-pre-training-by-representing-and.md)
- [Named Entity Recognition with Bidirectional LSTM-CNNs](https://refivu.com/en/papers/454922d0-d836-4e69-a3cd-d40cf940d456-named-entity-recognition-with-bidirectional-lstm-cnns.md)
- [Man is to Computer Programmer as Woman is to Homemaker? Debiasing Word Embeddings](https://refivu.com/en/papers/54f76c5c-e7e0-4849-8c34-62d4d7e29119-man-is-to-computer-programmer-as-woman-is.md)
- [Instruction-Following Evaluation for Large Language Models](https://refivu.com/en/papers/87d7b3e4-5def-4a0c-ac6d-4f0204c38402-instruction-following-evaluation-for-large-language-models.md)
- [Neural Architecture Search: A Survey](https://refivu.com/en/papers/b954b27d-f3d7-4513-8986-c9a0dfb01e6e-neural-architecture-search-a-survey.md)
- [NTU RGB+D 120: A Large-Scale Benchmark for 3D Human Activity Understanding](https://refivu.com/en/papers/3fe61b53-c129-49a6-9839-f52dcd0e5d8d-ntu-rgb-d-120-a-large-scale-benchmark.md)
- [Imbalanced-learn: A Python Toolbox to Tackle the Curse of Imbalanced Datasets in Machine Learning](https://refivu.com/en/papers/fddce09d-7fcc-4378-9b7f-d421fd3b3e85-imbalanced-learn-a-python-toolbox-to-tackle-the.md)
- [Learning Structured Sparsity in Deep Neural Networks](https://refivu.com/en/papers/904b80d6-c19c-420d-861d-be919e5725b1-learning-structured-sparsity-in-deep-neural-networks.md)
- [ThiNet: A Filter Level Pruning Method for Deep Neural Network Compression](https://refivu.com/en/papers/13501147-4289-4a98-981e-919e37e87fc7-thinet-a-filter-level-pruning-method-for-deep.md)

## Terms in this paper

- [perplexity](https://refivu.com/en/terms/2b204e513801-perplexity)
- [BLEU](https://refivu.com/en/terms/42cd9b97719e-bleu)
- [beam search](https://refivu.com/en/terms/3e449f8f713b-beam-search)
- [newstest2014](https://refivu.com/en/terms/4ef4de9dc349-newstest2014)
- [Byte Pair Encoding](https://refivu.com/en/terms/fa8474289452-byte-pair-encoding)
- [Neural Machine Translation](https://refivu.com/en/terms/17d91eb90f6d-neural-machine-translation)
- [ROUGE-1](https://refivu.com/en/terms/5d5306875daf-rouge-1)
- [Gigaword](https://refivu.com/en/terms/7c9b16ee9919-gigaword)
- [sentence summarization](https://refivu.com/en/terms/8b02a321d7a9-sentence-summarization)

---

AI-written text can contain mistakes. [Refivu](https://refivu.com/en/papers/d158ab7b-d0c6-4ffd-a069-53d34c28b7eb-opennmt-open-source-toolkit-for-neural-machine-translation)
