Switch-GPT: An Effective Method for Constrained Text Generation under Few-Shot Settings (Student Abstract)

Chang Ma, Song Zhang, Gehui Shen, Zhihong DengAAAI 2022

Abstract

In real-world applications of natural language generation, target sentences are often required to satisfy some lexical constraints. However, the success of most neural-based models relies heavily on data, which is infeasible for data-scarce new domains. In this work, we present FewShotAmazon, the first benchmark for the task of Constrained Text Generation under few-shot settings on multiple domains. Further, we propose the Switch-GPT model, in which we utilize the strong language modeling capacity of GPT-2 to generate fluent and well-formulated sentences, while using a light attention module to decide which constraint to attend to at each step. Experiments show that the proposed Switch-GPT model is effective and remarkably outperforms the baselines.

Introduction

Constrained Text Generation (CTG) requires a model to produce fluent sentences that incorporate a specific set of keywords or phrases. While existing models perform well in data-rich environments, they are notoriously "data-hungry." For instance, the POINTER model typically requires around 160,000 fine-tuning samples to reach peak performance. In many real-world scenarios—such as specialized medical domains or new product categories—collecting such massive datasets is impossible. This research addresses the "few-shot" challenge: generating high-quality constrained text using as few as 100 or 200 training examples.

Methodology: The Switch-GPT Framework

Switch-GPT splits the generation process into two distinct but collaborative components to maximize performance in data-scarce environments.

The Switch-GPT architecture, featuring a 'Switch with Attention' module that selects constraints and a 'Conditional Generator' based on GPT-2.
  1. The Language Backbone: The model utilizes a pre-trained GPT-2 backbone. This leverages the extensive prior knowledge the model has about English grammar and syntax, ensuring the output is fluent even with minimal fine-tuning.
  2. The Switch Module (Hard Attention): This is the core innovation. Most attention mechanisms use "soft attention," which creates a weighted average of all possible constraints. The authors argue this "blurs" the representation, making it hard for the model to focus on a specific word. Instead, Switch-GPT uses hard attention to select a specific constraint at each step, avoiding the "convex hull" problem where weighted sums land on meaningless points in the hidden space.
  3. The Copy-Generate Switch: The model decides at each time step whether to "copy" a specific constraint into the sentence or "generate" a transition word (like "and," "is," or "with") to link the constraints together.

FewShotAmazon Benchmark

The paper introduces FewShotAmazon, a new benchmark to test few-shot capabilities across five domains: Books, Clothing, Music, Movies, and Electronics. Unlike traditional datasets with hundreds of thousands of samples, this benchmark provides only 200 training samples per domain. Keywords were extracted using dependency parsing to ensure they represent meaningful entities rather than random words.

Key Results and Insights

Switch-GPT demonstrates a massive performance leap over baselines like POINTER and the standard Switch-LSTM.

Performance metrics across five domains. Switch-GPT achieves 100% coverage and significantly higher BLEU scores than all baselines.
  • 100% Coverage: Switch-GPT achieved perfect keyword coverage across all five Amazon domains, meaning it never missed a required keyword. Baselines struggled to stay above 90% in the few-shot setting.
  • Fluency and Cohesion: In the "Books" domain, Switch-GPT reached a BLEU score of 24.15, while POINTER lagged at 8.68. The authors also utilized a ΔBLEU metric to confirm that the model connects keywords smoothly rather than just "dumping" them into a list.
  • Extreme Data Efficiency: The most striking insight is the efficiency of pre-training. By effectively "steering" GPT-2, the model achieves better results with 50 samples (average BLEU 17.42) than previous models did with 20,000 samples (average BLEU 10.74).

Conclusion

Switch-GPT provides a robust solution for constrained text generation in data-scarce environments. By combining a large pre-trained model with a lightweight hard-attention switch, it achieves perfect constraint satisfaction and high fluency with minimal training data. Future work will explore applying this paradigm to other few-shot NLP tasks beyond text generation.

Summary updated

BibTeX
@inproceedings{ma2022switch,
  author = {Chang Ma and Song Zhang and Gehui Shen and Zhihong Deng},
  title = {{Switch-GPT: An Effective Method for Constrained Text Generation under Few-Shot Settings (Student Abstract)}},
  booktitle = {AAAI Conference on Artificial Intelligence},
  year = {2022},
  url = {https://openreview.net/forum?id=x06mqR8x4k},
}
Figure