논문 해설
Can Large Language Models Transform Natural Language Intent into Formal Method Postconditions?
대형 언어 모델은 자연어 의도를 형식 메서드의 사후조건으로 변환할 수 있는가?
- 연구 문제 자연어 의도를 검사 가능한 사후조건으로 바꾸는 문제를 LLM으로 다룹니다.
- 연구 방법 프롬프트로 자연어 명세에서 사후조건을 생성하고 정확성과 완전성 지표로 평가합니다.
- 주요 결과 EvalPlus에서 최선의 설정은 생성 사후조건의 77%가 올바르며, Defects4J에서는 64개 역사적 버그를 구별하는 사후조건을 찾았습니다.
자연어 의도를 검사 가능한 사후조건으로 바꾸는 문제
코드 주석이나 함수 문서에 담긴 자연어 명세는 프로그램의 의도를 많이 담고 있지만, 구현과 문서가 일치한다는 보장이 없습니다. 자연어는 모호하여 프로그램으로 직접 검사하기 어렵고, 기존의 번역 방법은 구조화된 입력이나 nullness·예외 같은 제한된 명세 종류에 머무르는 경우가 많습니다. 이 논문은 LLM을 이용해 자연어 메서드 설명을 프로그램 어서션 형태의 사후조건으로 옮기는 문제를 nl2postcond로 정의합니다. 사후조건은 메서드의 입력과 출력 상태 사이의 관계를 나타내는 어서션으로, 성공적인 실행 뒤에 참이어야 합니다. 이 문제를 풀려면 생성된 사후조건이 의도에 맞는지와 잘못된 코드를 구별하는지를 측정할 수 있어야 합니다.

Fig. 3 . Prompt template for generating postconditions from natural language via chat models (including changes needed for thesimple and no reference variations). We found that the bold text greatly improved the quality of the postconditions: without it, the model tended to return point-based tests or code blocks with side effects. While modified here slightly for clarity, our full prompts are included in our replication package.
원문 · CC BY 4.0 · Madeline Endres, Sarah Fakhoury, Saikat Chakraborty, Shuvendu K. Lahiri · Can Large Language Models Transform Natural Language Intent into Formal Method Postconditions? · 원문 그림 인용 · 원본 PDF 6쪽에서 그림 영역을 추출했습니다.사후조건의 정확성과 완전성 지표
이 논문은 사후조건의 품질을 두 축으로 측정합니다. 첫째 test-set correctness는 기준 구현 r이 테스트 집합 T의 모든 입력에서 사후조건을 만족하는지 보는 기준입니다. 여러 후보 중 적어도 하나가 올바를 확률을 accept@k로 정의하며, 이는 코드 생성의 pass@k에서 착안되었습니다. 둘째 bug-completeness-score는 올바른 사후조건이 코드 뮤턴트 집합 CM 중 몇 개를 실패시키는지를 셉니다. 이 값은 사후조건이 실패시키는 뮤턴트의 수를 |CM|으로 나눈 비율이며, 뮤턴트 집합 전체에 대해 정규화됩니다. 논문은 가장 강한 사후조건을 직접 구하기 어렵기 때문에 이 완전성 개념으로 대신합니다.
EvalPlus에서의 사후조건 정확성과 완전성
RQ1은 EvalPlus의 164개 Python 문제에서 GPT-3.5, GPT-4, StarChat이 생성한 사후조건을 평가합니다. 가장 좋은 프롬프트 변형에서 GPT-4의 simple 프롬프트는 생성된 사후조건의 77%를 테스트 집합 기준으로 올바르게 만들었고, 올바른 사후조건이 생긴 문제는 164개 중 158개였습니다. 완전성 측면에서 base 프롬프트의 GPT-4 사후조건은 bug-completeness가 높게 나타났으며, 논문은 올바른 사후조건이 평균적으로 뮤턴트의 약 3/4 이상을 구별한다고 보고합니다. 다만 simple 프롬프트는 correctness를 높이는 대신 완전성 점수를 낮추는 경향이 있었고, 자연 뮤턴트만 쓰면 점수가 더 낮게 나타났습니다.

Table 1 . Test-set correctness on EvalPlus for three models (GPT-3.5,GPT-4, andStarChat), differing prompt complexities (base vs.simple), and including or omitting the reference solution in the prompt. Darker highlighted cells are more correct. Bolded values are the largest for a specific model.
원문 · CC BY 4.0 · Madeline Endres, Sarah Fakhoury, Saikat Chakraborty, Shuvendu K. Lahiri · Can Large Language Models Transform Natural Language Intent into Formal Method Postconditions? · 원문 그림 인용 · 원본 PDF 9쪽에서 그림 영역을 추출했습니다.
Table 2 . Table of bug-completeness for EvalPlus.% bug-complete is the % of postconditions that detect all buggy code mutants.% problems with bug-complete is the % of all EvalPlus problems with at least onebug-complete postcondition.% problems union bug-complete is the % of problems where the union of correct postconditions isbug-complete. Finally, the last two columns are the average bug-completeness-score, a fraction between 0 and 1, for all correct postconditions, normalized by EvalPlus problem. We report this for both natural and all generated code mutants. Bolded values are the largest value per column per model.
원문 · CC BY 4.0 · Madeline Endres, Sarah Fakhoury, Saikat Chakraborty, Shuvendu K. Lahiri · Can Large Language Models Transform Natural Language Intent into Formal Method Postconditions? · 원문 그림 인용 · 원본 PDF 11쪽에서 그림 영역을 추출했습니다.Defects4J에서 실제 역사적 버그 탐지
RQ2는 Java 8에서 재현 가능한 525개 Defects4J 버그를 대상으로 합니다. 사후조건이 버그를 탐지한다는 것은 수정 전 함수에서 trigger 또는 regression 테스트를 실패시키고, 수정 후 함수에서는 모든 테스트를 통과하는 경우입니다. 이 설정에서 GPT-4는 최대 47개 버그를 구별하는 사후조건을 생성했고, StarChat은 25개를 구별했습니다. 두 모델과 모든 프롬프트 변형을 합치면 70개 버그 메서드에서 64개의 고유한 버그를 찾았으며, 이는 사용된 버그의 12.2%에 해당합니다. 이 결과는 주로 Defects4J 버그 집합과 이 논문의 프롬프트 설정에 대한 것입니다.

