Giter VIP home page Giter VIP logo

nl2spec's Introduction

Overview

nl2spec is a framework for applying Large Language Models (LLMs) to derive formal specifications (in temporal logics) from unstructured natural language. It introduces a new methodology to detect and resolve the inherent ambiguity of system requirements in natural language by utilizing 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 tool works best when providing in-distribution few-shot examples (see Prompting). It can be easily adjusted to other models by extending the backend (see Extendability).

Install

Fulfill dependencies:

All model inferences run in the cloud. Therefore, access to the respective APIs is necessary.

Run frontend

From inside the src folder:

  • create the following file and paste your open ai, hf key or google project id into: keys/oai_key.txt, keys/hf_key.txt or keys/google_project_id.txt
  • python3 -m flask --app frontend.py run
  • add --debug for debug mode
  • Then open web-based tool at http://127.0.0.1:5000

Run from terminal

Can also be run from command line from the scr folder. See python3 nl2ltl.py --help for more details.

E.g., with gpt-3.5:

python3 nl2ltl.py --model gpt-3.5-turbo --keyfile PATH/TO/YOUR/OPENAIKEY --nl "Globally a and b until c." --num_tries 3 --temperature 0.2 --prompt minimal

or bloom

python3 nl2ltl.py --model bloom --keyfile PATH/TO/YOUR/HFKEY --nl "Every request is eventually followed by a grant." --num_tries 3 --temperature 0.2 --prompt minimal

or PaLM

python3 nl2ltl.py --model text-bison@001 --keyfile PATH/TO/YOUR/GCLOUD/PROJECTID --nl "Every request is eventually followed by a grant." --num_tries 3 --temperature 0.2 --prompt minimal

Prompting

The prompting pattern consists of a short introduction to the specification language, followed by few-shot examples that exploit the LLM to construct subtranslations. We provide four example prompts in /prompts:

  • minimal.txt - the generic prompt used for the user study experiments in the paper
  • indistribution.txt - the prompt with few-shot examples drawn from the user study
  • smart.txt - a prompt obtained from examples in a recently conducted smart home user study
  • stl.txt - a proof of concept extension for Signal Temporal Logic (STL)

See the paper and /prompts for more details. The prompts in nl2spec must follow a specific pattern to obtain the subtranslations as follows.

<Specification Language Tutorial>

Followed by few shot examples, where each few shot example consists of the following:

<Natural Language input>

<Given translations, as a dictionary>

<Explanation of the translation>

<Explanation dictionary>

<Final Translation>

Extendability

The tool can be easily extended to other specification languages based on temporal logics (see /prompts/stl.txt). The best performance is expected when drawing the few-shot examples from the distribution to translate. Adding a few well-crafted examples to the prompt and then using the tool to translate the rest of the workload is significantly easier than translating every requirement from scratch.

Additionally, the tool can be extended to more fine-tuned or other upcoming open-source language models. To this end, backend.py must be extended with a new new_model, for which a method named new_model must be implemented in models.py.

How to cite

@inproceedings{nl2spec,
	title = {nl2spec: Interactively Translating Unstructured Natural Language to Temporal Logics with Large Language Models},
	author = {Cosler, Matthias and Hahn, Christopher and Mendoza, Daniel and Schmitt, Frederik and Trippel, Caroline},
	booktitle = {Computer {Aided} {Verification}},
	series = {Lecture {Notes} in {Computer} {Science}},
	address = {Cham},
	isbn = {978-3-031-37703-7},
	shorttitle = {nl2spec},
	doi = {10.1007/978-3-031-37703-7_18},
	language = {en},
	publisher = {Springer Nature Switzerland},
	editor = {Enea, Constantin and Lal, Akash},
	year = {2023},
	pages = {383--396},
}

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.