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

Controllable code generation aims to move source code toward a target coding style while preserving program behavior. Direct prompting may neither describe fine-grained style precisely nor reliably perform the requested transformation; it can preserve the source and achieve high correctness without effective style transfer. We propose Style2Code, a dual-modal framework that extracts an explicit 34-dimensional target-style profile spanning naming, layout, and function-level structure. A lightweight style encoder and contrastive learning align this profile with code representations before generation. Experiments on five synthetic and human-written benchmarks assess reference and source-relative style similarity, static and execution correctness, and copying. In controlled comparisons, Style2Code improves lexical reference similarity and target-style alignment over its backbone and same-backbone trained alternatives. Style2Code-9B achieves positive mean source-relative style improvement on all five datasets and lower copy rates than untuned Qwen Prompt and the evaluated API models, indicating active migration rather than source preservation alone. These gains do not consistently extend to CodeBLEU, static quality, Syntax, or Pass@1 because active style modification can introduce parsing, execution, and behavioral errors. Test-time repair recovers many failures but may increase source retention and is reported separately. Style2Code provides an interpretable mechanism for quantifiable, non-copy style transfer, while reliable function preservation remains an open challenge.

Link
https://www.semanticscholar.org/paper/5fcb0f1143f71b66f126f4fcb4375b9fc33e1604
Found by
Semantic Scholar
Authors
Du-Tao Zhang, Yulong He, Nicolas Rafael Arroyo Arias, Bo Li, S. Kovalchuk, Dutao Zhang, Boyi Li, Sergey Kovalchuk
Organizations
ITMO University, St Petersburg University
Categories
benchmark, evaluation, dataset
Published
2026-11-07
Last seen by the radar
2026-11-09
Citations
0
Influential citations
0
Radar score
44.25 / 100 (how it is scored)
Why it scored so
Also found via OpenAlex; Matched: benchmark, dataset, evaluat; Primary record: Semantic Scholar
Related links
https://doi.org/10.1007/s10515-026-00704-y
https://www.researchsquare.com/article/rs-8686062/latest.pdf
Is this record right? If you made this work and something here is wrong or missing, tell us what to fix.

More records found by Semantic Scholar