Towards the Readability of LLM-Generated Codes through Multitask Representation Engineering

· Source: cs.SE updates on arXiv.org · Field: Technology & Digital — Artificial Intelligence & Machine Learning, Software Development & Engineering · Depth: Expert, extended

Summary

Researchers introduce Multitask Representation Engineering (MRepE), a novel framework designed to enhance the readability of code generated by large language models (LLMs) while managing the trade-off with code correctness. MRepE employs a joint principal component analysis algorithm with multidimensional orthogonal constraints (MOC-JPCA) to extract distinct steering vectors for three key readability metrics: comment density, naming conventions, and cyclomatic complexity. These orthogonal vectors are then injected into the LLM's hidden layers during inference, allowing for fine-grained control over code output. Experiments on Deepseek_R1_14b, Qwen2.5coder_14b_Instruct, and Codellama_13b_Instruct models demonstrate that MRepE significantly improves readability with minimal correctness degradation, such as a 0.79% loss for Deepseek_R1_14b, 0.95% for Qwen2.5coder_14b_Instruct, and 0.28% for Codellama_13b_Instruct, validating its theoretical bounds.

Key takeaway

For Machine Learning Engineers deploying LLMs for code generation, you should consider implementing the MRepE framework. It allows you to enhance code readability across comment density, naming conventions, and cyclomatic complexity by adjusting steering vector coefficients. This approach enables fine-grained control to balance readability improvements with minimal impact on code correctness, ensuring generated code is both functional and maintainable.

Key insights

MRepE uses orthogonal steering vectors to enhance LLM code readability across multiple metrics while bounding correctness impact.

Principles

Method

MRepE extracts orthogonal steering vectors for readability metrics using MOC-JPCA from contrastive datasets. These vectors are then injected into LLM hidden layers during inference to modulate code generation.

In practice

Topics

Best for: Research Scientist, AI Scientist, Machine Learning Engineer, AI Engineer

Related on AIssential

Open in AIssential →

Editorial summary, takeaway, and curation by AIssential. Original article published by cs.SE updates on arXiv.org.