Style2Code: A Dual-Modal Contrastive Learning Framework for Style-Controllable Code Generation | 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 Style2Code: A Dual-Modal Contrastive Learning Framework for Style-Controllable Code Generation Dutao Zhang, Sergey Kovalchuk, YuLong He, Nicolas Arroyo Arias, and 1 more This is a preprint; it has not been peer reviewed by a journal. https://doi.org/ 10.21203/rs.3.rs-8686062/v1 This work is licensed under a CC BY 4.0 License Status: Under Review Version 1 posted 6 You are reading this latest preprint version Abstract Controllable code generation aims to produce source code that adheres to specified style patterns while maintaining functional correctness. This research direction primarily serves scenarios where programmers use code generation models in daily practice, enabling models to better adapt to users' specific project requirements. Additionally, controllable code generation allows models to produce code with more consistent style that aligns closely with developers' coding habits, thereby achieving alignment between model outputs and user coding practices. However, existing methods often rely on multi-model collaborative training, requiring multiple AI systems to mutually correct errors to optimize outputs, which not only increases training and deployment complexity but also limits flexibility and scalability in practical applications. To address this, we propose Style2Code, a novel dual-modal framework for style-controllable code generation. Our approach encodes code style as an explicit 34-dimensional vector representation that captures fine-grained style attributes from three dimensions: naming conventions (14-dim), code spacing layout (9-dim), and structural complexity (11-dim), including aspects such as naming conventions, indentation patterns, and structural layout. Subsequently, this style vector is concatenated with source code tokens and fed into a pre-trained language model (e.g., Flan-T5), enabling the decoder to generate code reflecting the target style. Experimental results on multiple benchmark datasets demonstrate that Style2Code achieves significant improvements in both style alignment and generation quality, outperforming state-of-the-art baseline methods on BLEU, ROUGE, and Code Style Similarity (CSS) metrics. To our knowledge, Style2Code is the first model to achieve explicit and user-controllable code style transfer through continuous vector conditioning in a dual-modal generation framework. Source code and dataset: https://github.com/zh19980811/Style2Code Controllable code generation Code style transfer Style conditioning Interactive programming assistant Full Text Additional Declarations No competing interests reported. Cite Share Download PDF Status: Under Review Version 1 posted Reviews received at journal 07 Apr, 2026 Reviewers agreed at journal 26 Feb, 2026 Reviewers invited by journal 23 Feb, 2026 Editor assigned by journal 29 Jan, 2026 Submission checks completed at journal 27 Jan, 2026 First submitted to journal 24 Jan, 2026 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-8686062","acceptedTermsAndConditions":true,"allowDirectSubmit":false,"archivedVersions":[],"articleType":"Research Article","associatedPublications":[],"authors":[{"id":597805694,"identity":"85cc0824-b1db-4a03-9b21-9e030b39a0e0","order_by":0,"name":"Dutao Zhang","email":"data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAZAAAAAyAQMAAABI0h/eAAAABlBMVEX///8AAABVwtN+AAAACXBIWXMAAA7EAAAOxAGVKw4bAAAA6ElEQVRIiWNgGAWjYDACCcbGBx8qJOTYmJkPgLgyRGhhbjacccbGmI+dLQHE5SFCC3ubNG9bWuI8fh4DEJ+wFvnZjW3SPGcOG7Mx83x+daPGgoeB/fDRDfi0MM452Gw5p+Iw0C+826xzjgEdxpOWdgOfFmaJxMYbb8C28G4zzmEDapHgMcOrhU0isUGCt+1wYhszzzPjnH9EaOGRSGySBHkfqIX5cW4bEVokJBIhgczGzGbGnNsnwcNGyC/yM9IfgqNSvv/w48853+rk+NkPH8OrBdVfYJJY5SDA/IEU1aNgFIyCUTByAAAqXURB4aq61wAAAABJRU5ErkJggg==","orcid":"","institution":"ITMO University","correspondingAuthor":true,"prefix":"","firstName":"Dutao","middleName":"","lastName":"Zhang","suffix":""},{"id":597805695,"identity":"f5f18ae3-19df-4e2b-bc0a-7e3c37104178","order_by":1,"name":"Sergey Kovalchuk","email":"","orcid":"","institution":"ITMO University","correspondingAuthor":false,"prefix":"","firstName":"Sergey","middleName":"","lastName":"Kovalchuk","suffix":""},{"id":597805696,"identity":"a01319b8-ff3f-492d-9a72-dcf5060876a8","order_by":2,"name":"YuLong He","email":"","orcid":"","institution":"St Petersburg University","correspondingAuthor":false,"prefix":"","firstName":"YuLong","middleName":"","lastName":"He","suffix":""},{"id":597805697,"identity":"d3b813ef-8c15-49e9-bacf-cacda2645cf2","order_by":3,"name":"Nicolas Arroyo Arias","email":"","orcid":"","institution":"ITMO University","correspondingAuthor":false,"prefix":"","firstName":"Nicolas","middleName":"Arroyo","lastName":"Arias","suffix":""},{"id":597805698,"identity":"a86f1f74-8d80-4b7d-9532-632a803c2862","order_by":4,"name":"Boyi Li","email":"","orcid":"","institution":"ITMO University","correspondingAuthor":false,"prefix":"","firstName":"Boyi","middleName":"","lastName":"Li","suffix":""}],"badges":[],"createdAt":"2026-01-24 10:55:03","currentVersionCode":1,"declarations":"","doi":"10.21203/rs.3.rs-8686062/v1","doiUrl":"https://doi.org/10.21203/rs.3.rs-8686062/v1","draftVersion":[],"editorialEvents":[],"editorialNote":"","failedWorkflow":false,"files":[{"id":104400511,"identity":"458c00d8-4162-4d75-b7b8-23092c27526d","added_by":"auto","created_at":"2026-03-11 12:10:12","extension":"pdf","order_by":1,"title":"","display":"","copyAsset":false,"role":"manuscript-pdf","size":838911,"visible":true,"origin":"","legend":"","description":"","filename":"style2code2.pdf","url":"https://assets-eu.researchsquare.com/files/rs-8686062/v1_covered_528a1153-ac3b-4d42-b656-f51249a69e11.pdf"}],"financialInterests":"No competing interests reported.","formattedTitle":"\u003cp\u003eStyle2Code: A Dual-Modal Contrastive Learning Framework for Style-Controllable Code Generation\u003c/p\u003e","fulltext":[],"fulltextSource":"","fullText":"","funders":[],"hasAdminPriorityOnWorkflow":false,"hasManuscriptDocX":false,"hasOptedInToPreprint":true,"hasPassedJournalQc":"","hasAnyPriority":false,"hideJournal":false,"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":"automated-software-engineering","isNatureJournal":false,"hasQc":true,"allowDirectSubmit":false,"externalIdentity":"ause","sideBox":"Learn more about [Automated Software Engineering](http://link.springer.com/journal/10515)","snPcode":"10515","submissionUrl":"https://submission.nature.com/new-submission/10515/3","title":"Automated Software Engineering","twitterHandle":"","acdcEnabled":true,"dfaEnabled":true,"editorialSystem":"em","reportingPortfolio":"Springer Hybrid","inReviewEnabled":true,"inReviewRevisionsEnabled":false},"keywords":"Controllable code generation, Code style transfer, Style conditioning, Interactive programming assistant","lastPublishedDoi":"10.21203/rs.3.rs-8686062/v1","lastPublishedDoiUrl":"https://doi.org/10.21203/rs.3.rs-8686062/v1","license":{"name":"CC BY 4.0","url":"https://creativecommons.org/licenses/by/4.0/"},"manuscriptAbstract":"\u003cp\u003eControllable code generation aims to produce source code that adheres to specified style patterns while maintaining functional correctness. This research direction primarily serves scenarios where programmers use code generation models in daily practice, enabling models to better adapt to users' specific project requirements. Additionally, controllable code generation allows models to produce code with more consistent style that aligns closely with developers' coding habits, thereby achieving alignment between model outputs and user coding practices. However, existing methods often rely on multi-model collaborative training, requiring multiple AI systems to mutually correct errors to optimize outputs, which not only increases training and deployment complexity but also limits flexibility and scalability in practical applications. To address this, we propose Style2Code, a novel dual-modal framework for style-controllable code generation. Our approach encodes code style as an explicit 34-dimensional vector representation that captures fine-grained style attributes from three dimensions: naming conventions (14-dim), code spacing layout (9-dim), and structural complexity (11-dim), including aspects such as naming conventions, indentation patterns, and structural layout. Subsequently, this style vector is concatenated with source code tokens and fed into a pre-trained language model (e.g., Flan-T5), enabling the decoder to generate code reflecting the target style. Experimental results on multiple benchmark datasets demonstrate that Style2Code achieves significant improvements in both style alignment and generation quality, outperforming state-of-the-art baseline methods on BLEU, ROUGE, and Code Style Similarity (CSS) metrics. To our knowledge, Style2Code is the first model to achieve explicit and user-controllable code style transfer through continuous vector conditioning in a dual-modal generation framework.\u003c/p\u003e\n\u003cp\u003eSource code and dataset: https://github.com/zh19980811/Style2Code\u003c/p\u003e","manuscriptTitle":"Style2Code: A Dual-Modal Contrastive Learning Framework for Style-Controllable Code Generation","msid":"","msnumber":"","nonDraftVersions":[{"code":1,"date":"2026-03-02 19:48:17","doi":"10.21203/rs.3.rs-8686062/v1","editorialEvents":[{"type":"communityComments","content":0},{"type":"editorInvitedReview","content":"","date":"2026-04-07T17:42:42+00:00","index":"hide","fulltext":""},{"type":"reviewerAgreed","content":"146722124078668668654937422496803588443","date":"2026-02-26T15:36:43+00:00","index":"hide","fulltext":""},{"type":"reviewersInvited","content":"","date":"2026-02-23T13:25:30+00:00","index":"","fulltext":""},{"type":"editorAssigned","content":"","date":"2026-01-29T21:46:55+00:00","index":"","fulltext":""},{"type":"checksComplete","content":"","date":"2026-01-27T11:56:00+00:00","index":"","fulltext":""},{"type":"submitted","content":"Automated Software Engineering","date":"2026-01-24T10:41:55+00:00","index":"","fulltext":""}],"status":"published","journal":{"display":true,"email":"
[email protected]","identity":"automated-software-engineering","isNatureJournal":false,"hasQc":true,"allowDirectSubmit":false,"externalIdentity":"ause","sideBox":"Learn more about [Automated Software Engineering](http://link.springer.com/journal/10515)","snPcode":"10515","submissionUrl":"https://submission.nature.com/new-submission/10515/3","title":"Automated Software Engineering","twitterHandle":"","acdcEnabled":true,"dfaEnabled":true,"editorialSystem":"em","reportingPortfolio":"Springer Hybrid","inReviewEnabled":true,"inReviewRevisionsEnabled":false}}],"origin":"","ownerIdentity":"53d5f4f1-1501-427d-8176-b6a48907f2b7","owner":[],"postedDate":"March 2nd, 2026","published":true,"recentEditorialEvents":[],"rejectedJournal":[],"revision":"","amendment":"","status":"under-review","subjectAreas":[],"tags":[],"updatedAt":"2026-03-02T19:48:17+00:00","versionOfRecord":[],"versionCreatedAt":"2026-03-02 19:48:17","video":"","vorDoi":"","vorDoiUrl":"","workflowStages":[]},"version":"v1","identity":"rs-8686062","journalConfig":"researchsquare"},"__N_SSP":true},"page":"/article/[identity]/[[...version]]","query":{"redirect":"/article/rs-8686062","identity":"rs-8686062","version":["v1"]},"buildId":"XKTyCvWXoU3ODBz1xrDgd","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.