Exploring different approaches to customize language models for domain-specific text-to-code generation
Organizations: Technical University of Denmark · The LEGO Group
Abstract
Large language models (LLMs) have demonstrated strong capabilities in generating executable code from natural language descriptions. However, general-purpose models often struggle in specialized programming contexts where domain-specific libraries, APIs, or conventions must be used. Customizing smaller open-source models offers a cost-effective alternative to relying on large proprietary systems. In this work, we investigate how smaller language models can be adapted for domain-specific code generation using synthetic datasets. We construct datasets of programming exercises across three domains within the Python ecosystem: general Python programming, Scikit-learn machine learning workflows, and OpenCV-based computer vision tasks. Using these datasets, we evaluate three customization strategies: few-shot prompting, retrieval-augmented generation (RAG), and parameter-efficient fine-tuning using Low-Rank Adaptation (LoRA). Performance is evaluated using both benchmark-based metrics and similarity-based metrics that measure alignment with domain-specific code. Our results show that prompting-based approaches such as few-shot learning and RAG can improve domain relevance in a cost-effective manner, although their impact on benchmark accuracy is limited. In contrast, LoRA-based fine-tuning consistently achieves higher accuracy and stronger domain alignment across most tasks. These findings highlight practical trade-offs between flexibility, computational cost, and performance when adapting smaller language models for specialized programming tasks.
Figures & tables
| Domain | Generated Samples | Valid Samples | Retention Rate |
|---|---|---|---|
| General Python Exercises | 21,745 | 21,042 | 96.8% |
| OpenCV Exercises | 22,770 | 21,039 | 92.4% |
| Scikit-learn Exercises | 20,330 | 20,052 | 98.6% |
| Python | Scikit-learn | OpenCV | ||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|
| Method | Pass@1 | Sim. | Pass@1 | Sim. | Pass@1 | Sim. | ||||||
| StarCoder-1B | ||||||||||||
| Baseline | ||||||||||||
| Few-shot | (-1.4) | (+2.2) | (-9.3) | (+5.2) | (+10.0) | (+1.7) | ||||||
| RAG | (-2.0) | (+7.3) | (-8.6) | (+11.7) | (+8.2) | |||||||
| LoRA | 18.3 | (+2.3) | 87.1 | (+13.5) | 20.4 | (+7.2) | 77.5 | (+14.7) | 20.0 | (+20.0) | 87.1 | (+7.8) |
Code Generation
Code generation studies methods for turning natural-language, visual, or formal specifications into executable programs and code edits.
See all 304 papers