Coder Social home page Coder Social logo

allyoushawn / transformer_mt Goto Github PK

View Code? Open in Web Editor NEW
1.0 2.0 0.0 21 KB

A PyTorch implementation of the transformer. Use machine translation to compare it with LSTM.

Python 99.54% Shell 0.46%
lstm-neural-networks machine-translation neural-machine-translation pytorch seq2seq transformer

transformer_mt's Introduction

Transformer on Machine Translation

The repository is a PyTorch implementation of transformer. We also implement attentional LSTM and use machine translation to compare the two models. The MT data and preprocessing code is based on the Link. The transformer code is based on the Link

Datasets

The repository contains two translation pairs: en-fr, en-zh. We provide some example files for illustrating the proper paths of each file. Please follow the steps in setup to download and put the files in their corresponding paths.

Setup (French-English)

  1. Please download the French-English corpus.
  2. Unzip the corpus and rename europarl-v7.fr-en.en, europarl-v7.fr-en.fr to en.txt, fr.txt, respectively.
  3. Put en.txt, fr.txt in datasets/en_fr
  4. Download the SpaCy models we need for preprocessing. The full list of languages of SpaCy is here.
python -m spacy download en_core_web_sm
python -m spacy download fr_core_news_sm

Run the code

Use bash run.sh to run the code, it would generate the following items in directory results.

  • model.cpu.pt : The model which can be loaded with CPU environment.
  • model.pt: The model which can be loaded with GPU or CPU environment, based on if the model is trained with GPU.
  • src.vocab: Source language vocabulary.
  • tgt.vocab: Target language vocabulary.

Use different models

Specify the model_type variable to be Transformer or LSTM.

English-Chinese Translation

We use Back-translated news released by WMT20 for our English-Chinese Translation dataset. The dataset could be found here

Configs

  • Python: 3.8.10
  • torch: 1.9.0
  • torchtext: 0.10.0
  • CUDA: 11.3

transformer_mt's People

Contributors

allyoushawn avatar

Stargazers

wenhao avatar

Watchers

 avatar Kostas Georgiou avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.