Git Product home page Git Product logo

nlg-rl's Introduction

NLG-RL

This repository provides PyTorch implementations of our method [1] for reinforcement learning for sentence generation with action-space reduction.

Requirements

  • Python 3.X
  • PyTorch 0.2X or 0.4X
  • Numba

Training NMT models

Please cd to ./code_0.2 or ./code_0.4 to run experiments. The input data format is one sentence per line for each language.

Small softmax

  • Vocabulary predictor (minimal usage with the default settings used in our paper)
    python train_vocgen.py --train_source XX --train_target YY --dev_source ZZ --dev_target WW

  • NMT with cross-entropy (minimal usage after training the vocabulary predictor)
    python train_nmt.py --train_source XX --train_target YY --dev_source ZZ --dev_target WW

  • NMT with REINFORCE and cross-entropy
    python train_nmt_rl.py --train_source XX --train_target YY --dev_source ZZ --dev_target WW

Full softmax (standard baseline)

  • NMT with cross-entropy (minimal usage without using the vocabulary predictor)
    python train_nmt.py --K -1 --train_source XX --train_target YY --dev_source ZZ --dev_target WW

  • NMT with REINFORCE and cross-entropy
    python train_nmt_rl.py --K -1 --train_source XX --train_target YY --dev_source ZZ --dev_target WW

Notes

A new feature in ./code_0.4

I added an additional option --batch_split_size to train_nmt.py and train_nmt_rl.py to avoid using multiple GPUs, mainly for the Full-softmax setting. The idea is very simple; at each mini-batch iteration, the mini-batch is further split into N smaller chunks by setting --batch_split_size N, after sorting the mini-batch examples according to source token lengths. By this, GPU memory consumption can be reduced, and sometimes we can even expect speedup because of less padding computations. Note that partial derivatives of the N chunks are accumurated, and thus this is different from reducing the mini-batch size. Some experimental results are shown in our NAACL2019 camera-ready paper.

BLEU scores

By default, the BLEU scores computed by this codebase do not assume any additional (de-)tokenization. Thus, if you need more specific ways to compute BLEU scores, you need to modify bleu.sh to incorporate your (de-)tokenization tools.

Reference

[1] Kazuma Hashimoto and Yoshimasa Tsuruoka. 2019. Accelerated Reinforcement Learning for Sentence Generation by Vocabulary Prediction. In Proceedings of the 2019 Conference of the North American Chapter of the Association for Computational Linguistics: Human Language Technologies (NAACL-HLT 2019), arXiv cs.CL 1809.01694. (bibtex)

Questions?

Any issues and PRs are welcome.

E-mail: [email protected]

nlg-rl's People

Stargazers

 avatar

Watchers

James Cloos 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.