Skip to main content

a zero-shot NMT

Project description

Title : Teacher-Student FrameWork for Zero-Shot Machine Translation Author : xxlucas Logo : True

[TITLE]

Introduction

TS-FrameWork is machine translation framework which is based on OpenNMT-py.

The main idea about how to implement is coming from A Teacher-Student Framework for Zero-Resource Neural Machine Translation

Here is the paper :[arXiv:1705.00753]

And if you don’t know what zero-shot mean, please do a Google search and you will find the answer.

Usage

If you want to translate some resource-poor languages into the target language, usually such a parallel corpus is difficult to build.

So there is a commonly used method called pivot-based method to solve this situation. It means that if the source-to-target parallel corpus are not available but we can find the source-to-pivot language pairs and the pivot-to-target language pairs,and build a NMT model to solve the problem. In this way, our problem becomes very easy to solve: train two NMT models for the source-pivot and the pivot-target language pairs, respectively. Both of them also bring two new problems.The result is that the training time is too long,and error propagation that is,the training error from the former model will be the input of the latter one.

Therefore,if we train a model once that all the issue will be vanished.

Assume that the source-to-pivot and pivot-to-target languages are all available.

**Step 0. preprocess the raw data **

mkdir data
cd data

mkdir teacher
mkdir student

python ../preprocess.py --train_src path_to_pivot --train_tgt path_to_target \
                  --save_data data/teacher
python ../preprocess.py --train_src path_to_source --train_tgt path_to_pivot \
                  --save_data data/student

**Step 1. train teacher model on pivot-to-target **

# the GNMT style teacher model
python train.py -data data/teacher -save_model ./model \
        -layers 8 -rnn_size 1024 -rnn_type GRU \
        -encoder_type brnn -decoder_type rnn \
        -train_steps 200000  -max_generator_batches 2 -dropout 0.1 \
        -batch_size 128 -batch_type sents -normalization sents  -accum_count 2 \
        -optim adam -adam_beta2 0.998 -decay_method noam -warmup_steps 8000 -learning_rate 1e-3 \
        -max_grad_norm 5 -param_init 0  -param_init_glorot \
        -valid_steps 10000 -save_checkpoint_steps 10000 \
        -world_size 1 -gpu_ranks 0

**Step 2. train student model on source-to-pivot **

# the transformer student model
python train.py -data data/student/ -save_model student \
-layers 6 -rnn_size 512 -word_vec_size 512 -transformer_ff 2048 -heads 8 \
-encoder_type transformer -decoder_type transformer -position_encoding \
-train_steps 100000 -max_generator_batches 2 -dropout 0.1 \
-batch_size 4096 -batch_type tokens -normalization tokens -accum_count 2 \
-optim adam -adam_beta2 0.998 -decay_method noam -warmup_steps 8000 -learning_rate 2 \
-label_smoothing 0.1 -save_checkpoint_steps 10000 \
-world_size 1 -gpu_ranks 0 --teacher_model_path model_step_200000.pt

You can evaluate the model with OpenNMT-py's api.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

pivot-based-NMT-1.1.tar.gz (3.2 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

pivot_based_NMT-1.1-py3-none-any.whl (3.8 kB view details)

Uploaded Python 3

File details

Details for the file pivot-based-NMT-1.1.tar.gz.

File metadata

  • Download URL: pivot-based-NMT-1.1.tar.gz
  • Upload date:
  • Size: 3.2 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.1.1 pkginfo/1.5.0.1 requests/2.23.0 setuptools/41.2.0 requests-toolbelt/0.9.1 tqdm/4.30.0 CPython/3.8.3

File hashes

Hashes for pivot-based-NMT-1.1.tar.gz
Algorithm Hash digest
SHA256 9ce9a7f3d11f291b0b3477986202313ca3e6aeac80458fcbeb81577a93e98cbf
MD5 8ac3219ed683db0671a7e434d8cc429c
BLAKE2b-256 de7414390482014bd7e5b306b5bf9369b3345b0417795f2b56028dc3ffcef971

See more details on using hashes here.

File details

Details for the file pivot_based_NMT-1.1-py3-none-any.whl.

File metadata

  • Download URL: pivot_based_NMT-1.1-py3-none-any.whl
  • Upload date:
  • Size: 3.8 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.1.1 pkginfo/1.5.0.1 requests/2.23.0 setuptools/41.2.0 requests-toolbelt/0.9.1 tqdm/4.30.0 CPython/3.8.3

File hashes

Hashes for pivot_based_NMT-1.1-py3-none-any.whl
Algorithm Hash digest
SHA256 f4c7ec1b3b51d4cd91d29e4f84452c4e220f23e7f0c157a0dd59ec17e80a710c
MD5 9bb8a6e693c76336be6a6c1b2a40aff3
BLAKE2b-256 785b602d06d69ef2be87cfb989dc5c148c3a72e9246e8e599f3dc4431f18b9d2

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page