{"id":{"repo_id":"nanyang","oai_identifier":"oai:dr.ntu.edu.sg:10356/218864"},"canonical_url":"https://search.ndltd.org/etd/nanyang/oai:dr.ntu.edu.sg:10356/218864","repository":{"repo_id":"nanyang","name":"Nanyang Technological University","base_url":"https://dr.ntu.edu.sg/oai/request"},"display":{"title":"Aligning code language models for documentation quality via supervised fine-tuning and direct preference optimisation","abstract":"Modern 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.","abstract_html":"Modern 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&#x27;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.","abstract_has_math":false,"creators":["Chen, Qi"],"institution":"Nanyang Technological University","degree_name":null,"degree_level":null,"degree_discipline":null,"degree_department":null,"school":"School of Electrical and Electronic Engineering","contributors":[],"advisors":["-"],"committee_chairs":[],"committee_members":[],"year":2026,"date_issued":"2026","date_published":"2026","updated_at":"2026-11-27T08:07:44Z","subjects":["Engineering"],"languages":["en"],"rights":[],"rights_urls":[],"identifier_entries":[],"person_identifier_entries":[]},"links":{"outbound_url":"https://hdl.handle.net/10356/218864","outbound_label":"Handle","outbound_source":"dc:identifier.uri","record_url":"https://hdl.handle.net/10356/218864","record_label":"Repository record","record_kind":"handle","record_source":"dc:identifier.uri","access_status":null,"embargo_until":null,"access_note":null},"oai_pmh_record":{"url":"https://union.ndltd.org/oai-pmh/?verb=GetRecord&metadataPrefix=oai_dc&identifier=oai%3Aunion.ndltd.org%3Arepo%3Ananyang%3Aoai%3Adr.ntu.edu.sg%3A10356%2F218864","prefix":"oai_dc"},"source_record":{"url":"https://dr.ntu.edu.sg/oai/request?verb=GetRecord&metadataPrefix=dim&identifier=oai%3Adr.ntu.edu.sg%3A10356%2F218864","prefix":"dim"},"metadata_groups":[{"id":"people","label":"People","entries":[{"key":"dc:contributor.school","label":"School","values":["School of Electrical and Electronic Engineering"]},{"key":"dc:contributor.supervisor","label":"Supervisor","values":["-"]},{"key":"dc:creator","label":"Author","values":["Chen, Qi"]}]},{"id":"academic_context","label":"Academic Context","entries":[{"key":"dc:date.accessioned","label":"Dc Date Accessioned","values":["2026-07-08T02:50:33Z"]},{"key":"dc:date.available","label":"Dc Date Available","values":["2026-07-08T02:50:33Z"]},{"key":"dc:date.issued","label":"Date","values":["2026"]},{"key":"dc:publisher","label":"Institution","values":["Nanyang Technological University"]},{"key":"dc:type","label":"Dc Type","values":["Thesis-Master by Coursework"]}]},{"id":"subjects_keywords","label":"Subjects and Keywords","entries":[{"key":"dc:subject","label":"Dc Subject","values":["Engineering"]}]},{"id":"language_rights","label":"Language and Rights","entries":[{"key":"dc:language.iso","label":"Language (ISO)","values":["en"]}]},{"id":"identifiers","label":"Identifiers","entries":[{"key":"dc:identifier.uri","label":"Identifier URI","values":["https://hdl.handle.net/10356/218864"]}]},{"id":"additional","label":"Additional Metadata","entries":[{"key":"cerif:openaire","label":"Cerif Openaire","values":["<Publication xmlns=\"https://www.openaire.eu/cerif-profile/1.1/\" id=\"59c47e12-9b40-47cd-b35a-03f401283f4a\"> <Type xmlns=\"https://www.openaire.eu/cerif-profile/vocab/COAR_Publication_Types\">http://purl.org/coar/resource_type/c_1843</Type> <Language>en</Language> <Title>Aligning code language models for documentation quality via supervised fine-tuning and direct preference optimisation</Title> <PublishedIn> <Publication> </Publication> </PublishedIn> <PublicationDate>2026</PublicationDate> <Authors> <Author> <DisplayName>Chen, Qi</DisplayName> <Affiliation> <OrgUnit> </OrgUnit> </Affiliation> </Author> </Authors> <Editors> </Editors> <Publishers> <Publisher> <DisplayName>Nanyang Technological University</DisplayName> <OrgUnit /> </Publisher> </Publishers> <Keyword>Engineering</Keyword> <Abstract>Modern 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.</Abstract> <Access xmlns=\"http://purl.org/coar/access_right\" > </Access> </Publication>"]},{"key":"dc:description.abstract","label":"Abstract","values":["Modern 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."]},{"key":"dc:description.degree","label":"Dc Description Degree","values":["Master's degree"]},{"key":"dc:format.mimetype","label":"Dc Format Mimetype","values":["application/pdf"]},{"key":"dc:title","label":"Title","values":["Aligning code language models for documentation quality via supervised fine-tuning and direct preference optimisation"]},{"key":"dspace:entity.type","label":"Dspace Entity Type","values":["Publication"]}]}],"canonical_facts":{"cerif:openaire":["<Publication xmlns=\"https://www.openaire.eu/cerif-profile/1.1/\" id=\"59c47e12-9b40-47cd-b35a-03f401283f4a\"> <Type xmlns=\"https://www.openaire.eu/cerif-profile/vocab/COAR_Publication_Types\">http://purl.org/coar/resource_type/c_1843</Type> <Language>en</Language> <Title>Aligning code language models for documentation quality via supervised fine-tuning and direct preference optimisation</Title> <PublishedIn> <Publication> </Publication> </PublishedIn> <PublicationDate>2026</PublicationDate> <Authors> <Author> <DisplayName>Chen, Qi</DisplayName> <Affiliation> <OrgUnit> </OrgUnit> </Affiliation> </Author> </Authors> <Editors> </Editors> <Publishers> <Publisher> <DisplayName>Nanyang Technological University</DisplayName> <OrgUnit /> </Publisher> </Publishers> <Keyword>Engineering</Keyword> <Abstract>Modern 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.</Abstract> <Access xmlns=\"http://purl.org/coar/access_right\" > </Access> </Publication>"],"dc:contributor.school":["School of Electrical and Electronic Engineering"],"dc:contributor.supervisor":["-"],"dc:creator":["Chen, Qi"],"dc:date.accessioned":["2026-07-08T02:50:33Z"],"dc:date.available":["2026-07-08T02:50:33Z"],"dc:date.issued":["2026"],"dc:description.abstract":["Modern 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."],"dc:description.degree":["Master's degree"],"dc:format.mimetype":["application/pdf"],"dc:identifier.uri":["https://hdl.handle.net/10356/218864"],"dc:language.iso":["en"],"dc:publisher":["Nanyang Technological University"],"dc:subject":["Engineering"],"dc:title":["Aligning code language models for documentation quality via supervised fine-tuning and direct preference optimisation"],"dc:type":["Thesis-Master by Coursework"],"dspace:entity.type":["Publication"]},"updated_at":"2026-11-27T08:07:44Z"}