A Plug-and-Play Method for Controlled Text Generation

Damian Pascual, Beni Egressy, Clara Meister, Ryan Cotterell, Roger Wattenhofer
9/20/2021
cs.CLcs.AI

Official code: dapascual/K2T (69 stars, Python, last commit 2021-10-29).

Abstract

Large pre-trained language models have repeatedly shown their ability to produce fluent text. Yet even when starting from a prompt, generation can continue in many plausible directions.

Show full abstract

Current decoding methods with the goal of controlling generation, e.g., to ensure specific words are included, either require additional models or fine-tuning, or work poorly when the task at hand is semantically unconstrained, e.g., story generation. In this work, we present a plug-and-play decoding method for controlled language generation that is so simple and intuitive, it can be described in a single sentence: given a topic or keyword, we add a shift to the probability distribution over our vocabulary towards semantically similar words. We show how annealing this distribution can be used to impose hard constraints on language generation, something no other plug-and-play method is currently able to do with SOTA language generators. Despite the simplicity of this approach, we see it works incredibly well in practice: decoding from GPT-2 leads to diverse and fluent sentences while guaranteeing the appearance of given guide words. We perform two user studies, revealing that (1) our method outperforms competing methods in human evaluations; and (2) forcing the guide words to appear in the generated text has no impact on the fluency of the generated text.

View on arXivView PDF

Code Implementations(1)

dapascual/K2TOfficial100%
6911Python, ShellSep 3, 20215 years ago

Similar Papers

Cite this paper

@article{pascual2021plugandplay,
  title  = {A Plug-and-Play Method for Controlled Text Generation},
  author = {Damian Pascual and Beni Egressy and Clara Meister and Ryan Cotterell and Roger Wattenhofer},
  year   = {2021},
  eprint = {2109.09707},
  archivePrefix = {arXiv},
  url    = {https://arxiv.org/abs/2109.09707}
}

Add a badge to your README

Shows whether official code is linked for this paper.

Code of Paper badge
[![Code of Paper](https://codeofpaper.com/badge/2109.09707.svg)](https://codeofpaper.com/paper/2109.09707)

Discussion