Style2Code: A dual-modal contrastive learning framework for style-controllable code generation
Dutao Zhang, Yulong He, Nicolas Rafael Arroyo Arias, Boyi Li, Sergey Kovalchuk
ITMO University · St Petersburg University
Key points
From the paper's conclusion- 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.
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
Read the paper
Discussion
Science Skim's AI key points, plus readers' public thoughts
Readers' thoughts
No reader thoughts yet.
Related papers
- Self-Adaptive Code Representation: Grammar-Guided or Token-Based?Proceedings of the ACM on Software Engineering · 2026
- DivAlgo: A systematic evaluation of algorithmic diversity for code generation modelsarXiv · 2026
- Towards Practical Automata-Based Steering of Large Language Models for Diverse Structured GenerationFormal Aspects of Computing · 2026
- LLMs program using Reusable and Composable Abstract RepresentationsarXiv · 2026
- Option-GRPO: Hierarchical RL Against AI Slop in Code Generation for Unseen SDKsarXiv · 2026
- Predicting Steering Vectors and Adapter Weights for Few-Shot Author-Style TransferarXiv · 2026