This is the Pytorch implementation for the paper Contrastive Learning with Adversarial Perturbations for Conditional Text Generation (ICLR 2021): [Paper]
Recently, sequence-to-sequence (seq2seq) models with the Transformer architecture have achieved remarkable performance on various conditional text generation tasks, such as machine translation. However, most of them are trained with teacher forcing with the ground truth label given at each time step, without being exposed to incorrectly generated tokens during training, which hurts its generalization to unseen inputs, that is known as the "exposure bias" problem. In this work, we propose to solve the conditional text generation problem by contrasting positive pairs with negative pairs, such that the model is exposed to various valid or incorrect perturbations of the inputs, for improved generalization. However, training the model with naïve contrastive learning framework using random non-target sequences as negative examples is suboptimal, since they are easily distinguishable from the correct output, especially so with models pretrained with large text corpora. Also, generating positive examples requires domain-specific augmentation heuristics which may not generalize over diverse domains. To tackle this problem, we propose a principled method to generate positive and negative samples for contrastive learning of seq2seq models. Specifically, we generate negative examples by adding small perturbations to the input sequence to minimize its conditional likelihood, and positive examples by adding large perturbations while enforcing it to have a high conditional likelihood. Such "hard'' positive and negative pairs generated using our method guides the model to better distinguish correct outputs from incorrect ones. We empirically show that our proposed method significantly improves the generalization of the seq2seq on three text generation tasks --- machine translation, text summarization, and question generation.
Contribution of this work
Summarization
cd src/summarization
mkdir data
wget
http://bollin.inf.ed.ac.uk/public/direct/XSUM-EMNLP18-Summary-Data-Original.tar.gz
Download train/dev/test split from here and place it under data directory.
python preprocess.py
NMT
cd src/nmt
Download data.gz and unzip it.
QG
cd src/qg
Download data.gz and unzip it. Download pickle.tar.gz and unzip it
cd src/"task"(e.g. qg, nmt, or summarization)
python main.py --model_dir "directory for checkpoint" --devices "gpu devices" (gpu number delimited by _ e.g. 0_1_2_3_4_5_6_7) --batch_size "batch size"
cd src/"task"
python inference.py --ckpt_file "check point file" --batch_size "batch size" --beam_size "beam size" --res_dir "directory for evaluation result"
To cite the code/data/paper, please use this BibTex
@inproceedings{
lee2021contrastive,
title={Contrastive Learning with Adversarial Perturbations for Conditional Text Generation},
author={Seanie Lee and Dong Bok Lee and Sung Ju Hwang},
booktitle={International Conference on Learning Representations},
year={2021},
}