Table 4 . Table containing our Defects4J results for postconditions generated for 840 methods across 525 historical bugs. We report the likelihood of generated postconditions to compile, and the likelihood that they pass all tests when instrumenting the fixed function (test-set correct columns). # distinguishable bugs is the number of bugs for which at least one generated postcondition was discriminating (see Section 4.1.2).
원문 · CC BY 4.0 · Madeline Endres, Sarah Fakhoury, Saikat Chakraborty, Shuvendu K. Lahiri · Can Large Language Models Transform Natural Language Intent into Formal Method Postconditions? · 원문 그림 인용 · 원본 PDF 14쪽에서 그림 영역을 추출했습니다.기준 방법과 적용 한계
논문은 TOGA와 Daikon과 비교합니다. TOGA는 테스트 오라클을 생성하고, Daikon은 실행으로부터 불변식을 추론합니다. Defects4J 비교에서 두 방법과 nl2postcond가 잡은 버그는 상당 부분 겹치지 않았으며, 저자들은 두 접근이 서로 보완적일 수 있다고 해석합니다. 한계로서 평가는 525개 버그로 제한되어 있고, 사용한 벤치마크가 학습 데이터에 포함되었을 가능성이 있으며, OpenAI 모델은 갱신되거나 폐기될 수 있어 재현성에 위험이 있습니다. 완전성 지표 역시 생성된 뮤턴트 집합에 의존하므로 모든 가능한 버그를 대표하지 않습니다.
논문 정보
- 저자
- Madeline Endres, Sarah Fakhoury, Saikat Chakraborty, Shuvendu K. Lahiri
- 학회·저널
- arXiv · 프리프린트
- 최초 공개일
- 2023년 10월 3일
- 등록일
- 2026년 11월 6일
- 수정일
- 2024년 4월 15일
- 버전
- v2
- arXiv
- 2310.01831
- 분류
- cs.SE · cs.AI · cs.PL
- 원문 이용 조건
- CC BY 4.0
- 제공 범위
- 논문 정보, 해설, 허용된 원문 그림
AI 해설은 논문 원문과 별개의 설명이며 오류가 있을 수 있습니다. 원문과 그림은 각 출처의 이용 조건과 따로 표시된 권리를 따릅니다.
초록
Informal natural language that describes code functionality, such as code comments or function documentation, may contain substantial information about a programs intent. However, there is typically no guarantee that a programs implementation and natural language documentation are aligned. In the case of a conflict, leveraging information in code-adjacent natural language has the potential to enhance fault localization, debugging, and code trustworthiness. In practice, however, this information is often underutilized due to the inherent ambiguity of natural language which makes natural language intent challenging to check programmatically. The emergent abilities of Large Language Models (LLMs) have the potential to facilitate the translation of natural language intent to programmatically checkable assertions. However, it is unclear if LLMs can correctly translate informal natural language specifications into formal specifications that match programmer intent. Additionally, it is unclear if such translation could be useful in practice. In this paper, we describe nl2postcond, the problem of leveraging LLMs for transforming informal natural language to formal method postconditions, expressed as program assertions. We introduce and validate metrics to measure and compare different nl2postcond approaches, using the correctness and discriminative power of generated postconditions. We then use qualitative and quantitative methods to assess the quality of nl2postcond postconditions, finding that they are generally correct and able to discriminate incorrect code. Finally, we find that nl2postcond via LLMs has the potential to be helpful in practice; nl2postcond generated postconditions were able to catch 64 real-world historical bugs from Defects4J.
원문 인용
Madeline Endres, Sarah Fakhoury, Saikat Chakraborty, Shuvendu K. Lahiri (2023). Can Large Language Models Transform Natural Language Intent into Formal Method Postconditions?. arXiv:2310.01831v2. https://arxiv.org/abs/2310.01831v2
BibTeX
@misc{endres2023large,
title = {{Can Large Language Models Transform Natural Language Intent into Formal Method Postconditions?}},
author = {Madeline Endres and Sarah Fakhoury and Saikat Chakraborty and Shuvendu K. Lahiri},
year = {2023},
eprint = {2310.01831},
archivePrefix = {arXiv},
url = {https://arxiv.org/abs/2310.01831v2}
}