The code for the paper "Adversarial Decomposition of Text Representation", NAACL 2019 https://arxiv.org/abs/1808.09042
- Clone this repo:
https://github.com/text-machine-lab/adversarial_decomposition.git
- Install NumPy:
pip install numpy==1.16.3
- Install PyTorch v1.1.0:
pip install https://download.pytorch.org/whl/cu100/torch-1.1.0-cp37-cp37m-linux_x86_64.whl
(for python3.6, usepip install https://download.pytorch.org/whl/cu100/torch-1.1.0-cp36-cp36m-linux_x86_64.whl
) - Install dependencies:
pip install -r requirements.txt
- Download spacy models:
python -m spacy download en_core_web_lg
- Create dir
mkdir -p data/experiments
- Create dir
mkdir -p data/datasets
- Create dir
mkdir -p data/word_embeddings
- Download the Shakespeare data:
git clone https://github.com/cocoxu/Shakespeare.git data/datasets/shakespeare
- Download the Yelp data:
git clone https://github.com/shentianxiao/language-style-transfer.git data/datasets/yelp
- Download the pickled GloVe embeddings
wget https://mednli.blob.core.windows.net/shared/word_embeddings/glove.840B.300d.pickled -O data/word_embeddings/glove.840B.300d.pickled
- Download the pickled fastText embeddings
wget https://mednli.blob.core.windows.net/shared/word_embeddings/crawl-300d-2M.pickled -O data/word_embeddings/crawl-300d-2M.pickled
Global constants are set in the file settings.py
. In general, you don't need to change this file.
Experiment parameters are set in the config.py
file.
First, run the preprocessing script: python preprocess.py
This scipt will print the ID of the preprocessing experiment, for example preprocess.buppgpnf
. Copy this ID and change parameter preprocess_exp_id
of the TrainConfig
class on the line 12 in the file config.py
file accordingly.
After you set the preprocess experiment id, run the training: python train.py
.
This scirpt will also print the ID of the training experiment. You can paste it in the eval_generation.ipynb
notebook to play with the model.
The provided eval_generation.ipynb
notebook shows how to use the model to swap the meaning and form vectors of the input sentences!
If you find this code helpful, please consider citing our paper:
A. Romanov, A. Rumshisky, A. Rogers, D. Donahue,Adversarial decomposition of text represen-tation, In Proceedings of NAACL 2019: Conference of the North American Chapter of the Association for Computational Linguistics, 2019
https://arxiv.org/abs/1808.09042
@inproceedings{romanov2019adversarial,
title={Adversarial Decomposition of Text Representation},
author={Romanov, Alexey and Rumshisky, Anna and Rogers, Anna and Donahue, David},
booktitle={Proceedings of NAACL 2019: Conference of the North American Chapter of the Association for Computational Linguistics},
year={2019}
}