All Projects → dreamgonfly → transformer-pytorch

dreamgonfly / transformer-pytorch

Licence: MIT License
A PyTorch implementation of Transformer in "Attention is All You Need"

Programming Languages

python
139335 projects - #7 most used programming language

Projects that are alternatives of or similar to transformer-pytorch

SequenceToSequence
A seq2seq with attention dialogue/MT model implemented by TensorFlow.
Stars: ✭ 11 (-85.71%)
Mutual labels:  machine-translation
Machine-Translation-v2
英中机器文本翻译
Stars: ✭ 48 (-37.66%)
Mutual labels:  machine-translation
Video-guided-Machine-Translation
Starter code for the VMT task and challenge
Stars: ✭ 45 (-41.56%)
Mutual labels:  machine-translation
urbans
A tool for translating text from source grammar to target grammar (context-free) with corresponding dictionary.
Stars: ✭ 19 (-75.32%)
Mutual labels:  machine-translation
masakhane-web
Masakhane Web is a translation web application for solely African Languages.
Stars: ✭ 27 (-64.94%)
Mutual labels:  machine-translation
NiuTrans.NMT
A Fast Neural Machine Translation System. It is developed in C++ and resorts to NiuTensor for fast tensor APIs.
Stars: ✭ 112 (+45.45%)
Mutual labels:  machine-translation
MetricMT
The official code repository for MetricMT - a reward optimization method for NMT with learned metrics
Stars: ✭ 23 (-70.13%)
Mutual labels:  machine-translation
apertium-html-tools
Web application providing a fully localised interface for text/website/document translation, analysis and generation powered by Apertium.
Stars: ✭ 36 (-53.25%)
Mutual labels:  machine-translation
dynmt-py
Neural machine translation implementation using dynet's python bindings
Stars: ✭ 17 (-77.92%)
Mutual labels:  machine-translation
mtdata
A tool that locates, downloads, and extracts machine translation corpora
Stars: ✭ 95 (+23.38%)
Mutual labels:  machine-translation
BSD
The Business Scene Dialogue corpus
Stars: ✭ 51 (-33.77%)
Mutual labels:  machine-translation
parallel-corpora-tools
Tools for filtering and cleaning parallel and monolingual corpora for machine translation and other natural language processing tasks.
Stars: ✭ 35 (-54.55%)
Mutual labels:  machine-translation
Deep-NLP-Resources
Curated list of all NLP Resources
Stars: ✭ 65 (-15.58%)
Mutual labels:  machine-translation
inmt
Interactive Neural Machine Translation tool
Stars: ✭ 44 (-42.86%)
Mutual labels:  machine-translation
ilmulti
Tooling to play around with multilingual machine translation for Indian Languages.
Stars: ✭ 19 (-75.32%)
Mutual labels:  machine-translation
rtg
Reader Translator Generator - NMT toolkit based on pytorch
Stars: ✭ 26 (-66.23%)
Mutual labels:  machine-translation
deepl-rb
A simple ruby gem for the DeepL API
Stars: ✭ 38 (-50.65%)
Mutual labels:  machine-translation
Natural-Language-Processing
Contains various architectures and novel paper implementations for Natural Language Processing tasks like Sequence Modelling and Neural Machine Translation.
Stars: ✭ 48 (-37.66%)
Mutual labels:  machine-translation
NLP Toolkit
Library of state-of-the-art models (PyTorch) for NLP tasks
Stars: ✭ 92 (+19.48%)
Mutual labels:  machine-translation
omegat-tencent-plugin
This is a plugin to allow OmegaT to source machine translations from Tencent Cloud.
Stars: ✭ 31 (-59.74%)
Mutual labels:  machine-translation

Transformer-pytorch

A PyTorch implementation of Transformer in "Attention is All You Need" (https://arxiv.org/abs/1706.03762)

This repo focuses on clean, readable, and modular implementation of the paper.

screen shot 2018-09-27 at 1 49 14 pm

Requirements

Usage

Prepare datasets

This repo comes with example data in data/ directory. To begin, you will need to prepare datasets with given data as follows:

$ python prepare_datasets.py --train_source=data/example/raw/src-train.txt --train_target=data/example/raw/tgt-train.txt --val_source=data/example/raw/src-val.txt --val_target=data/example/raw/tgt-val.txt --save_data_dir=data/example/processed

The example data is brought from OpenNMT-py. The data consists of parallel source (src) and target (tgt) data for training and validation. A data file contains one sentence per line with tokens separated by a space. Below are the provided example data files.

  • src-train.txt
  • tgt-train.txt
  • src-val.txt
  • tgt-val.txt

Train model

To train model, provide the train script with a path to processed data and save files as follows:

$ python train.py --data_dir=data/example/processed --save_config=checkpoints/example_config.json --save_checkpoint=checkpoints/example_model.pth --save_log=logs/example.log 

This saves model config and checkpoints to given files, respectively. You can play around with hyperparameters of the model with command line arguments. For example, add --epochs=300 to set the number of epochs to 300.

Translate

To translate a sentence in source language to target language:

$ python predict.py --source="There is an imbalance here ." --config=checkpoints/example_config.json --checkpoint=checkpoints/example_model.pth

Candidate 0 : Hier fehlt das Gleichgewicht .
Candidate 1 : Hier fehlt das das Gleichgewicht .
Candidate 2 : Hier fehlt das das das Gleichgewicht .

It will give you translation candidates of the given source sentence. You can adjust the number of candidates with command line argument.

Evaluate

To calculate BLEU score of a trained model:

$ python evaluate.py --save_result=logs/example_eval.txt --config=checkpoints/example_config.json --checkpoint=checkpoints/example_model.pth

BLEU score : 0.0007947

File description

  • models.py includes Transformer's encoder, decoder, and multi-head attention.
  • embeddings.py contains positional encoding.
  • losses.py contains label smoothing loss.
  • optimizers.py contains Noam optimizer.
  • metrics.py contains accuracy metric.
  • beam.py contains beam search.
  • datasets.py has code for loading and processing data.
  • trainer.py has code for training model.
  • prepare_datasets.py processes data.
  • train.py trains model.
  • predict.py translates given source sentence with a trained model.
  • evaluate.py calculates BLEU score of a trained model.

Reference

Author

@dreamgonfly

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].