arXivDaily arXiv每日学术速递 周一至周五更新
arXiv 2507.08992cs.SEcs.CLcs.PL
收藏

使用小型与大型语言模型的语义源代码分割

Semantic Source Code Segmentation using Small and Large Language Models

GESIS - Institute for Social Sciences(GESIS莱布尼茨社会科学研究所);Ulm University(乌尔姆大学);Utrecht University(乌得勒支大学)

Abdelhalim Dahou, Ansgar Scherp, Sebastian Kurten, Brigitte Mathiak, Madhu Chauhan

AI总结:

本文提出利用LLMs和SLMs自动化分割研究R代码的方法,结合上下文逐行分析优于基于范围的分割,微调后的小模型表现优于大模型。

摘要:

源代码分割,即将代码划分为功能连贯的片段,对于软件开发中的知识检索和维护至关重要。尽管它能够实现对大型代码库的高效导航与理解,但随着代码库规模的增长,手动和语法分析方法已变得不切实际,特别是对于像R这样的低资源语言及其研究领域(例如社会科学、心理学)。本文介绍了一种使用大型和小型语言模型(LLMs/SLMs)进行研究R代码分割的自动化、特定领域的方法。我们提出了两种新颖的方法和一个人工标注的数据集StatCodeSeg。我们探索了两种不同的方法:结合上下文的逐行分析和基于范围的片段确定。我们对LLMs和微调后的SLMs进行了实验。为了支持我们方法的泛化性,我们还纳入了对计算机科学领域Python代码的实验。结果表明,基于上下文的逐行分析优于基于范围的分割。使用像CodeBERT和仅编码器版本的CodeT5+这样的小型语言模型,比其对应的LLM表现更好。最值得注意的是,这两个表现最佳的模型在预训练期间未见过R代码,而仅在4,130行人工标注代码上进行了微调。

英文摘要:

Source code segmentation, dividing code into functionally coherent segments, is crucial for knowledge retrieval and maintenance in software development. While enabling efficient navigation and comprehension of large codebases, manual and syntactic analysis approaches have become impractical as repositories grow, especially for low-resource languages like R and their research domains (e.g., social sciences, psychology).This paper introduces an automated, domain-specific approach for research R code segmentation using Large and Small Language Models (LLMs/SLMs). It presents two novel approaches and a human-annotated dataset, StatCodeSeg. We explore two distinct approaches: line-by-line analysis with context and range-based segment determination. We experiment with LLMs and fine-tuned SLMs. To support the generalizability of our approaches, we also include experiments on Python code from the computer science domain.Our results show that context-based line-by-line analysis is superior over range-based segmentation.Using smaller language models like CodeBERT and an encoder-only version of CodeT5+ are better than their LLM counterparts. Most notably, these two best-performing models did not see R code during pre-training versus the LLMs but were only fine-tuned on 4,130 lines of manually annotated code.

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

↑