Style2Code: A dual-modal contrastive learning framework for style-controllable code generation

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

Authors

Institutions

Publication Details

Journal
Automated Software Engineering
Published
2026-11-07
DOI
https://doi.org/10.1007/s10515-026-00704-y
Primary Topic
Software Engineering Research
Type
article
Field-Weighted Citation Impact
0.00
Controls
|||
ALL TIME
JAN
FEB
MAR
APR
MAY
JUN
JUL
AUG
SEP
OCT
NOV
article

Style2Code: A dual-modal contrastive learning framework for style-controllable code generation

Sergey Kovalchuk, Nicolas Rafael Arroyo Arias, Yulong He, Dutao Zhang et al.
3 links
Automated Software Engineering
Software Engineering Research
article

Style2Code: A dual-modal contrastive learning framework for style-controllable code generation

Sergey Kovalchuk, Nicolas Rafael Arroyo Arias, Yulong He, Dutao Zhang, Boyi Li
article en

Abstract

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

Automated Software EngineeringVol. 34(1)
St Petersburg University (RU), ITMO University (RU)
Openalex Percentile: Top 92%
Software Engineering Research
AI Navigator

Ask Laika to Summarize, Analyze, and Connect papers live on the map.

Summarize Papers & Methodologies

Extract key findings, datasets, and comparative methods across publications.

Benchmark Rankings & Visual Analytics

Rank top research institutions, authors, funders, topics, and journals by Field-Weighted Citation Impact (FWCI) and paper volume with instant charts.

Connect Distant Disciplines

Bridge topological clusters on the map to find hidden collaborative intersections.

Laika access coming soon