Nanyang Technological University
Aligning code language models for documentation quality via supervised fine-tuning and direct preference optimisation
Abstract
dc:description.abstractModern code language models have become remarkably good at producing functionally correct solutions on standard benchmarks, but they still tend to write bare, uncommented code that would raise eyebrows in a professional codebase. This dissertation presents a two-stage fine-tuning approach — first Supervised Fine-Tuning (SFT), then Direct Preference Optimisation (DPO) — to steer a compact code model toward writing code that is properly documented and easier to maintain, without giving up correctness in the process. Starting from Qwen2.5-Coder-1.5B-Instruct, the first stage uses SFT on a curated set of documented, verified completions to nudge the model away from its default terse style. The second stage applies DPO with preference pairs built by deliberately introducing bugs into correct solutions and confirming failures through unit tests — this keeps the training signal anchored to whether code actually works, rather than how it looks on the surface. Evaluation on HumanEval shows a 1.22 percentage point gain in Pass@1 over the unmodified baseline, alongside a jump in comment rate from 6.1% to 77.4% and a Maintainability Index improvement from 79.81 to 84.83. An independent LLM judge favoured the fine-tuned model's outputs in 63–67% of head-to-head comparisons. Comment diversity rates above 95% further suggest the model is writing comments tailored to each problem rather than recycling a fixed pattern.
Degree
thesis:*- College dc:contributor.school
- School of Electrical and Electronic Engineering
- Grantor dc:publisher
- Nanyang Technological University
- Year dc:date.issued
- 2026
Author and committee
dc:creator, dc:contributor.*- Author dc:creator
-
- Chen, Qi
- Advisor dc:contributor.supervisor
-
- -
Subjects
dc:subject × 1Rights
- Language dc:language.iso
- en
Identifiers
dc:identifier.*- Handle dc:identifier.uri
- https://hdl.handle.net/10356/218864