nl2spec: Interactively Translating Unstructured Natural Language to Temporal Logics with Large Language Models

Matthias Cosler, Christopher Hahn, Daniel Mendoza, Frederik Schmitt, Caroline Trippel

nl2spec: Interactively Translating Unstructured Natural Language to Temporal Logics with Large Language Models

TL;DR

nl2spec is a framework that leverages Large Language Models (LLMs) to bridge the gap between unstructured natural language and formal specifications like Linear-Time Temporal Logic (LTL). By decomposing complex requirements into interactive "sub-translations," the tool enables users to resolve ambiguity and correct errors through a web interface, increasing translation accuracy from 44% to over 86%.

Introduction: The Specification Bottleneck

In formal verification, ensuring a system (such as a self-driving car or a circuit) behaves correctly requires a "specification" written in a formal language like LTL. However, writing LTL is a manual, error-prone task typically reserved for logic experts. While AI-driven translation from natural language (NL) to logic has been explored, two major obstacles remain:

  1. Unstructured Language: Real-world requirements are often messy and full of linguistic nuances.
  2. Ambiguity: Natural language is inherently ambiguous (e.g., "A holds until B holds or always A holds"), making one-shot automated translation unreliable.

The nl2spec Framework

The authors of nl2spec address these challenges by creating an interactive system that invites the user into a debugging process rather than providing a static, "take it or leave it" translation.

System architecture of nl2spec showing the interaction between the user, frontend, and backend components.

The architecture consists of a frontend interface and a backend that manages prompts and neural models. The system uses Interactive Few-Shot Prompting to break down the translation process into manageable steps, allowing for ambiguity detection and iterative refinement.

Interactive Methodology

The core innovation of nl2spec is the use of sub-translations. Instead of generating a final formula immediately, the framework decomposes the input sentence into fragments and maps them to sub-formulas.

The nl2spec web interface demonstrating the decomposition of a natural language prompt into sub-translations with confidence scores.

Key components of this methodology include:

  • Chain-of-Thought Prompting: Encourages the LLM to "explain" its reasoning before providing the final LTL formula.
  • Human-in-the-Loop: Users can add, edit, or delete individual sub-translations. The LLM then uses these corrections as context to regenerate a more accurate final result.
  • Confidence Scores: By running multiple queries (voting), the system provides confidence scores for each sub-translation, highlighting potential errors for the user to review.

Key Results and Insights

The effectiveness of the interactive approach was validated through a study involving expert-provided, highly challenging requirements.

  • Accuracy Boost: Initial accuracy with a minimal prompt was 44.4%. After an average of just 1.4 interactive loops, accuracy jumped to 86.11%.
  • Superiority over Baselines: Existing tools like nl2ltl struggled with the unstructured dataset, achieving as low as 2.7% to 5.5% accuracy.
  • Decomposition as a Debugging Tool: The study found that humans are significantly better at verifying small fragments (sub-translations) than reading long, nested LTL formulas.
  • Teacher-Student Effect: High-quality sub-translations generated by a powerful model (like Codex) were shown to significantly improve the performance of weaker models (like Bloom), acting as a powerful form of context.

Conclusion and Future Work

While nl2spec significantly lowers the barrier to formal specification, it faces limitations regarding computational costs and the pre-training bias of underlying LLMs. Future work includes fine-tuning models specifically for sub-translation tasks and integrating the framework directly into formal verification development environments. By making formalization intuitive and interactive, nl2spec moves us closer to a future where rigorous system verification is accessible to all engineers.

Summary updated

BibTeX
@inproceedings{cosler2023nl,
  author = {Matthias Cosler and Christopher Hahn and Daniel Mendoza and Frederik Schmitt and Caroline Trippel},
  title = {{nl2spec: Interactively Translating Unstructured Natural Language to Temporal Logics with Large Language Models}},
  booktitle = {CAV},
  year = {2023},
  doi = {10.1007/978-3-031-37703-7\_18},
}
Figure