REVIEW 3 major objections 5 minor 42 references
Semantic Source Code Segmentation using Small and Large Language Models
T0 review · 3 major / 5 minor · reviewed 2026-08-06 · deepseek-v4-flash
Pith's one-line read Small fine-tuned encoder-only models outperform large language models at semantically segmenting research R code, and line-by-line classification with local context beats range-based generation.
desk verdict Worth reading for the new StatCodeSeg dataset, but the fine-tuned-SLM-beats-LLMs claim is fragile because context-window sizes were selected without a stated validation protocol and the margins are within noise. read the letter →
The pith
A machine-rendered reading of the paper's core claim, the machinery that carries it, and where it could break.
The reading
What carries the argument
The mechanism is a sliding context window: each target code line is presented to the model together with $c$ preceding and $c$ following lines, the model assigns the target line one of seven functional categories (Loading Library, Loading Data, Data Wrangling, Analysis, Visualization, Saving to Output, Comment), and then consecutive lines with identical categories are merged into segments. This turns segmentation into a local sequence-labeling task, which is what the fine-tuned encoders excel at. The competing range-based variant feeds the entire file as a JSON list of numbered lines and instructs the model to generate contiguous ranges with labels; because it relies on generative reasoning over the whole file, it performs more unevenly. The paper also anchors the comparison with a new annotation resource, StatCodeSeg, consisting of 160 R scripts and 13,819 line-level labels with substantial inter-annotator agreement.
What would settle it
Recompute Table 2 with a pre-registered protocol in which each model's context window $c$ is tuned only on the validation split, then re-run the test comparisons; if CodeBERT no longer tops the best LLMs on macro F1, the paper's central conclusion would not reproduce.
Extended reading notes
Core claim
The central discovery is a reversal of the usual expectation: for labeling each line of an R script with its functional role, the 125M-parameter bidirectional encoder CodeBERT, fine-tuned on 4,130 manually annotated lines, outperforms all tested decoder-only LLMs, including models with far more parameters and models whose pretraining included R. The best configuration uses a context window of three lines before and after the target line ($c = 3$). An encoder-only variant of CodeT5+ (110M parameters) also outperforms all zero-shot and few-shot LLM variants with 74.9% accuracy at $c = 7$. The paper interprets this as evidence that local discriminative classification, enabled by bidirectional encoder representations, fits the code-segmentation task better than open-ended generation; it supports this by showing that the line-by-line approach generally beats the range-based approach in precision and recall, and by reproducing the same ranking on Python code.
Load-bearing premise
The headline comparison depends on the assumption that each model's context-window size was chosen on the validation split and not by looking at test results, so the reported per-model best numbers are honest optima rather than test-set cherry-picks.
Editorial extensions
If this is right
- A small, locally fine-tunable model can serve as a practical semantic segmenter for R scripts in the social sciences without calling paid LLM APIs, which matters for domain researchers who share R code on platforms not supported by commercial copilots.
- Line-by-line classification with a modest context window is a more reliable task formulation than range-based generation for capturing functional boundaries in code.
- Fine-tuning on roughly four thousand lines of annotated code appears sufficient to transfer segmentation ability to a language the model did not see during pre-training, at least for a structurally close language like Python.
- The StatCodeSeg dataset and the two approach variants provide a benchmark against which future segmentation methods for R can be measured.
Reading between the lines
- A corollary not tested in the paper: the same fine-tune-a-small-encoder recipe likely transfers to other low-resource statistical languages such as Stata, SAS, or SPSS, provided a few thousand domain lines can be annotated; this is our extrapolation.
- The paper reports that larger context windows can hurt accuracy; a practical, testable extension would be a context-length schedule that starts small and grows only when line-level uncertainty is high, an active-learning variant the authors do not run.
- The consistent encoder advantage on both R and Python suggests the benefit comes from the discriminative task formulation rather than from language-specific pretraining, so similar rankings are plausible for other code languages once annotations exist; the paper only demonstrates this for two languages.
Editorial analysis
A structured set of objections, weighed in public.
Referee Report
Summary. The paper introduces StatCodeSeg, a human-annotated dataset of 13,819 lines from 160 R scripts in the social-science/psychology domain, labeled with seven functional categories. It proposes two segmentation approaches: line-by-line classification with a local context window (applied to fine-tuned small models and zero/few-shot LLMs) and range-based segment generation from the whole file (applied to LLMs). The authors report results on R and Python, claiming that context-based line-by-line analysis is superior to range-based segmentation and that fine-tuned small encoder models (CodeBERT, CodeT5+ encoder-only) outperform all evaluated LLMs despite not having seen R code in pretraining.
Significance. If substantiated, the paper would make a useful empirical contribution: a new annotated dataset for a low-resource language, a clear comparison of two task formulations, and evidence that small fine-tuned encoders are competitive and economical for line-level code classification. The inclusion of inter-annotator agreement (Fleiss kappa = 0.649), multiple LLM baselines, and a Python extension are strengths. However, the headline claim about small models outperforming LLMs rests on a very small accuracy margin and on a context-window selection procedure that is not described as validation-based, so the current evidence does not yet support the strength of the claim.
major comments (3)
- [Section 5.2, Figure 3, Appendix A.6] The per-model context-window size c reported in Table 2 is not selected through an explicit validation protocol. Appendix A.6 states that 'it seems reasonable that the experiments identified optimal context window sizes,' which suggests the best c was read from the test-set curves in Figure 3. This matters because the headline advantage of CodeBERT over DeepSeek R1 is only 0.61 accuracy points (77.14 vs. 76.53) and 1.22 points over Gemini 1.5 Pro. If c was chosen on the test set, every reported accuracy is a test-set-selected maximum, and the reported ordering could be an artifact. Please specify a pre-registered validation rule for c, report results for all c values on the test set, or otherwise correct for the selection.
- [Section 5.3, Table 2] The reported comparisons lack confidence intervals, significance tests, or multiple fine-tuned seeds. Fine-tuning hyperparameters for CodeBERT are given in Appendix A.2, but there is no indication of run-to-run variance, and no paired significance test (e.g., McNemar) between CodeBERT and the best LLMs is reported. Given that the CodeBERT advantage over DeepSeek R1 is under one accuracy point, the claim that 'SLMs clearly outperform' is not statistically established. Please provide CIs or significance tests on the line-level predictions, and run fine-tuned models with at least three seeds to report variance.
- [Section 3.3, Table 1] The manuscript does not state whether the train/val/test split is performed at the file level. The statistics in Table 1 are consistent with a file-level split (roughly 50/10/100 files out of 160), but this is not stated explicitly. If lines from the same file appear in multiple splits, the local context window and file-specific style could leak into training. Please state explicitly that the 160 files were partitioned before line extraction, and describe the stratification criteria (e.g., by project or domain).
minor comments (5)
- [Section 6, first paragraph] The text refers to 'Table 5' for the line-by-line R results, but the actual table is Table 2; Table 5 contains the Python results.
- [Section 6, first paragraph] The comparison sentence for Gemini 1.5 Pro says '75.2% vs. 76.99%', but the line-by-line accuracy in Table 2 is 75.92%, not 76.99%.
- [Section 3.2] The citation 'Fleiss’ kappa (κ) Landis JRKoch (1977)' is malformed; it should be formatted as a proper reference to Landis and Koch (1977).
- [Appendix A.8] The appendix title contains a typo: 'Annotaiton Rules' should be 'Annotation Rules'.
- [Section 5.2] The Hugging Face model names appear as 'codet5p-110m-embedding' and 'codet5p-770m', but the platform is misspelled as 'HuggigFace' in one place.
Circularity Check
No significant circularity: the headline comparison is grounded in a held-out test set; the self-cited unseen-data assumption is ancillary, not load-bearing.
full rationale
This paper is an empirical benchmark, not a mathematical derivation. The central claim that fine-tuned CodeBERT outperforms larger LLMs on StatCodeSeg rests on held-out test-set results (Table 2), which are not constructed from the inputs of the method. The only potential self-citation concern is the use of Diera et al. (2023) to support the assumption that OSF-derived R code was unseen during pretraining (Section A.5: 'as noted in Diera et al. (2023), since the dataset derives from OSF rather than public platforms such as GitHub, we assume that existing language models were not exposed to this data during pre-training'). That assumption is explicitly labeled as an assumption, and it is ancillary to the measured comparison: the CodeBERT-versus-LLM ranking on the test set would stand even if the pretraining-exposure claim were false. The context-window size c is a hyperparameter, not a fitted parameter renamed as a prediction; the absence of a stated validation protocol for selecting c (Section A.6 says only that 'it seems reasonable that the experiments identified optimal context window sizes') is a methodological limitation regarding possible test-set selection, but it does not make the result circular by construction. No equation reduces a predicted quantity to an input, and no load-bearing argument reduces to an unverified self-citation. The paper is therefore self-contained as an empirical study, with a minor self-citation that does not force the outcome.
Assumptions & free parameters
free parameters (2)
- Per-model context window size c =
CodeBERT 3; CodeT5+ encoder 7; GPT-4o 2; Gemini 1.5 Pro 7; Claude 3.5 Sonnet 3; DeepSeek V3 1; Qwen2.5-coder 3; Code…
- CodeBERT fine-tuning hyperparameters =
lr 3e-5, batch 16, epochs 8, weight decay 0.02
assumptions (3)
- domain assumption Three annotators' labels, resolved by majority voting and discussion, constitute reliable ground truth for all 13,819 lines.
- domain assumption CodeBERT and CodeT5+ were not exposed to R code during pretraining.
- ad hoc to paper Context-window size c for each model was selected without using the test set.
Cite this review
Pith. "Pith review of Semantic Source Code Segmentation using Small and Large Language Models." pith.science (2026). https://pith.science/paper/WCK3BKJZ
@misc{pith2026250708992,
author = {Pith},
title = {Pith review of: Semantic Source Code Segmentation using Small and Large Language Models},
year = {2026},
howpublished = {\url{https://pith.science/paper/WCK3BKJZ}},
note = {Machine review of arXiv:2507.08992}
}
read the original abstract
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.
Figures
Reference graph
Works this paper leans on
-
[1]
Josh Achiam, Steven Adler, Sandhini Agarwal, Lama Ahmad, Ilge Akkaya, Florencia Leoni Aleman, Diogo Almeida, Janko Altenschmidt, Sam Altman, Shyamal Anadkat, et al. Gpt-4 technical report. arXiv preprint arXiv:2303.08774, 2023
arXiv 2023
-
[2]
Monitor-guided decoding of code lms with static analysis of repository context
Lakshya A Agrawal, Aditya Kanade, Navin Goyal, Shuvendu Lahiri, and Sriram Rajamani. Monitor-guided decoding of code lms with static analysis of repository context. Advances in Neural Information Processing Systems, 36, 2024
work page 2024
-
[3]
The claude 3 model family: Opus, sonnet, haiku
AI Anthropic. The claude 3 model family: Opus, sonnet, haiku. Claude-3 Model Card, 1, 2024
2024
-
[4]
Experience with github copilot for developer productivity at zoominfo
Gal Bakal, Ali Dasdan, Yaniv Katz, Michael Kaufman, and Guy Levin. Experience with github copilot for developer productivity at zoominfo. arXiv preprint arXiv:2501.13282, 2025
arXiv 2025
-
[5]
Improving Segmentation for Technical Support Problems
Kushal Chauhan and Abhirut Gupta. Improving segmentation for technical support problems. arXiv preprint arXiv:2005.11055, 2020
work page Pith review arXiv 2005
-
[6]
Evaluating large language models trained on code
Mark Chen, Jerry Tworek, Heewoo Jun, Qiming Yuan, Henrique Ponde De Oliveira Pinto, Jared Kaplan, Harri Edwards, Yuri Burda, Nicholas Joseph, Greg Brockman, et al. Evaluating large language models trained on code. arXiv preprint arXiv:2107.03374, 2021
arXiv 2021
-
[7]
Advances in domain independent linear text segmentation
Freddy YY Choi. Advances in domain independent linear text segmentation. arXiv preprint cs/0003083, 2000
work page Pith review arXiv 2000
-
[8]
Bert: Pre-training of deep bidirectional transformers for language understanding
Jacob Devlin. Bert: Pre-training of deep bidirectional transformers for language understanding. arXiv preprint arXiv:1810.04805, 2018
arXiv 2018
Show all 42 references
-
[9]
Gencodesearchnet: A benchmark test suite for evaluating generalization in programming language understanding
Andor Diera, Abdelhalim Dahou, Lukas Galke, Fabian Karl, Florian Sihler, and Ansgar Scherp. Gencodesearchnet: A benchmark test suite for evaluating generalization in programming language understanding. arXiv preprint arXiv:2311.09707, 2023
2023 arXiv
-
[10]
Logical segmentation of source code
Jacob Dormuth, Ben Gelman, Jessica Moore, and David Slater. Logical segmentation of source code. arXiv preprint arXiv:1907.08615, 2019
1907 arXiv
-
[11]
Lumberchunker: Long-form narrative document segmentation
Andr \'e V Duarte, Jo \ a o Marques, Miguel Gra c a, Miguel Freire, Lei Li, and Arlindo L Oliveira. Lumberchunker: Long-form narrative document segmentation. arXiv preprint arXiv:2406.17526, 2024
2024 arXiv
-
[12]
Codebert: A pre-trained model for programming and natural languages
Zhangyin Feng, Daya Guo, Duyu Tang, Nan Duan, Xiaocheng Feng, Ming Gong, Linjun Shou, Bing Qin, Ting Liu, Daxin Jiang, et al. Codebert: A pre-trained model for programming and natural languages. arXiv preprint arXiv:2002.08155, 2020
2002 arXiv
-
[13]
The limits of the identifiable: Challenges in python version identification with deep learning
Marcus Gerhold, Lola Solovyeva, and Vadim Zaytsev. The limits of the identifiable: Challenges in python version identification with deep learning. In 2024 IEEE International Conference on Software Analysis, Evolution and Reengineering (SANER), pp.\ 137--146. IEEE, 2024
2024
-
[14]
Topic segmentation of semi-structured and unstructured conversational datasets using language models
Reshmi Ghosh, Harjeet Singh Kajal, Sharanya Kamath, Dhuri Shrivastava, Samyadeep Basu, Hansi Zeng, and Soundararajan Srinivasan. Topic segmentation of semi-structured and unstructured conversational datasets using language models. In Intelligent Systems Conference, pp.\ 91--10...
2023
-
[15]
Deepseek-coder: When the large language model meets programming--the rise of code intelligence
Daya Guo, Qihao Zhu, Dejian Yang, Zhenda Xie, Kai Dong, Wentao Zhang, Guanting Chen, Xiao Bi, Yu Wu, YK Li, et al. Deepseek-coder: When the large language model meets programming--the rise of code intelligence. arXiv preprint arXiv:2401.14196, 2024
2024 arXiv
-
[16]
Binyuan Hui, Jian Yang, Zeyu Cui, Jiaxi Yang, Dayiheng Liu, Lei Zhang, Tianyu Liu, Jiajun Zhang, Bowen Yu, Keming Lu, et al. Qwen2. 5-coder technical report. arXiv preprint arXiv:2409.12186, 2024
2024 arXiv
-
[17]
Topic segmentation and labeling in asynchronous conversations
Shafiq Joty, Giuseppe Carenini, and Raymond T Ng. Topic segmentation and labeling in asynchronous conversations. Journal of Artificial Intelligence Research, 47: 0 521--573, 2013
2013
-
[18]
Text segmentation as a supervised learning task
Omri Koshorek, Adir Cohen, Noam Mor, Michael Rotman, and Jonathan Berant. Text segmentation as a supervised learning task. arXiv preprint arXiv:1803.09337, 2018
2018 arXiv
-
[19]
The measurement of observer agreement for categorical data
GG Landis JRKoch. The measurement of observer agreement for categorical data. Biometrics, 33 0 (1): 0 159174, 1977
1977
-
[20]
Starcoder 2 and the stack v2: The next generation
Anton Lozhkov, Raymond Li, Loubna Ben Allal, Federico Cassano, Joel Lamy-Poirier, Nouamane Tazi, Ao Tang, Dmytro Pykhtar, Jiawei Liu, Yuxiang Wei, et al. Starcoder 2 and the stack v2: The next generation. arXiv preprint arXiv:2402.19173, 2024
2024 arXiv
-
[21]
Text segmentation by cross segment attention
Michal Lukasik, Boris Dadachev, Gon c alo Simoes, and Kishore Papineni. Text segmentation by cross segment attention. arXiv preprint arXiv:2004.14535, 2020
2004 arXiv
-
[22]
Lms: Understanding code syntax and semantics for code analysis
Wei Ma, Shangqing Liu, Zhihao Lin, Wenhan Wang, Qiang Hu, Ye Liu, Cen Zhang, Liming Nie, Li Li, and Yang Liu. Lms: Understanding code syntax and semantics for code analysis. arXiv preprint arXiv:2305.12138, 2023
2023 arXiv
-
[23]
Evaluating ai-based code segmentation for abap programs in an industrial use case
Richard Mayer, Michael Moser, Niklas Greif, Florian Schnitzhofer, Verena Geist, and Martin Pinzger. Evaluating ai-based code segmentation for abap programs in an industrial use case. In International Conference on Product-Focused Software Process Improvement, pp.\ 131--147. Sp...
2024
-
[24]
Beamseg: A joint model for multi-document segmentation and topic identification
Pedro Mota, Maxine Eskenazi, and Lu \' sa Coheur. Beamseg: A joint model for multi-document segmentation and topic identification. In Proceedings of the 23rd Conference on Computational Natural Language Learning (CoNLL), pp.\ 582--592, 2019
2019
-
[25]
Codegen2: Lessons for training llms on programming and natural languages
Erik Nijkamp, Hiroaki Hayashi, Caiming Xiong, Silvio Savarese, and Yingbo Zhou. Codegen2: Lessons for training llms on programming and natural languages. arXiv preprint arXiv:2305.02309, 2023
2023 arXiv
-
[26]
Automated support for legacy code understanding
Jim Q Ning, Andre Engberts, and W Voytek Kozaczynski. Automated support for legacy code understanding. Communications of the ACM, 37 0 (5): 0 50--58, 1994
1994
-
[27]
Unsupervised dialogue topic segmentation in hyperdimensional space
Seongmin Park, Jinkyu Seo, and Jihwa Lee. Unsupervised dialogue topic segmentation in hyperdimensional space. arXiv preprint arXiv:2308.10464, 2023
2023 arXiv
-
[28]
Topictiling: a text segmentation algorithm based on lda
Martin Riedl and Chris Biemann. Topictiling: a text segmentation algorithm based on lda. In Proceedings of ACL 2012 student research workshop, pp.\ 37--42, 2012
2012
-
[29]
Code llama: Open foundation models for code
Baptiste Roziere, Jonas Gehring, Fabian Gloeckle, Sten Sootla, Itai Gat, Xiaoqing Ellen Tan, Yossi Adi, Jingyu Liu, Tal Remez, J \'e r \'e my Rapin, et al. Code llama: Open foundation models for code. arXiv preprint arXiv:2308.12950, 2023
2023 arXiv
-
[30]
Unsupervised topic segmentation of meetings with bert embeddings
Alessandro Solbiati, Kevin Heffernan, Georgios Damaskinos, Shivani Poddar, Shubham Modi, and Jacques Cali. Unsupervised topic segmentation of meetings with bert embeddings. arXiv preprint arXiv:2106.12978, 2021
2021 arXiv
-
[31]
Chaos to clarity with semantic inferencing for python source code snippets
Aviel Stein and Spiros Mancoridis. Chaos to clarity with semantic inferencing for python source code snippets. In 2023 IEEE 17th International Conference on Semantic Computing (ICSC), pp.\ 161--166. IEEE, 2023
2023
-
[32]
Linguistic approach to segmenting source code
Aviel J Stein, Daniel Schwartz, Yiwen Shi, and Spiros Mancoridis. Linguistic approach to segmenting source code. In 2022 IEEE 16th International Conference on Semantic Computing (ICSC), pp.\ 177--178. IEEE, 2022
2022
-
[33]
Text classification via large language models
Xiaofei Sun, Xiaoya Li, Jiwei Li, Fei Wu, Shangwei Guo, Tianwei Zhang, and Guoyin Wang. Text classification via large language models. arXiv preprint arXiv:2305.08377, 2023
2023 arXiv
-
[34]
Gemini: a family of highly capable multimodal models
Gemini Team, Rohan Anil, Sebastian Borgeaud, Yonghui Wu, Jean-Baptiste Alayrac, Jiahui Yu, Radu Soricut, Johan Schalkwyk, Andrew M Dai, Anja Hauth, et al. Gemini: a family of highly capable multimodal models. arXiv preprint arXiv:2312.11805, 2023
2023 arXiv
-
[35]
Automatic segmentation of method code into meaningful blocks to improve readability
Xiaoran Wang, Lori Pollock, and K Vijay-Shanker. Automatic segmentation of method code into meaningful blocks to improve readability. In 2011 18th Working Conference on Reverse Engineering, pp.\ 35--44. IEEE, 2011
2011
-
[36]
Codet5+: Open code large language models for code understanding and generation
Yue Wang, Hung Le, Akhilesh Deepak Gotmare, Nghi DQ Bui, Junnan Li, and Steven CH Hoi. Codet5+: Open code large language models for code understanding and generation. arXiv preprint arXiv:2305.07922, 2023
2023 arXiv
-
[37]
Coral: Code representation learning with weakly-supervised transformers for analyzing data analysis
Ge Zhang, Mike A Merrill, Yang Liu, Jeffrey Heer, and Tim Althoff. Coral: Code representation learning with weakly-supervised transformers for analyzing data analysis. EPJ Data Science, 11 0 (1): 0 14, 2022
2022
-
[38]
Meta-chunking: Learning efficient text segmentation via logical perception
Jihao Zhao, Zhiyuan Ji, Pengnian Qi, Simin Niu, Bo Tang, Feiyu Xiong, and Zhiyu Li. Meta-chunking: Learning efficient text segmentation via logical perception. arXiv preprint arXiv:2410.12788, 2024
2024 arXiv
-
[39]
write newline
" write newline "" before.all 'output.state := FUNCTION n.dashify 't := "" t empty not t #1 #1 substring "-" = t #1 #2 substring "--" = not "--" * t #2 global.max substring 't := t #1 #1 substring "-" = "-" * t #2 global.max substring 't := while if t #1 #1 substring * t #2 gl...
-
[40]
@esa (Ref
\@ifxundefined[1] #1\@undefined \@firstoftwo \@secondoftwo \@ifnum[1] #1 \@firstoftwo \@secondoftwo \@ifx[1] #1 \@firstoftwo \@secondoftwo [2] @ #1 \@temptokena #2 #1 @ \@temptokena \@ifclassloaded agu2001 natbib The agu2001 class already includes natbib coding, so you should ...
-
[41]
\@lbibitem[] @bibitem@first@sw\@secondoftwo \@lbibitem[#1]#2 \@extra@b@citeb \@ifundefined br@#2\@extra@b@citeb \@namedef br@#2 \@nameuse br@#2\@extra@b@citeb \@ifundefined b@#2\@extra@b@citeb @num @parse #2 @tmp #1 NAT@b@open@#2 NAT@b@shut@#2 \@ifnum @merge>\@ne @bibitem@firs...
-
[42]
@open @close @open @close and [1] URL: #1 \@ifundefined chapter * \@mkboth \@ifxundefined @sectionbib * \@mkboth * \@mkboth\@gobbletwo \@ifclassloaded amsart * \@ifclassloaded amsbook * \@ifxundefined @heading @heading NAT@ctr thebibliography [1] @ \@biblabel @NAT@ctr \@bibset...
Reviewed August 6, 2026 · model on record in the stance chip above.
Discussion (0). Sign in to comment.