Coder Social home page Coder Social logo

textstyletransfer's Introduction

This is implementation for the paper "Reinforcement Learning Based Text Style Transfer without Parallel Training Corpus" accepted by NAACL 2019.

  • Add folder Create folder data/, dump/, model/ and pretrained_model/ in the same level of src/

  • Data prep Put data to data_folder

  • data_folder: ../data/[data_type]/
  • data_type: yelp/gyafc_family
  • Put train/dev/test corpus in original/target style as corpus.(train/dev/test).(orig/tsf) Put pretrained embedding in text format to the path of embed_fn
  • Running instructions
  1. Data processing yelp data: python3 corpus_helper.py --data DATA --vec_dim 100 --embed_fn gyafc_family data: python3 corpus_helper.py --data DATA --tokenize --vec_dim 100 --embed_fn
  • DATA: gyafc_family / yelp
  • "--tokenize" only for gyafc_family data
  • data path: ../data/DATA/corpus.(train/test).(orig/tsf)
  • save path: pkl is saved to ../dump/DATA/, pkl files are (train/test)_(orig/tsf).pkl, tuned embedding is saved to tune_vec.txt
  1. python3 style_transfer_rl.py -- data DATA
  • DATA: gyafc_family / yelp

yelp data pretrain CUDA_VISIBLE_DEVICES=0,1 python3 style_transfer_RL.py --data_type yelp --max_sent_len 18 --lm_seq_length 18 --lm_epochs 5 --style_epochs 1 --pretrain_epochs 2 --beam_width 1 --pretrained_model_path best_pretrained_model --batch_size 32

yelp data RL CUDA_VISIBLE_DEVICES=0,1 python3 style_transfer_RL.py --data_type yelp --max_sent_len 18 --lm_seq_length 18 --use_pretrained_model --pretrained_model_path best_pretrained_model --rollout_num 2 --beam_width 1 --rl_learning_rate 1e-6 --batch_size 16 --epochs 1

gyafc_family pretrain CUDA_VISIBLE_DEVICES=0,1 python3 style_transfer_RL.py --data_type gyafc_family --max_sent_len 30 --lm_seq_length 30 --lm_epochs 8 --style_epochs 3 --pretrain_epochs 4 --beam_width 1 --pretrained_model_path best_pretrained_model --batch_size 32

gyafc_family RL CUDA_VISIBLE_DEVICES=2,3 python3 style_transfer_RL.py --data_type yelp --max_sent_len 30 --lm_seq_length 30 --use_pretrained_model --pretrained_model_path best_pretrained_model --rollout_num 2 --beam_width 1 --rl_learning_rate 1e-6 --batch_size 16 --epochs 1

  1. Test yelp data CUDA_VISIBLE_DEVICES=2 python3 style_transfer_test.py --data_type yelp --max_sent_len 18 --lm_seq_length 18 --use_beamsearch_decode --beam_width 1 --model_path MODEL_PATH --output_path OUTPUT_PATH --batch_size 32
  • MODEL_PATH: ../model/[DATA_TYPE]/model
  • OUTPUT_PATH: the path where transferred sentences are saved

Hypeparameters:

In reinforcement learning, we use a combination rewards from style, semantic discriminator and language model as the training reward. You may want to change style_weight, semantic_weight and lm_weight in params.py to tune the model. The larger the weight is, the more dominant the corresponding metric is.

Also, both pretrain.py and style_transfer_RL.py enable model selection, the default method in the implementation is to select the model with the highest semantic reward with a preset style threshold. You may want to try other methods for model selection.


If you're considering using our code, please cite our paper:

@article{gong2019reinforcement, title={Reinforcement Learning Based Text Style Transfer without Parallel Training Corpus}, author={Gong, Hongyu and Bhat, Suma and Wu, Lingfei and Xiong, Jinjun and Hwu, Wen-mei}, journal={arXiv preprint arXiv:1903.10671}, year={2019} }

Gong H, Bhat S, Wu L, Xiong J, Hwu WM. Reinforcement Learning Based Text Style Transfer without Parallel Training Corpus. arXiv preprint arXiv:1903.10671. 2019 Mar 26.

textstyletransfer's People

Contributors

hongyugong avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.