README.md 2.2 KB
Newer Older
1 2 3 4
The minimum PaddlePaddle version needed for the code sample in this directory is v0.11.0. If you are on a version of PaddlePaddle earlier than v0.11.0, [please update your installation](http://www.paddlepaddle.org/docs/develop/documentation/en/build_and_install/pip_install_en.html).

---

R
ranqiu 已提交
5 6 7 8 9
# Convolutional Sequence to Sequence Learning
This model implements the work in the following paper:

Jonas Gehring, Micheal Auli, David Grangier, et al. Convolutional Sequence to Sequence Learning. Association for Computational Linguistics (ACL), 2017

R
ranqiu 已提交
10
# Data Preparation
R
ranqiu 已提交
11
- The data used in this tutorial can be downloaded by runing:
R
ranqiu 已提交
12

R
ranqiu 已提交
13 14 15
    ```bash
    sh download.sh
    ```
R
ranqiu 已提交
16

R
ranqiu 已提交
17 18 19 20 21
- Each line in the data file contains one sample and each sample consists of a source sentence and a target sentence. And the two sentences are seperated by '\t'. So, to use your own data, it should be organized as follows:

    ```
    <source sentence>\t<target sentence>
    ```
R
ranqiu 已提交
22

R
ranqiu 已提交
23 24 25
# Training a Model
- Modify the following script if needed and then run:

R
ranqiu 已提交
26 27 28 29
  ```bash
  python train.py \
      --train_data_path ./data/train \
      --test_data_path ./data/test \
Y
yangyaming 已提交
30 31 32 33 34 35
      --src_dict_path ./data/src_dict \
      --trg_dict_path ./data/trg_dict \
      --enc_blocks "[(256, 3)] * 5" \
      --dec_blocks "[(256, 3)] * 3" \
      --emb_size 256 \
      --pos_size 200 \
R
ranqiu 已提交
36 37
      --drop_rate 0.2 \
      --use_bn False \
Y
yangyaming 已提交
38 39 40 41 42
      --use_gpu False \
      --trainer_count 1 \
      --batch_size 32 \
      --num_passes 20 \
      >train.log 2>&1
R
ranqiu 已提交
43
  ```
R
ranqiu 已提交
44 45 46 47

# Inferring by a Trained Model
- Infer by a trained model by running:

R
ranqiu 已提交
48 49 50
  ```bash
  python infer.py \
      --infer_data_path ./data/dev \
Y
yangyaming 已提交
51 52 53 54 55 56
      --src_dict_path ./data/src_dict \
      --trg_dict_path ./data/trg_dict \
      --enc_blocks "[(256, 3)] * 5" \
      --dec_blocks "[(256, 3)] * 3" \
      --emb_size 256 \
      --pos_size 200 \
R
ranqiu 已提交
57 58
      --drop_rate 0.2 \
      --use_bn False \
Y
yangyaming 已提交
59 60 61
      --use_gpu False \
      --trainer_count 1 \
      --max_len 100 \
R
ranqiu 已提交
62
      --batch_size 256 \
Y
yangyaming 已提交
63
      --beam_size 1 \
R
ranqiu 已提交
64
      --is_show_attention False \
Y
yangyaming 已提交
65 66 67
      --model_path ./params.pass-0.tar.gz \
      1>infer_result 2>infer.log
    ```
R
ranqiu 已提交
68 69

# Notes
R
ranqiu 已提交
70
Since PaddlePaddle of current version doesn't support weight normalization, we use batch normalization instead to confirm convergence when the network is deep.