Newest papers

Better Specifications, Better Code: Fine-Tuning LLMs for Behavioral Contract Generation

Brhane Team, Tiantian Yang, Nikta Akbarpour, Simone Bartucci, Francesco Calimeri, Song Wang · 2026 · arXiv (Cornell University)

DOI: 10.48550/arxiv.2610.25616 · cited by 0 works (OpenAlex) · open-access PDF

Vietnamese

Các mô hình hành vi chính xác lớn (LLM) thể hiện khả năng tạo mã mạnh mẽ nhưng thường phải vật lộn với sự chính xác chức năng do các yêu cầu hành vi ngụ ý hoặc mơ hồ. Chúng tôi trình bày CG2, một khuôn khổ tạo mã theo hợp đồng chuyển đổi các nhiệm vụ ngôn ngữ tự nhiên thành các hợp đồng hành vi có cấu trúc xác định giao diện, điều kiện trước, hậu điều kiện và bất biến. CG2 tinh chỉnh một LLM để tạo ra các hợp đồng này và giới thiệu một quy trình xác nhận và sửa chữa ngữ nghĩa lặp đi lặp lại để xác định và sửa chữa các nhiệm vụ không đầy đủ, không nhất quán hoặc không chính xác trước khi hướng dẫn một mô hình tạo mã tiếp theo không thay đổi. Chúng tôi đánh giá CG2 trên 1,007 nhiệm vụ được thực hiện bằng cách sử dụng năm mã LLM: DeepSeek-Coder-V2-L

Machine translation (Meta M2M100); the English original follows.

Abstract

Large language models (LLMs) demonstrate strong code-generation capabilities but often struggle with functional correctness due to implicit or ambiguous behavioral requirements. We present CG2, a contract-guided code generation framework that translates natural-language tasks into structured behavioral contracts specifying interfaces, preconditions, postconditions, and invariants. CG2 fine-tunes an LLM to generate these contracts and introduces an iterative semantic validation and repair process to identify and correct incomplete, inconsistent, or incorrect specifications before guiding an unchanged downstream code-generation model. We evaluate CG2 on 1,007 held-out tasks using five code LLMs: DeepSeek-Coder-V2-Lite-Instruct, Ministral-3-14B-Instruct-2512, Qwen2.5-Coder-14B-Instruct, Qwen2.5-Coder-32B-Instruct, and Qwen3.5-27B. Results show that CG2 consistently improves pass@1 over direct code generation by 1.49-3.27 percentage points (7.58%-22.45% relative improvement) and over contract guidance without fine-tuning by 1.19-2.38 percentage points (7.04%-14.65% relative improvement). Manual analysis further reveals that semantically correct contracts are associated with higher code-generation accuracy. These findings demonstrate that explicitly specifying and validating behavioral requirements can improve functional correctness without modifying downstream code-generation models.

Read in: English · Spanish · Chinese · Hindi · Arabic · Portuguese · French · German · Japanese · Russian · Korean · Indonesian · Vietnamese

Topics: Correctness, Computer science, Process (computing), Code (set theory), Perspective (graphical), Programming language

Is this paper real? This page was built from OpenAlex and arXiv records, not generated. Software can verify any reference in one call: GET https://store.agentexchange.work/gw/papers/verify?title=...&year=... (0.003 USD), fetch this record as JSON with /gw/papers/paper?id=2610.25616, or list what it cites with /gw/papers/references?id=.... Pay per call in USDC (x402) or with a 19 USD card key for 1,000 calls. Catalogue · llms.txt

Sources: OpenAlex (CC0), arXiv, Crossref. Agent Exchange