arXiv:2508.13805cs.CLcs.AI2025-08被引 6

用提示词让大模型精准生成指定字数内容,无需微调

Prompt-Based One-Shot Exact Length-Controlled Generation with LLMs

  • 通过添加倒计时标记和计数规则,让模型边写边数
  • 在MT-Bench-LI任务中,严格符合长度要求的比例从不足30%提升至95%以上
  • 无需训练或迭代采样,适合对输出长度有精确要求的场景

控制大语言模型(LLMs)生成文本的长度仍具挑战:模型常超出或未达明确长度指令,因无法可靠维持内部词元计数。本文提出一种基于提示词的一次性策略,使现成的LLM在不进行微调或迭代采样的情况下,精确生成指定数量的词元(英文为词,中文为字符)。提示词通过追加倒计时标记和显式计数规则,引导模型“边写边数”。我们在四种设置下评估:开放式生成(1-1000词元)、XSUM摘要、MT-Bench-LI指令遵循及LIFEBENCH等长赛道。在MT-Bench-LI任务中,使用GPT-4.1时,严格符合长度要求的比例从原始提示下的低于30%跃升至95%以上,优于常见的先草稿再修订基线,且生成答案质量保持不变。结果表明,仅通过提示工程即可实现精确长度控制,为训练或解码方法提供了轻量级替代方案。

原文摘要 · Abstract (English)

Controlling the length of text produced by large language models (LLMs) remains challenging: models frequently overshoot or undershoot explicit length instructions because they cannot reliably keep an internal token count. We present a prompt-based, one-shot strategy that compels an off-the-shelf LLM to generate exactly a desired number of tokens - words (English) or characters (Chinese) - without any fine-tuning or iterative sampling. The prompt appends countdown markers and explicit counting rules so that the model "writes while counting." We evaluate on four settings: open-ended generation (1-1000 tokens), XSUM summarization, MT-Bench-LI instruction following, and the LIFEBENCH equal-length track. On MT-Bench-LI, strict length compliance with GPT-4.1 leaps from below 30% under naive prompts to above 95% with our countdown prompt, surpassing the popular draft-then-revise baseline, while judged answer quality is preserved. These results show that precise length control can be achieved through prompt engineering alone, offering a lightweight alternative to training- or decoding-based methods.

长度控制提示工程大模型生成精度

Thank you to arXiv for use of its open access interoperability. PaperDance 不是 arXiv 官方产品;中文卡片由大模型生成,请以原文为准。