arXivDaily arXiv每日学术速递 周一至周五更新
感恩节,周五至周末无更新,大家顺遂。周一再来吧
arXiv 2603.16526cs.AI
收藏

探索不同方法以定制语言模型用于领域特定的文本到代码生成

Exploring different approaches to customize language models for domain-specific text-to-code generation

Technical University of Denmark(丹麦技术大学);The LEGO Group(乐高集团)

Luís Freire, Fernanda A. Andaló, Nicki Skafte Detlefsen

AI总结:

本文探讨了如何通过合成数据集定制小型语言模型用于领域特定的代码生成,比较了少样本提示、检索增强生成和LoRA微调三种方法,发现LoRA在准确性和领域对齐上表现更优。

摘要:

大型语言模型(LLMs)在从自然语言描述生成可执行代码方面表现出强大的能力。然而,通用模型在需要使用领域特定库、API或惯例的专门编程上下文中往往表现不佳。定制小型开源模型为依赖大型专有系统提供了更具成本效益的替代方案。本文研究了如何利用合成数据集对小型语言模型进行适应,以实现领域特定的代码生成。我们构建了三个领域内的编程练习数据集:通用Python编程、Scikit-learn机器学习工作流和基于OpenCV的计算机视觉任务。使用这些数据集,我们评估了三种定制策略:少样本提示、检索增强生成(RAG)和使用低秩适应(LoRA)的参数高效微调。性能评估使用了基于基准的指标和测量与领域特定代码对齐的相似性指标。我们的结果表明,基于提示的方法如少样本学习和RAG可以在低成本下提高领域相关性,尽管对基准准确性的提升有限。相比之下,基于LoRA的微调在大多数任务中实现了更高的准确性和更强的领域对齐。这些发现突显了在适应小型语言模型进行专门编程任务时,灵活性、计算成本和性能之间的实际权衡。

英文摘要:

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.

机构、总结、中文摘要均由AI分析而来,可能存在错误,请以论文正文为准。

↑