Hansel: Output Length Controlling Framework for Large Language Models

Seoha Song, Junhyun Lee, Hyeonmok Ko · 2024

Read Hansel: Output Length Controlling Framework for Large Language Models by Seoha Song, Junhyun Lee, Hyeonmok Ko (2024) in the Tower of Babel, a free online library of public-domain works preserved in clean, searchable text. No sign-up. The full text is served as a plain-text file at a predictable URL, where text is present: https://antarctic-labs.com/tower-of-babel/arxiv-2412-14033.txt.

Introduction

Seoha Song, Junhyun Lee, and Hyeonmok Ko rein in the length of chat model output in a 2024 paper. Length control is a known weak spot for such models, in spite of their wide wins. Their frame slips marked bits into the stream at set gaps to count down the room left.

Tricks in the frame bar a hard stop at the count's end, which keeps text smooth and whole. The frame fits any base model at tune time, what-ever its place code. Four tuned models show tight length calls in the tests.

Catalog record

CREATORSeoha Song, Junhyun Lee, Hyeonmok Ko
YEAR2024
COLLECTIONPAPERS
FORMATTXT
FILE SIZE46 KB
VERSION1.0
LICENSEhttp://creativecommons.org/licenses/by/4.0/
RIGHTSCC BY
SOURCEarXiv

Source: https://arxiv.org/abs/2412-14033

Browse the full library · About the Tower of Babel

Full text

The opening of the work, from the library's hosted text:

Hansel: Output Length Controlling Framework for Large Language Models Seoha Song, Junhyun Lee, Hyeonmok Ko Abstract Despite the great success of large language models (LLMs), efficiently controlling the length of the output sequence still remains a challenge. In this paper, we propose Hansel, an efficient framework for length control in LLMs without affecting its generation ability. Hansel utilizes periodically outputted hidden special tokens to keep track of the remaining target length of the output sequence. Together with techniques to avoid abrupt termination of the output, this seemingly simple method proved to be efficient and versatile, while not harming the coherency and fluency of the generated text. The framework can be applied to any pre-trained LLMs during the finetuning stage of the model, regardless of its original positional encoding method. We demonstrate this by finetuning four different LLMs with Hansel and show that the mean absolute error of the output sequence decreases significantly in every model and dataset compared to the prompt-based length control finetuning. Moreover, the framework showed a substantially improved ability to extrapolate to target lengths unseen during finetuning, such as long dialog responses or extremely short summaries. This indicates that the model learns the general means of length control, rather than learning to match output lengths to those seen during training. Introduction How many words are there in the following: ”The visualizations help readers understand the concept.” There are 10 words in the sentence ”The visualizations help readers understand the concept.” Why don’t you try again? Maybe by counting the words one by one. Sure, here’s another attempt at counting the words in the sentence ”The visualizations and examples in this paper help readers understand the concept”: 1 . The 2 . visualizations 3 . help 4 . readers 5 . understand 6 . the 7 . concept There are 7 words in total. Figure 1: An example conversation with GPT. We have edited the example sentence for brevity. Large language models (LLMs) have shown great promise in generating coherent and fluent text, making them useful for a variety of tasks ( Arivazhagan et al. 2019 ; Karpukhin et al. 2020 ; Lewis et al. 2020 ; Zhang et al. 2020 ) . However, a number of challenges still remain for LLMs, including the difficulty of efficiently controlling the length of the output sequence. Length control of the output sequence has practical importance in the real-world application of LLMs. Setting the length determines the level of details to include in the output, which is desired both in the aspect of content and system interface. While this task seems relatively mundane compared to the emergent abilities of LLMs, to the best of our knowledge length control has yet to be achieved even for the larger LLMs ( Achiam et al. 2023 ; Anil et al. 2023 ; Touvron et al. 2023 ) with hundreds of billions of parameters. A couple of specific examples where length control is useful would be i) a news app where articles are accompanied by AI-generated summaries, or ii) a voice assistant that can tune the amount of information to be spoken. For the news app, the default length should be concise enough to fit the system interface, and the user may want to tune the summarization length to include or drop details. Even for simple voice assistant tasks such as telling the weather, “rain at noon” may be sufficient but sometimes precipitation or temperature might be needed. These examples show the benefits of various outputs from the identical input and controlling them is important and useful. The study of length control dates back to the pre-transformer era. Kikuchi et al. 2016 first suggested feeding the remaining length information to the LSTM as an embedding or the memory cell. After the advent of the transformer ( Vaswani et al. 2017 ) , there were attempts to include the length information in a modified form of positional encoding ( Takase and Okazaki 2019 ) . Other studies turn to the attention mechanism such as Length Attention ( Yu et al. 2021 ) and Length-Aware Attention ( Liu, Jia, and Zhu 2022 ) . Although the previous methods of length control were fairly successful, they mostly concentrate on the relatively small sequence-to-sequence models ( Sutskever, Vinyals, and Le 2014 ) and not the nowadays prevalent decoder models. The main reason for this is two-fold. First, the aforementioned methods require application in the pretraining stage and show significant performance degradation when used only while finetuning. Large decoder models are mostly pre-trained once as a foundation model and finetuned for downstream tasks due to their large size, making the previous methods inapplicable. Second, with their better understanding of the context, the decoder models have some, although imperfect, length-controlling ability. The decoder LLMs would not output the exact required length, for example, 17 words, but it does understand commands such as shorter/longer and will tend to output longer texts when specified to output 25 words than when asked for 10 words. In this paper, we introduce a simple finetuning framework to improve the output length-controlling ability of LLMs. We first observe why generating outputs with a certain length is a difficult task for LLMs. LLMs are known to have limited mathematical ability even with the significant improvement from the zero-shot-CoT technique ( Kojima et al. 2022 ) . This not only applies to complex math problems but also to simple counting. Figure 1 shows a short example conversation with GPT 1 1 1 We have used GPT-3.5 to generate the example. GPT-4 can generate similar conversations by explicitly instructing not to call Python scripts. , slightly edited for brevity. Because LLMs are not intrinsic counters, GPT sometimes outputs incorrect answers when asked to answer the number of words in a sentence. One way to correct this behavior is to prompt the model to explicitly count the words first and then output the answer as in Figure 1 . We build upon this observation and apply it to the task of output length control. With its lack of counting ability, the model would not be aware of how many words it has output and how many words are left at a certain point. To overcome this, we introduce the Hansel – H idden A rrangements (of special tokens) in N atural S equence for E xpected L ength – framework, which directly injects the information via the form of hidden special tokens. By augmenting a finetuning dataset with special tokens appearing regularly, the model can efficiently learn the relative position compared to the target length at a given time. This can be considered a simple hard-coded CoT method specifically for output length control. Our method performs well even when only used during finetuning without degradation in output quality. Phi2 ( Li et al. 2023 ) based Hansel model showed great performance in mean absolute error from the reference length in four summarization and dialogue datasets (Table 1 ). Moreover, the error remains small for a wide range of arbitrary target lengths, where other methods diverge rapidly as the target length deviates from the dataset’s typical length (Figure 3 ). Contribution The main contributions of this paper are as follows: • We

Read the complete text