Package: nl2ltl
NL 2 LTLNL2LTL is an interface to translate natural language (NL) utterances to
linear temporal logic (LTL) formulas.🏆 NL2LTL won the People's Choice Best System Demonstration Award Runner-Up in the ICAPS 2023 System Demonstration
Track in Prague. Read more about ithere.Installationfrom PyPI:pipinstallnl2ltlfrom source (mainbranch):pipinstallgit+https://github.com/IBM/nl2ltl.gitor clone the repository and install the package:gitclonehttps://github.com/IBM/nl2ltl.gitcdnl2ltl
pipinstall-e.QuickstartOnce you have installed all dependencies you are ready to go with:fromnl2ltlimporttranslatefromnl2ltl.engines.gpt.coreimportGPTEngine,Modelsfromnl2ltl.filters.simple_filtersimportBasicFilterfromnl2ltl.engines.utilsimportprettyengine=GPTEngine()filter=BasicFilter()utterance="Eventually send me a Slack after receiving a Gmail"ltlf_formulas=translate(utterance,engine,filter)pretty(ltlf_formulas)Thetranslatefunction takes a natural language utterance, an engine and an
option filter, and outputs the best matchingpylogicsLTL formulas.NOTE: Before using theNL2LTLtranslation function, depending on the
engine you want to use, make sure all preconditions for such an engine are met.
For instance, Rasa requires a.tar.gzformat trained model in themodels/folder to run. To train the model use the available NL2LTLtrain(...)API.NLU EnginesGPT-3.xlarge language modelsGPT-4large language modelRasaintents/entities classifier (to use Rasa, please install it withpip install -e ".[rasa]")Watson Assistantintents/entities classifier -- PlannedNOTE: To use OpenAI GPT models don't forget to add theOPEN_API_KEYenvironment
variable with:exportOPENAI_API_KEY=your_api_keyWrite your own EngineYou can easily write your own engine (i.e., intents/entities classifier,
language model, etc.) by implementing the Engine interface:fromnl2ltl.engines.baseimportEnginefrompylogics.syntax.baseimportFormulaclassMyEngine(Engine):deftranslate(self,utterance:str,filtering:Filter)->Dict[Formula,float]:"""From NL to LTL."""Then, use it as a parameter in the main entry point:my_engine=MyEngine()ltl_formulas=translate(utterance,engine=my_engine)Write your own FilterYou can easily write your own filtering algorithm by implementing
the Filter interface:fromnl2ltl.filters.baseimportFilterfrompylogics.syntax.baseimportFormulaclassMyFilter(Filter):defenforce(self,output:Dict[Formula,float],entities:Dict[str,float],**kwargs)->Dict[Formula,float]:"""Filtering algorithm."""Then, use it as a parameter in the main entry point:my_engine=MyEngine()my_filter=MyFilter()ltl_formulas=translate(utterance,engine=my_engine,filter=my_filter)DevelopmentContributions are welcome! Here's how to set up the development environment:set up your preferred virtualenv environmentclone the repo:git clone https://github.com/IBM/nl2ltl.git && cd nl2ltlinstall dependencies:pip install -e .install dev dependencies:pip install -e ".[dev]"install pre-commit:pre-commit installsign-off your commits using the-sflag in the commit message to be compliant with
theDCOTestsTo run tests:toxTo run the code tests only:tox -e py310DocsTo build the docs:mkdocs buildTo view documentation in a browser:mkdocs serveand then go tohttp://localhost:8000Citing@inproceedings{icaps2023fc,
  author       = {Francesco Fuggitti and  Tathagata Chakraborti},
  title        = {{NL2LTL} -- A Python Package for Converting Natural Language ({NL}) Instructions to Linear Temporal Logic ({LTL}) Formulas},
  booktitle    = {{ICAPS}},
  year         = {2023},
  note         = {Best System Demonstration Award Runner-Up.},
  url_code     = {https://github.com/IBM/nl2ltl},
}and@inproceedings{aaai2023fc,
  author       = {Francesco Fuggitti and  Tathagata Chakraborti},
  title        = {{NL2LTL} -- A Python Package for Converting Natural Language ({NL}) Instructions to Linear Temporal Logic ({LTL}) Formulas},
  booktitle    = {{AAAI}},
  year         = {2023},
  note         = {System Demonstration.},
  url_code     = {https://github.com/IBM/nl2ltl},
}