CODE UPDATED ON 5.16.2020. PLEASE USE UPDATED VERISON.
Contains data/code for the paper "Neural Syntactic Preordering for Controlled Paraphrase Generation" (ACL 2020). https://arxiv.org/abs/2005.02013
Additional data/resources/trained models are available at https://drive.google.com/drive/folders/1NIpmFxD3ZKFAZdkzUIBzj8Au74pzsacU?usp=sharing The link contains training data to train new models, and also trained models for both SOW and REAP.
Environment base is Python 3.6. Also see requirements.txt. We used Stanford CoreNLP version 3.9.1.
The SOW-REAP pipeline generates syntactically diverse paraphrases using 2 steps.
Source Order reWriting: An encoder-decoder model is used to apply tranduction operations over various versions of the input sentence, obtained by abstracting out different pairs of constituents.
REarrangement Aware Paraphrasing: A combination of the transductions are chosen to construct an ordering guide. This ordering informs the generation of the output paraphrases.
Data files train_sow.hdf5 and dev_sow.hdf5 correspond to the training and dev files for SOW. These contain phrase level inputs and outputs, with exactly two constituents abstracted out. We train a seqq2seq transformer model to learn this transduction. Run the following commands from the project root folder to train the sow model:
export PYTHONPATH=./
python sow/train.py
Data files train.hdf5 and dev.hdf5 correspond to the training and dev files for REAP. This model learns a seq2seq model to paraphrase the input sentence, additionally conditioned on an input reordering, that indicates the desired order of content in the output sentence. Run the following commands from the project root folder to train the reap model:
export PYTHONPATH=./
python reap/train.py
java -mx4g -cp "*" edu.stanford.nlp.process.PTBTokenizer -preserveLines < sample_test_baseline.txt > sample_test_baseline.tok
python generate_paraphrases_baseline.py
python generate_paraphrases_gt_reap.py
java -mx4g -cp "*" edu.stanford.nlp.pipeline.StanfordCoreNLP -annotators tokenize,ssplit,pos,parse -preserveLines -ssplit.eolonly true -outputFormat text -file sample_test_baseline.txt
The output from the stanford nlp parser serves as an input to our SOW-REAP generator. To generate paraphrases:
python generate_paraphrases_sow_reap.py
# The code in this repo uses the transformer implementaion from https://github.com/eladhoffer/seq2seq.pytorch