用小模型自动分割R语言科研代码,效果优于大模型。
Semantic Source Code Segmentation using Small and Large Language Models
- 结合上下文进行逐行分析,比按范围划分更准确
- 微调后的CodeBERT等小模型在4130行数据上表现最佳
- 适合处理低资源语言科研代码,如心理学、社会科学领域
代码分割将代码划分为功能连贯的段落,对软件知识检索与维护至关重要。随着代码库规模增长,传统手动与语法分析方法已不适用,尤其在低资源语言(如R语言)及其研究领域(如社会学、心理学)中更为突出。本文提出一种基于大语言模型(LLMs)和小语言模型(SLMs)的自动化、领域特定的R语言科研代码分割方法,构建了首个人工标注的数据集StatCodeSeg。探索两种新方法:基于上下文的逐行分析与基于范围的段落确定,并在计算机科学领域的Python代码上验证通用性。实验表明,上下文驱动的逐行分析优于基于范围的方法;使用CodeBERT及编码器版CodeT5+等小模型的表现优于大模型。值得注意的是,这些最优模型未在R代码上预训练,仅在4,130行标注数据上微调后即取得优异效果。
原文摘要 · Abstract (English)
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.
Thank you to arXiv for use of its open access interoperability. PaperDance 不是 arXiv 官方产品;中文卡片由大模型生成,请以原文为准。