Giter VIP home page Giter VIP logo

advsr's Introduction

Overview

AdvSR GitHub

Adversarial Subword Regularization for Robust Neural Machine Translation

intro

We present AdvSR to study whether gradient signals during training can be a substitute criterion for choosing segmentation among candidates. NMT models suffer from typos(character drop, character swap) in the source text due to the unseen subword compositions ( _ denotes segmentation). Our method correctly decodes them by exposing diverse, yet adversarial subword sequence which regularizes NMT models in the low-resource datasets.

Requirements

$ conda create -n adv_sr python=3.6
$ conda activate adv_sr
$ conda install numpy tqdm nltk
$ pip install sentencepiece
$ pip install torch==1.2.0

Clone & Build

$ git clone https://github.com/dmis-lab/AdvSR.git
$ cd AdvSR
$ pip install .

Resources

Library

We use the Fairseq (v0.8.0) for training, and SacreBLEU for evaluation.

Datasets

The preprocessed dataset can be downloaded from the following link.

Also, you can manually download and preprocess the dataset (IWSLT15.CS.EN) by following example.

bash prepare_iwslt15_cs_en.sh
RAW_DIR=iwslt15.cs.en.sp16k
DATA_DIR=data-bin/iwslt15.cs.en
make preprocess RAW_DIR=${RAW_DIR} DATA_DIR=${DATA_DIR}
mv ${RAW_DIR}/sentencepiece.sp.model ${DATA_DIR}/.

Train

The following example trains transformer-base model on IWSLT15_CS_EN.

CUDA=0
CHECK_DIR=iwslt15.cs.en.ckpt
DATA_DIR=data-bin/iwslt15.cs.en
SPM_DIR=${DATA_DIR}/sentencepiece.sp.model
make train_adv CUDA=${CUDA} DATA=${DATA_DIR} CHECK_DIR=${CHECK_DIR} NUM_CANDS=9 SRC_PERT_PROB=0.25 TGT_PERT_PROB=0.25 SPM_DIR=${SPM_DIR}

GPU memory will be variable upon training due to the variable length of the adversarially generated sequence. If OOM occurs(rarely happens), the optimizer will simply skip training the corresponding batch (as implemented in fairseq). We experimented with Tesla P40 and present our trained checkpoint from the example.

Note that if you want to evaluate with the pre-trained checkpoint from the above link, you may want to use the preprocessed data-file from the drive since the vocabulary index might be different.

Evaluation

The following example evaluates trained NMT model with the evaluation dataset from IWSLT15_CS_EN. We cloned and updated the codes from SacreBLEU for the evaluation of IWSLT15, IWSLT13.

CUDA=0
CHECK_DIR=iwslt15.cs.en.ckpt
DATA_DIR=data-bin/iwslt15.cs.en
SPM_DIR=${DATA_DIR}/sentencepiece.sp.model
make inference CUDA=${CUDA} TEST_DATA=iwslt15/tst2013 SRC=cs TGT=en SPM_DIR=${SPM_DIR} DATA=${DATA_DIR} CHECK_DIR=${CHECK_DIR}/checkpoint_best.pt

Result

The result is as follows.

BLEU+case.lc+lang.cs-en+numrefs.1+smooth.exp+test.iwslt15/tst2013+tok.13a+version.1.4.2 = 32.1 66.5/40.4/26.5/18.1 (BP = 0.954 ratio = 0.955 hyp_len = 26272 ref_len = 27502)

Citation

@inproceedings{park2020adversarial,
  title={Adversarial Subword Regularization for Robust Neural Machine Translation},
  author={Park, Jungsoo and Sung, Mujeen and Lee, Jinhyuk and Kang, Jaewoo},
  booktitle={EMNLP:Findings},
  year={2020}
}

advsr's People

Contributors

myleott avatar alexeib avatar jjumssu avatar liezl200 avatar edunov avatar huihuifan avatar louismartin avatar kartikayk avatar davidecaroselli avatar cndn avatar stephenroller avatar pipibjc avatar lematt1991 avatar jingfeidu avatar hitvoice avatar jhcross avatar rutyrinott avatar taylanbil avatar theweiho avatar skritika avatar freewym avatar hmc-cs-mdrissi avatar xianxl avatar nng555 avatar michaelauli avatar halilakin avatar sai-prasanna avatar alvations avatar taineleau avatar zhiqwang avatar

Watchers

James Cloos 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.