[Paper Review] nl2spec: Interactively Translating Unstructured Natural Language to Temporal Logics with Large Language Models
nl2spec is a framework that uses Large Language Models (LLMs) to interactively translate unstructured natural language requirements into formal temporal logic specifications (e.g., LTL), by decomposing input into sub-translations that users can edit. It achieves 86.11% accuracy in formalizing complex, ambiguous requirements through iterative refinement, reducing manual redrafting and improving error correction efficiency.
A rigorous formalization of desired system requirements is indispensable when performing any verification task. This often limits the application of verification techniques, as writing formal specifications is an error-prone and time-consuming manual task. To facilitate this, we present nl2spec, a framework for applying Large Language Models (LLMs) to derive formal specifications (in temporal logics) from unstructured natural language. In particular, we introduce a new methodology to detect and resolve the inherent ambiguity of system requirements in natural language: we utilize LLMs to map subformulas of the formalization back to the corresponding natural language fragments of the input. Users iteratively add, delete, and edit these sub-translations to amend erroneous formalizations, which is easier than manually redrafting the entire formalization. The framework is agnostic to specific application domains and can be extended to similar specification languages and new neural models. We perform a user study to obtain a challenging dataset, which we use to run experiments on the quality of translations. We provide an open-source implementation, including a web-based frontend.
Motivation & Objective
- To address the challenge of writing formal, error-prone system specifications manually, which limits the adoption of formal verification techniques.
- To reduce the cognitive load and error rate in formal specification authoring by enabling interactive, incremental refinement of LLM-generated translations.
- To detect and resolve ambiguity in natural language requirements—especially around operator precedence and semantic vagueness—through sub-translation editing.
- To design a framework that is agnostic to specific LLMs and specification languages, enabling extensibility to domains like STL or SVA.
- To evaluate the framework’s effectiveness using a benchmark dataset from expert user studies, demonstrating improved accuracy and usability.
Proposed method
- The framework decomposes natural language inputs into sub-translations, where each formula fragment is mapped back to a corresponding natural language phrase.
- It employs an interactive few-shot prompting scheme with LLMs to generate these sub-translations, allowing users to add, edit, or delete them without rewriting the entire formalization.
- Each sub-translation is accompanied by a confidence score and alternative suggestions, enabling users to iteratively correct errors and resolve ambiguity.
- The system supports user edits via explicit syntax changes (e.g., adding parentheses) to resolve precedence ambiguities, such as in 'a holds until b holds or always a holds'.
- The backend uses LLMs (e.g., Codex) to generate initial translations, and users refine them through up to three translation loops in practice.
- The framework is implemented as a web-based tool with open-source availability, supporting integration with various temporal logic languages.
Experimental results
Research questions
- RQ1Can LLMs effectively decompose natural language requirements into semantically meaningful sub-translations that support interactive refinement?
- RQ2Does interactive editing of sub-translations significantly improve the accuracy and usability of formal specification generation compared to monolithic translation?
- RQ3How effective is the sub-translation methodology in resolving ambiguity in natural language requirements, particularly around operator precedence and semantic vagueness?
- RQ4To what extent can users correct erroneous formalizations through minimal edits to sub-translations, rather than rewriting entire formulas?
- RQ5What is the end-to-end translation accuracy of the framework on a challenging, expert-validated benchmark dataset of ambiguous and complex requirements?
Key findings
- nl2spec achieved an end-to-end translation accuracy of 86.11% on a benchmark of 36 expert-validated natural language requirements, correctly formalizing 31 out of 36 instances.
- On average, only 1.4 translation loops were needed to achieve correct formalization, with 15 of 20 incorrectly translated instances corrected in ≤3 loops.
- The sub-translation methodology enabled correction of ambiguous cases such as 'a holds until b holds or always a holds' by editing the sub-translation to clarify operator precedence.
- Editing sub-translations like 'b must hold in the next two steps' to 'b | X b' resolved a semantic ambiguity that initially led to incorrect nesting in the formula.
- The framework reduced the need for manual redrafting: only five of the 36 instances required full manual re-encoding, while 31 were fixed via sub-translation edits.
- Even with a weaker model like Codex, the sub-translation approach improved translation success by 4 instances compared to direct prompting, demonstrating the method’s robustness.
Read this paper
Open the full text in the Nubint reader and ask about any passage as you read.
Read this paper on NubintThis review was generated by AI from the original paper. Please check the paper before citing it.