A Token-Agnostic Approach to Controlling Generated Text Length in Large Language Models | Research Square window.SnipcartSettings = { analytics: { enabled: false } }; (function() { var accessVector = localStorage.getItem('access_vector') || ''; window.dataLayer = window.dataLayer || []; if (accessVector) { window.dataLayer.push({ user: { profile: { profileInfo: { snid: accessVector } } } }); } })(); (function(w,d,s,l,i){w[l]=w[l]||[];w[l].push({'gtm.start':new Date().getTime(),event:'gtm.js'});var f=d.getElementsByTagName(s)[0],j=d.createElement(s),dl=l!='dataLayer'?'&l='+l:'';j.async=true;j.src='https://www.googletagmanager.com/gtm.js?id='+i+dl;f.parentNode.insertBefore(j,f);})(window,document,'script','dataLayer','GTM-K279D39R'); Browse Preprints In Review Journals COVID-19 Preprints AJE Video Bytes Research Tools Research Promotion AJE Professional Editing AJE Rubriq About Preprint Platform In Review Editorial Policies Our Team Advisory Board Help Center Sign In Submit a Preprint Cite Share Download PDF Research Article A Token-Agnostic Approach to Controlling Generated Text Length in Large Language Models Kiannah Foster, Andrew Johansson, Elizabeth Williams, Daniel Petrovic, and 1 more This is a preprint; it has not been peer reviewed by a journal. https://doi.org/ 10.21203/rs.3.rs-5204102/v1 This work is licensed under a CC BY 4.0 License Status: Posted Version 1 posted You are reading this latest preprint version Abstract The rapid expansion of language models has led to increased demand for precise control over text generation, particularly in terms of output length. Traditional token-based methods often struggle with consistency across languages and text coherence, presenting challenges in tasks that require strict length adherence. A novel token-agnostic approach has been developed to address these limitations, leveraging semantic structures such as sentences and paragraphs to manage length dynamically. Through this method, text generation becomes more flexible and adaptable to a variety of languages and writing styles, ensuring that length constraints are respected without sacrificing fluency or relevance. Experimental results demonstrate the effectiveness of the method when implemented with Llama, yielding high precision in length adherence and text quality across multiple evaluation metrics. This approach offers a robust solution to the ongoing challenge of managing output length in text generation, with potential applications spanning numerous domains, from summarization to content creation. Artificial Intelligence and Machine Learning Length control text generation token-agnostic multilingual semantic structures Full Text Additional Declarations The authors declare no competing interests. Cite Share Download PDF Status: Posted Version 1 posted You are reading this latest preprint version Research Square lets you share your work early, gain feedback from the community, and start making changes to your manuscript prior to peer review in a journal. As a division of Research Square Company, we’re committed to making research communication faster, fairer, and more useful. We do this by developing innovative software and high quality services for the global research community. Our growing team is made up of researchers and industry professionals working together to solve the most critical problems facing scientific publishing. Also discoverable on Platform About Our Team In Review Editorial Policies Advisory Board Help Center Resources Author Services Accessibility API Access RSS feed Manage Cookie Preferences © Research Square 2026 | ISSN 2693-5015 (online) Privacy Policy Terms of Service Do Not Sell My Personal Information {"props":{"pageProps":{"initialData":{"identity":"rs-5204102","acceptedTermsAndConditions":true,"allowDirectSubmit":true,"archivedVersions":[],"articleType":"Research Article","associatedPublications":[],"authors":[{"id":362299353,"identity":"7551ef7c-f616-4c48-b7f6-6ec59a6bf479","order_by":0,"name":"Kiannah Foster","email":"data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAZAAAAAyAQMAAABI0h/eAAAABlBMVEX///8AAABVwtN+AAAACXBIWXMAAA7EAAAOxAGVKw4bAAAA8ElEQVRIiWNgGAWjYBACCWYwdcCOn4eHgYGxQYKBj1gtyZI9UC1sBLVAqAOMG86AtTAQ1iLZzvzscUHNHWbjM2ePSXzcYSHPxt7A+OFjDm4t0sxs5sYzjj3jMzvblyY584yEYRvPAWbJmdtwa5FjZjCT5mE7zGx2nsfYmLdNIoENiJh58Wph/ybN8+8w4+Z+oJa/IC3yD/BrkWbmMZPmbTvMuIG3x/AxI9gWBvxaJJt5yqR5+w4nS5w5l/iwtw3kl8RmvH6ROH98mzTPt8N2/D25Bw78bKuT52c/fPDDRzxasAFQ7IyCUTAKRsEooAgAAAOaSCq0p9XoAAAAAElFTkSuQmCC","orcid":"https://orcid.org/0009-0003-7376-7982","institution":"","correspondingAuthor":true,"prefix":"","firstName":"Kiannah","middleName":"","lastName":"Foster","suffix":""},{"id":362299354,"identity":"06cdad37-6fbb-4d2b-bdaf-fc7c3f05b331","order_by":1,"name":"Andrew Johansson","email":"","orcid":"","institution":"","correspondingAuthor":false,"prefix":"","firstName":"Andrew","middleName":"","lastName":"Johansson","suffix":""},{"id":362299355,"identity":"eb526897-b606-41a3-8279-37dfd8e38a1d","order_by":2,"name":"Elizabeth Williams","email":"","orcid":"","institution":"","correspondingAuthor":false,"prefix":"","firstName":"Elizabeth","middleName":"","lastName":"Williams","suffix":""},{"id":362299356,"identity":"f8e89a39-2dac-402b-a323-0f370b268e9d","order_by":3,"name":"Daniel Petrovic","email":"","orcid":"","institution":"","correspondingAuthor":false,"prefix":"","firstName":"Daniel","middleName":"","lastName":"Petrovic","suffix":""},{"id":362299357,"identity":"a7be6ad7-e534-4ddc-b73e-f5563d03d7aa","order_by":4,"name":"Nicholas Kovalenko","email":"","orcid":"","institution":"","correspondingAuthor":false,"prefix":"","firstName":"Nicholas","middleName":"","lastName":"Kovalenko","suffix":""}],"badges":[],"createdAt":"2024-10-04 12:56:24","currentVersionCode":1,"declarations":{"humanSubjects":false,"vertebrateSubjects":false,"conflictsOfInterestStatement":false,"humanSubjectEthicalGuidelines":false,"humanSubjectConsent":false,"humanSubjectClinicalTrial":false,"humanSubjectCaseReport":false,"vertebrateSubjectEthicalGuidelines":false},"doi":"10.21203/rs.3.rs-5204102/v1","doiUrl":"https://doi.org/10.21203/rs.3.rs-5204102/v1","draftVersion":[],"editorialEvents":[],"editorialNote":"","failedWorkflow":false,"files":[{"id":66168973,"identity":"f2e8d4a7-2b6c-4671-8db3-6d2b74d49e9e","added_by":"auto","created_at":"2024-10-08 10:22:33","extension":"pdf","order_by":1,"title":"","display":"","copyAsset":false,"role":"manuscript-pdf","size":207955,"visible":true,"origin":"","legend":"","description":"","filename":"LLM.pdf","url":"https://assets-eu.researchsquare.com/files/rs-5204102/v1_covered_cd58b8d9-d613-46cd-a17c-0136ea4e3eb2.pdf"}],"financialInterests":"The authors declare no competing interests.","formattedTitle":"\u003cp\u003eA Token-Agnostic Approach to Controlling Generated Text Length in Large Language Models\u003c/p\u003e","fulltext":[],"fulltextSource":"","fullText":"","funders":[],"hasAdminPriorityOnWorkflow":false,"hasManuscriptDocX":false,"hasOptedInToPreprint":true,"hasPassedJournalQc":"","hasAnyPriority":true,"hideJournal":true,"highlight":"","institution":"","isAcceptedByJournal":false,"isAuthorSuppliedPdf":true,"isDeskRejected":"","isHiddenFromSearch":false,"isInQc":false,"isInWorkflow":false,"isPdf":true,"isPdfUpToDate":true,"isWithdrawnOrRetracted":false,"journal":{"display":true,"email":"
[email protected]","identity":"researchsquare","isNatureJournal":false,"hasQc":true,"allowDirectSubmit":true,"externalIdentity":"","sideBox":"","snPcode":"","submissionUrl":"/submission","title":"Research Square","twitterHandle":"researchsquare","acdcEnabled":true,"dfaEnabled":false,"editorialSystem":"","reportingPortfolio":"","inReviewEnabled":false,"inReviewRevisionsEnabled":true},"keywords":"Length control, text generation, token-agnostic, multilingual, semantic structures","lastPublishedDoi":"10.21203/rs.3.rs-5204102/v1","lastPublishedDoiUrl":"https://doi.org/10.21203/rs.3.rs-5204102/v1","license":{"name":"CC BY 4.0","url":"https://creativecommons.org/licenses/by/4.0/"},"manuscriptAbstract":"\u003cp\u003eThe rapid expansion of language models has led to increased demand for precise control over text generation, particularly in terms of output length. Traditional token-based methods often struggle with consistency across languages and text coherence, presenting challenges in tasks that require strict length adherence. A novel token-agnostic approach has been developed to address these limitations, leveraging semantic structures such as sentences and paragraphs to manage length dynamically. Through this method, text generation becomes more flexible and adaptable to a variety of languages and writing styles, ensuring that length constraints are respected without sacrificing fluency or relevance. Experimental results demonstrate the effectiveness of the method when implemented with Llama, yielding high precision in length adherence and text quality across multiple evaluation metrics. This approach offers a robust solution to the ongoing challenge of managing output length in text generation, with potential applications spanning numerous domains, from summarization to content creation.\u003c/p\u003e","manuscriptTitle":"A Token-Agnostic Approach to Controlling Generated Text Length in Large Language Models","msid":"","msnumber":"","nonDraftVersions":[{"code":1,"date":"2024-10-08 10:14:27","doi":"10.21203/rs.3.rs-5204102/v1","editorialEvents":[{"type":"communityComments","content":0}],"status":"published","journal":{"display":true,"email":"
[email protected]","identity":"researchsquare","isNatureJournal":false,"hasQc":true,"allowDirectSubmit":true,"externalIdentity":"","sideBox":"","snPcode":"","submissionUrl":"/submission","title":"Research Square","twitterHandle":"researchsquare","acdcEnabled":true,"dfaEnabled":false,"editorialSystem":"","reportingPortfolio":"","inReviewEnabled":false,"inReviewRevisionsEnabled":true}}],"origin":"","ownerIdentity":"6b1b3756-025b-4100-ba5e-db09c991c742","owner":[],"postedDate":"October 8th, 2024","published":true,"recentEditorialEvents":[],"rejectedJournal":[],"revision":"","amendment":"","status":"posted","subjectAreas":[{"id":38546677,"name":"Artificial Intelligence and Machine Learning"}],"tags":[],"updatedAt":"2024-10-08T10:14:27+00:00","versionOfRecord":[],"versionCreatedAt":"2024-10-08 10:14:27","video":"","vorDoi":"","vorDoiUrl":"","workflowStages":[]},"version":"v1","identity":"rs-5204102","journalConfig":"researchsquare"},"__N_SSP":true},"page":"/article/[identity]/[[...version]]","query":{"redirect":"/article/rs-5204102","identity":"rs-5204102","version":["v1"]},"buildId":"qtupq5eGEP_6zYnWcrvyt","isFallback":false,"isExperimentalCompile":false,"dynamicIds":[84888],"gssp":true,"scriptLoader":[]}
Text is read by the "Ask this paper" AI Q&A widget below.
Extraction quality varies by source — PMC NXML preserves structure
cleanly, OA-HTML may include some navigation residue, and OA-PDF can
have broken hyphenation. The publisher copy
(via DOI)
is the canonical version.