MCPcopy Index your code
hub / github.com/GXimingLu/Quark

github.com/GXimingLu/Quark @main

Chat with this repo
repository ↗ · DeepWiki ↗ · + Follow
89 symbols 339 edges 12 files 2 documented · 2%
What it actually does AI analysis from the code graph — generated when you open this
loading…
README

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

Instruction

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}
}

Core symbols most depended-on inside this repo

reduce_mean
called by 9
utils/utils.py
add
called by 7
data_pool.py
update
called by 6
main.py
decode
called by 5
main.py
reduce_sum
called by 4
utils/utils.py
request
called by 4
utils/perspective_api.py
forward_pass
called by 3
policy.py
mask_pad
called by 3
utils/utils.py

Shape

Method 46
Function 29
Class 14

Languages

Python100%

Modules by API surface

main.py32 symbols
utils/utils.py17 symbols
utils/perspective_api.py15 symbols
reward.py8 symbols
policy.py4 symbols
model/gpt2.py4 symbols
data_pool.py4 symbols
sample.py3 symbols
perplexity.py1 symbols
arguments.py1 symbols

For agents

$ claude mcp add Quark \
  -- python -m otcore.mcp_server <graph>

⬇ download graph artifact