本文提出通过引入长度差位置编码(LDPE)和Max New Tokens++扩展,使大型语言模型能够精确或按上限控制响应长度,在问答和摘要任务中实现平均误差小于3个令牌且不损失质量。
摘要:
大型语言模型(LLMs)越来越多地用于生产系统,为聊天机器人、摘要生成和问答等应用提供支持。尽管它们取得了成功,但控制其响应长度仍然是一个重大挑战,尤其是对于需要结构化输出或特定细节程度的任务。在这项工作中,我们提出了一种方法,用于调整预训练的解码器型LLMs以实现响应长度的精确控制。我们的方法将一种次级长度差位置编码(LDPE)引入输入嵌入中,该编码会倒数至用户设定的响应终止长度。使用LDPE进行微调使模型能够学会在所需长度处连贯地终止响应,实现平均令牌误差小于3个令牌。我们还引入了Max New Tokens++,这是一种扩展,可实现灵活的上限长度控制,而非精确目标。在问答和文档摘要等任务上的实验结果表明,我们的方法能够在不损害响应质量的情况下实现精确的长度控制。
英文摘要:
Large Language Models (LLMs) are increasingly used in production systems, powering applications such as chatbots, summarization, and question answering. Despite their success, controlling the length of their response remains a significant challenge, particularly for tasks requiring structured outputs or specific levels of detail. In this work, we propose a method to adapt pre-trained decoder-only LLMs for precise control of response length. Our approach incorporates a secondary length-difference positional encoding (LDPE) into the input embeddings, which counts down to a user-set response termination length. Fine-tuning with LDPE allows the model to learn to terminate responses coherently at the desired length, achieving mean token errors of less than 3 tokens. We also introduce Max New Tokens++, an extension that enables flexible upper-bound length control, rather than an exact target. Experimental results on tasks such as question answering and document summarization demonstrate that our method enables precise length control without compromising response quality.
Length-controllable Abstractive Summarization by Guiding with Summary Prototype
NTT Media Intelligence Laboratories(日本电信电话公司媒体智能实验室);NTT Corporation(日本电信电话公司);Nara Institute of Science Technology(奈良先端科学技术大学院大学);RIKEN Center for Advanced Intelligence Project(理化学研究所先进智能项目中心)
A Decoding Algorithm for Length-Control Summarization Based on Directed Acyclic Transformers
University of Alberta(阿尔伯塔大学);Alberta Machine Intelligence Institute (Amii)(阿尔伯塔机器智能研究所(Amii));Institute for AI Industry Research (AIR), Tsinghua University(清华大学人工智能产业研究院(AIR))
Evaluating the Efficacy of Length-Controllable Machine Translation
Academy for Advanced Interdisciplinary Studies, Peking University(北京大学前沿交叉学科研究院);Huawei Noah’s Ark Lab(华为诺亚方舟实验室);Artificial Intelligence Application Research Center, Huawei Technologies(华为技术有限公司人工智能应用研究中心);School of Mathematical Sciences, Peking University(北京大学数学科学学院)