We use a few cookies

Essential cookies keep the library working. With your permission, we'd also like to use analytics to see what's useful and improve the experience. Read our Privacy Policy or Cookie Policy.

Skip to main content
Home/e-Resources/Artificial Intelligence & Machine Learning/Precise length control for large language models
PeriodicalsArtificial Intelligence & Machine Learning

Precise length control for large language models

Checking your access to this record.

Abstract & Overview

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.

Cite this record

Bradley Butcher, Michael O’Keefe, James Titchener (2025). Precise length control for large language models. Natural Language Processing Journal, 11, 100143–100143. https://doi.org/10.1016/j.nlp.2025.100143

Copy in another style

Butcher, B., O’Keefe, M., & Titchener, J. (2025). Precise length control for large language models. Natural Language Processing Journal, 11, 100143–100143. https://doi.org/10.1016/j.nlp.2025.100143
Author names are used as deposited, so check their order before you submit.

Metadata is harvested from open-access indexes and can be incomplete. Check a citation against the published version before relying on it — see our open access & attribution policy.