{"title":"Precise length control for large language models","authors":"Bradley Butcher, Michael O’Keefe, James Titchener","doi":"10.1016/j.nlp.2025.100143","DOIUrl":null,"url":null,"abstract":"<div><div>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 brevity 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.</div></div>","PeriodicalId":100944,"journal":{"name":"Natural Language Processing Journal","volume":"11 ","pages":"Article 100143"},"PeriodicalIF":0.0000,"publicationDate":"2025-04-01","publicationTypes":"Journal Article","fieldsOfStudy":null,"isOpenAccess":false,"openAccessPdf":"","citationCount":"0","resultStr":null,"platform":"Semanticscholar","paperid":null,"PeriodicalName":"Natural Language Processing Journal","FirstCategoryId":"1085","ListUrlMain":"https://www.sciencedirect.com/science/article/pii/S2949719125000196","RegionNum":0,"RegionCategory":null,"ArticlePicture":[],"TitleCN":null,"AbstractTextCN":null,"PMCID":null,"EPubDate":"","PubModel":"","JCR":"","JCRName":"","Score":null,"Total":0}
引用次数: 0
Abstract
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 brevity 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.
大型语言模型(llm)越来越多地用于生产系统,为聊天机器人、摘要和问答等应用程序提供支持。尽管他们取得了成功,但控制他们回答的长度仍然是一个重大挑战,特别是对于需要简洁或特定细节级别的任务。在这项工作中,我们提出了一种方法来适应预训练的仅解码器的llm,以精确控制响应长度。我们的方法将二次长度差分位置编码(LDPE)集成到输入嵌入中,该编码计数到用户设置的响应终止长度。使用LDPE进行微调允许模型学习以所需长度连贯地终止响应,实现小于3个令牌的平均令牌误差。我们还介绍了Max New Tokens++,这是一个扩展,支持灵活的上限长度控制,而不是精确的目标。在问答和文档摘要等任务上的实验结果表明,我们的方法可以在不影响响应质量的情况下精确控制长度。