Work

Small Language Models for Generating Code Comments

Year: 2026
Type: article
Abstract: Generating line-level code explanations at scale highlights the potential of Large Language Models (LLMs) in computing education. Most prior work relies on large proprietary models accessed through closed APIs, which raises concerns about API cost, student data privacy, and the inability to deploy models on student devices. This paper investigates whether Small Language Models (SLMs) under 4B parameters in size can produce high-quality line-level explanations for CS1 students. We evaluate six models, namely Qwen3.5 at 0.8B, 2B, and 4B scales, SmolLM3-3B, Llama-3.2-1B and Llama-3.1-8B as a larger reference point, on 104 annotated introductory Python programs from the ACOS learning platform. We compare three prompting strategies varying along two axes: whether the model sees the full program (Context-Aware) or only the target line (Line-Only), and within the Context-Aware setting, whether the prompt contains a single worked demonstration (one-shot) or none (zero-shot). Quality is assessed with G-Eval framework on five dimensions: Correctness, Clarity, Conciseness, Pedagogical Completeness, and Abstraction Level, complemented by automated reference-based metrics. Our results show that model scale improves explanation quality, and one-shot demonstrations consistently improve performance, driven mostly by gains in conciseness. However, demonstrations trade pedagogical completeness for brevity, and the improvement shrinks as scale increases. Clarity and Abstraction Level are largely insensitive to model size and prompting strategy, suggesting these dimensions are already well handled by even the smallest models. These findings indicate that SLMs under 4B parameters in size, combined with context-aware one-shot prompting, are a promising privacy-preserving approach for generating line-level code explanations.
Language: English
Open Access status: green
OpenAlex ID: W7236976864
FWCI:
Cites: 36
Cited by:
Related to: 10