Ruler: A Model-Agnostic Method to Control Generated Length for Large Language Models

Jiaming Li, Lei Zhang, Yunshui Li, Ziqiang Liu, yuelin bai +3 more
9/27/2024
cs.CL

Official code: Geaming2002/Ruler (41 stars, MIT, last commit 2024-09-30).

Abstract

The instruction-following ability of large language models enables humans to interact with AI agents in a natural way. However, when required to generate responses of a specific length, large language models often struggle to meet users' needs due to their inherent difficulty in accurately perceiving numerical constraints. To explore the ability of large language models to control the length of generated responses, we propose the Target Length Generation Task (TLG) and design two metrics, Precise Match (PM) and Flexible Match (FM) to evaluate the model's performance in adhering to specified response lengths. Furthermore, we introduce a novel, model-agnostic approach called Ruler, which employs Meta Length Tokens (MLTs) to enhance the instruction-following ability of large language models under length-constrained instructions. Specifically, Ruler equips LLMs with the ability to generate responses of a specified length based on length constraints within the instructions. Moreover, Ruler can automatically generate appropriate MLT when length constraints are not explicitly provided, demonstrating excellent versatility and generalization. Comprehensive experiments show the effectiveness of Ruler across different LLMs on Target Length Generation Task, e.g., at All Level 27.97 average gain on PM, 29.57 average gain on FM. In addition, we conduct extensive ablation experiments to further substantiate the efficacy and generalization of Ruler. Our code and data is available at https://github.com/Geaming2002/Ruler.

View on arXivView PDF

Code Implementations(1)

Geaming2002/RulerOfficial100%
MIT

Ruler: A Model-Agnostic Method to Control Generated Length for Large Language Models

413Shell, PythonSep 6, 20242 years agoMIT

Similar Papers

Cite this paper

@article{li2024ruler,
  title  = {Ruler: A Model-Agnostic Method to Control Generated Length for Large Language Models},
  author = {Jiaming Li and Lei Zhang and Yunshui Li and Ziqiang Liu and yuelin bai and Run Luo and Longze Chen and Min Yang},
  year   = {2024},
  eprint = {2409.18943},
  archivePrefix = {arXiv},
  url    = {http://arxiv.org/abs/2409.18943v2}
}

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/2409.18943.svg)](https://codeofpaper.com/paper/2409.18943)

Discussion