GithubHelp home page GithubHelp logo

zanejins / floater Goto Github PK

View Code? Open in Web Editor NEW

This project forked from xuanqing94/floater

0.0 0.0 0.0 4.76 MB

Learning to Encode Position for Transformer with Continuous Dynamical Model

License: MIT License

Shell 0.06% C++ 0.74% Python 97.52% Lua 0.24% Cuda 1.45%

floater's Introduction

FLOATER

This is the official implementation of Learning to encode position for transformer with continuous dynamical model in ICML 2020

The codebase is modified upon fairseq.

Install the dependencies

In what follows I assume PyTorch(>=1.3) is installed.

# Install torchdiffeq
pip install [email protected]:xuanqing94/torchdiffeq.git

# Install fairseq
git clone https://github.com/xuanqing94/FLOATER.git
cd FLOATER
pip install -e .

NOTE Do not install the official torchdiffeq, I made several fixes to work with FLOATER.

Run WMT14 En-De and En-Fr

First, download and preprocess the dataset:

# Download & bpe tokenize
bash examples/translation/prepare-wmt14en2de.sh --icml17
bash examples/translation/prepare-wmt14en2fr.sh

Then binarize the dataset:

TEXT=ende32k_wmt14
fairseq-preprocess \
    --trainpref $TEXT/train \
    --validpref $TEXT/valid \
    --testpref $TEST/test \
    --source-lang en --target-lang de \
    --destdir data-bin/tokenized.en-de \
    --joined-dictionary \
    --workers 20

# Binarize En-Fr similarly.

You can choose to train FLOATER from scratch but it will take a pretty long time until convergence. So, I recommend to follow the pretraining and finetuning approach discussed in the paper:

# Pretraining
fairseq-train \
    data-bin/wmt14.en-de/ \
    --arch transformer_wmt_en_de --share-all-embeddings \
    --optimizer adam --adam-betas '(0.9, 0.98)' --clip-norm 0.0 \
    --lr 7e-4 --min-lr 1.0e-9 \
    --lr-scheduler inverse_sqrt \
    --weight-decay 0.0 \
    --criterion label_smoothed_cross_entropy --label-smoothing 0.1 \
    --max-tokens 2000 --save-dir ./checkpoints/base-flow \
    --warmup-init-lr 1.0e-7 --warmup-updates 4000 \
    --find-unused-parameters \
    --update-freq 2 \
    --reset-optimizer \
    --max-epoch 30 \

# initialize checkpoint_last.pt with original transformer model
python model_migration.py

# fine-tune FLOATER model for 10 more epochs
fairseq-train \
    data-bin/wmt14.en-de/ \
    --arch flow_transformer_wmt_en_de --share-all-embeddings \
    --optimizer adam --adam-betas '(0.9, 0.98)' --clip-norm 0.0 \
    --lr 3.5e-4 --min-lr 1.0e-9 \
    --lr-scheduler inverse_sqrt \
    --weight-decay 0.0 \
    --criterion label_smoothed_cross_entropy --label-smoothing 0.1 \
    --max-tokens 2000 --save-dir ./checkpoints/base-flow \
    --warmup-init-lr 1.0e-7 --warmup-updates 4000 \
    --find-unused-parameters \
    --update-freq 2 \
    --save-interval-updates 2000 \
    --reset-optimizer \
    --max-epoch 10 \

# evaluate on test set
folder=base-flow
nckpt=5
python scripts/average_checkpoints.py \
    --inputs ./checkpoints/${folder}/ \
    --output ./checkpoints/${folder}/averaged.pt \
    --num-update-checkpoints ${nckpt} \

 fairseq-generate data-bin/tokenized.en-de \
       --path checkpoints/${folder}/averaged.pt \
       --beam 4 --batch-size 64 --remove-bpe  --lenpen 0.6 > tmp_out

bash scripts/compound_split_bleu.sh tmp_out

floater's People

Contributors

alexeib avatar cndn avatar davidecaroselli avatar edunov avatar freewym avatar halilakin avatar hitvoice avatar hmc-cs-mdrissi avatar huihuifan avatar jhcross avatar jingfeidu avatar jma127 avatar kartikayk avatar lematt1991 avatar liezl200 avatar louismartin avatar michaelauli avatar myleott avatar nng555 avatar pipibjc avatar rutyrinott avatar skritika avatar stephenroller avatar taineleau avatar taylanbil avatar theweiho avatar vineetk1 avatar xianxl avatar xuanqing94 avatar zhiqwang 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.