IAAR-Shanghai / DATG

[ACL 2024]Controlled Text Generation for Large Language Model with Dynamic Attribute Graphs
https://iaar-shanghai.github.io/DATG/
Apache License 2.0
35 stars 3 forks source link
controllable-text-generation controlled-text-generation fudge graph inference large-language-models llms pagerank preadd text-generation

πŸ•ΈοΈ DATG: Controlled Text Generation for Large Language Models with Dynamic Attribute Graphs

A framework designed for controlled text generation in Large Language Models using dynamic attribute graphs.
Refer to our arXiv paper for detailed insights and methodology.

License: Apache arXiv Paper

Introduction

DATG (Dynamic Attribute Graphs-based Text Generation) is an innovative approach designed for controlled text generation, enabling precise control over text attributes during the decoding phase while maintaining the natural fluency of the text. This method leverages dynamic attribute graphs to evaluate and adjust key terms related to target attributes, thereby controlling the attributes of the generated text effectively without compromising text quality.

framework

Project structure

.
β”œβ”€β”€ .cache           # Cache some results during evaluation to prevent losing all results
β”œβ”€β”€ .gitattributes   # Git attributes
β”œβ”€β”€ .gitignore       # Ignore files for git
β”œβ”€β”€ README.md        # Project Description
β”œβ”€β”€ analyst.py       # Generate the statistics
β”œβ”€β”€ config.py        # Configuration file for experiment
β”œβ”€β”€ data             # Data for experiment, training classifier and evaluation
β”œβ”€β”€ main.py          # Core file for running the experiment
β”œβ”€β”€ method           # Different CTG methods (including ours)
β”œβ”€β”€ requirements.txt # Required packages
β”œβ”€β”€ results          # Results of the experiment
β”œβ”€β”€ stats            # Statistics of the experiment generated by analyst.py using the results
β”œβ”€β”€ train            # Scripts for training classifiers and other models
└── utils            # Utilities for the project

Usage

Setup

Running Experiments

  1. To run an experiment, use the following command:

    python main.py --model_name <MODEL_NAME> --task_name <TASK_NAME>

    Replace <MODEL_NAME> with one of the available model names: [phi2_3B_Base, llama2_13B_Base, falcon_7B_Base, opt_7B_Base, alpaca_7B_Base] , or more models you set in the config.py.

    Replace <TASK_NAME> with one of the available task names: [toxicMitigation, 2Positive, 2Negative], or more tasks you set in the config.py.

    Example:

    python main.py --model_name phi2_3B_Base --task_name toxicMitigation

Generating Statistics

  1. After running experiments, you can generate statistics by executing:
    python analyst.py

    This will analyze the results and generate statistical data based on the output from the experiments.

HuggingFace models used in our research

Results for Experiment-20240212

Citation

@inproceedings{liang-etal-2024-controlled,
    title = "Controlled Text Generation for Large Language Model with Dynamic Attribute Graphs",
    author = "Liang, Xun and Wang, Hanyu and Song, Shichao and Hu, Mengting and Wang, Xunzhi and Li, Zhiyu and Xiong, Feiyu and Tang, Bo",
    editor = "Ku, Lun-Wei and Martins, Andre and Srikumar, Vivek",
    booktitle = "Findings of the Association for Computational Linguistics ACL 2024",
    month = aug,
    year = "2024",
    address = "Bangkok, Thailand and virtual meeting",
    publisher = "Association for Computational Linguistics",
    url = "https://aclanthology.org/2024.findings-acl.345",
    doi = "10.18653/v1/2024.findings-acl.345",
    pages = "5797--5814",
}