MPCoder: Multi-user Personalized Code Generator with Explicit and Implicit Style Representation Learning

Zhenlong Dai, Chang Yao, WenKang Han, Yuanying Yuanying, Zhipeng Gao, Jingyuan Chen

Abstract

Large Language Models (LLMs) have demonstrated great potential for assisting developers in their daily development. However, most research focuses on generating correct code; how to use LLMs to generate personalized code has seldom been investigated. To bridge this gap, we proposed MPCoder (Multi-user Personalized Code Generator) to generate personalized code for multiple users. To better learn coding style features, we utilize explicit coding style residual learning to capture syntax code style standards and implicit style learning to capture semantic code style conventions. We train a multi-user style adapter to better differentiate the implicit feature representations of different users through contrastive learning, ultimately enabling personalized code generation for multiple users. We further propose a novel evaluation metric for estimating similarities between codes of different coding styles. Experimental results show the effectiveness of our approach for this novel task.

Introduction

While modern LLMs like CodeLlama excel at generating functionally correct code, they are generally "style-blind." Developers and organizations often adhere to specific coding standards—ranging from syntactic formatting (e.g., brace placement) to semantic naming conventions. Currently, achieving personalization requires either tedious prompt engineering or prohibitively expensive per-user fine-tuning. MPCoder addresses these challenges by enabling a single LLM to generate code tailored to the unique styles of multiple users simultaneously without the massive computational overhead of individual models.

Methodology

MPCoder employs a two-pronged approach to capture the dual nature of coding style:

  1. Explicit Coding Style Learning: The framework utilizes Checkstyle to identify 25 specific syntax attributes. To enhance learning, MPCoder uses Residual Learning, training the model on pairs of code snippets to identify specific stylistic differences. This makes the resulting representations significantly more precise than standard prompting.
  2. Implicit Coding Style Learning: To capture subtle semantic habits, such as logic structuring, MPCoder introduces a Multi-user Style Adapter. This lightweight neural network is integrated into the LLM's decoder layers.
  3. Contrastive Learning: To prevent style overlap between users, a contrastive loss function is employed. This forces the model to generate distinct "style signatures" in its hidden states, effectively clustering similar coding habits for each user.
The MPCoder architecture, showing the Multi-user Style Adapter and the dual-track learning process for explicit and implicit style features.

Datasets and Evaluation Metrics

As no public dataset for personalized code generation existed, the authors developed two new benchmarks from the Programming Teaching Assistant (PTA) platform: PCIDense (5,794 records from 50 users) and PCISparse (34,642 records from 1,121 users).

To quantify performance, the study introduces the Coding Style Score (CSS). This metric converts code into a 24-dimensional vector based on style violations and utilizes Jensen-Shannon divergence to measure the similarity between the generated output and a user's historical style.

Results and Discussion

MPCoder demonstrates significant improvements in style mimicry while maintaining functional integrity. On the PCIDense dataset, it achieved a CSS of 64.50%, substantially outperforming the base CodeLlama (48.73%).

Analysis of the Coding Style Score (CSS) relative to the number of attributes in residual learning and the contrastive learning hyperparameter.

Key findings include:

  • Scalability: The shared adapter architecture is highly efficient; adding a new user increases the parameter count by a negligible 0.0003%.
  • Correctness: Unlike other personalization methods like L-LDB, which often degrade logic to match style, MPCoder maintains high correctness (~31% on HumanEval-X).
  • Human Preference: In blind studies, developers preferred MPCoder’s personalized outputs 43% of the time, compared to only 12% for standard adapters.

Conclusion

MPCoder represents a significant step toward personalized AI-assisted development. While currently focused on Java and requiring a small history of user code to learn implicit styles, the framework is theoretically language-agnostic. Future work will focus on expanding language support and further closing the performance gap between personalized and purely correctness-focused models.

Summary updated

Abstract

Large Language Models (LLMs) have demonstrated great potential for assisting developers in their daily development. However, most research focuses on generating correct code, how to use LLMs to generate personalized code has seldom been investigated. To bridge this gap, we proposed MPCoder (Multi-user Personalized Code Generator) to generate personalized code for multiple users. To better learn coding style features, we utilize explicit coding style residual learning to capture the syntax code style standards and implicit style learning to capture the semantic code style conventions. We train a multi-user style adapter to better differentiate the implicit feature representations of different users through contrastive learning, ultimately enabling personalized code generation for multiple users. We further propose a novel evaluation metric for estimating similarities between codes of different coding styles. The experimental results show the effectiveness of our approach for this novel task.
BibTeX
@inproceedings{dai2024mpcoder,
  author = {Zhenlong Dai and Chang Yao and WenKang Han and Yuanying Yuanying and Zhipeng Gao and Jingyuan Chen},
  title = {{MPCoder: Multi-user Personalized Code Generator with Explicit and Implicit Style Representation Learning}},
  booktitle = {Annual Meeting of the Association for Computational Linguistics},
  year = {2024},
  url = {https://openreview.net/forum?id=YL65McMYHj},
}
Figure