Code Monkey home page Code Monkey logo

quark's Introduction

QUARK

This is the official repo for the paper "Quark: Controllable Text Generation with Reinforced Unlearning" (NeurIPS 2022)

Requirement

We suggest using conda to setup environment. You need to first replace prefix in environment.yml with your home path. With conda installed, create an environment called quark with:

conda env create -f environment.yml

Instuction

The main branch contains toxicity unlearning task. We put the other two tasks, sentiment steering and repetition reduction in sentiment branch and repetition branch separately.

We use the PerspectiveAPI to score toxicity in reward computing, which requires API key for access. Please refer to their website for API key application.

Training

Please first replace PERSPECTIVE_API_KEY in constants.py with your own API key. For training quark for toxicity reduction with default hyperparameters,

python main.py

You can change hyperparameters in arguments.py via argparse.

Evaluation

To evaluate the toxicity of unlearned model, please use sample.py. You need to first replace save_path and checkpoint_path with your output directory and model checkpoint path, then

python sample.py

It will save the evaluation result to your output directory.

To evaluate perplexity of the generations, please use perplexity.py. You need to first replace save_path with the same output directory specified above, then

python perplexity.py

It will save the perplexity result to the same output directory.

Model Checkpoint

We release our model checkpoints for all three tasks: toxicity unlearn, sentiment steering (positive, negative) and repetition reduction.

Citation

If you use this codebase in your work, please consider citing our paper:

@article{Lu2022QuarkCT,
  title={Quark: Controllable Text Generation with Reinforced Unlearning},
  author={Ximing Lu and Sean Welleck and Liwei Jiang and Jack Hessel and Lianhui Qin and Peter West and Prithviraj Ammanabrolu and Yejin Choi},
  journal={ArXiv},
  year={2022},
  volume={abs/2205.13636}
}

quark's People

Contributors

gloriaximinglu avatar gximinglu 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.