Skip to main content

Algorithm for learning DFA from demonstrations, examples, and language.

Project description

L*LM

PyPI version

Implementation of L*LM algorithm algorithm. See project page for details.

Table of Contents

Installation

If you just need to use lstar_lm, you can just run:

$ pip install lstar_lm

For developers, note that this project uses the poetry python package/dependency management tool. Please familarize yourself with it and then run:

$ poetry install

Usage

The main entry points for using this library are the guess_dfa and dfa_search_with_diss functions.

  • guess_dfa supports labeled examples and natural language.
  • dfa_search_with_diss supports labeled examples, natural language, and demonstrations.
from lstar_lm import guess_dfa

An invocation of guess_dfa takes the form.

dfa = guess_dfa(
    positive = ...,  # List of positive examples. Each example is a list of tuples of tokens.
    negative = ...,  # List of negative examples. Each example is a list of tuples of tokens.
    alphabet = ...,  # List of (hashable) tokens.
    task_description = ...,  # String of task description.
    allow_unsure = ...,      # Whether to allow unsure responses (default True).
    random_iters = ...,      # Number of random queries to oracle.
    active_queries = ...,    # Number of active queries to oracle.
    use_dfa_identify = ...,  # True if use SAT based DFA identification. False uses L* + SAT hybrid.
    llm_endpoint = ...,      # http endpoint for llama.cpp server (default "http://localhost:8080/completion").
)

To learn using demonstrations, one can use dfa_search_with_diss to search for low energy DFAs:

search = dfa_search_with_diss(
     alphabet = ..., # List of (hashable) tokens.

     # ---- Passive identification params ---
     positive = ..., # List of positive examples. Each example is a list of tuples of tokens.
     negative = ..., # List of negative examples. Each example is a list of tuples of tokens.

     # ---- LLM oracle params ----
     task_description = ...,              # String of task description.
     llm_params = ...,                    # Dictionary of llama.cpp parameters.
     llm_query_callback = ...,            # Callback sent prompt, response.
     llm_endpoint = ...,                  # http endpoint for llama.cpp server
                                          #    (default "http://localhost:8080/completion").
     allow_unsure = ...,                  # Whether to allow LLM to output unsure.

     # --- Active learning params ---
     random_iters = ...,                  # Number of random queries to oracle.
     active_queries = ...,                # Number of active queries to oracle.
     use_dfa_identify = ...,              # True if use SAT based DFA identification.
                                          # False uses L* + SAT hybrid.

     # --- Demonstration learning parameters ---
     demonstrations = ...,                # List of expert demonstrations
     max_diss_iters = ...,                # Maximum number of diss iterations.
     to_chain = ...,                      # Converted dfa concept to annotated markov chain given
                                          #   a maximum entropy policy. See DISS documentation.
     diss_params,                         # Other DISS parameters to override defaults.
)


mle = min(search, key=lambda _1, _2, metadata: metadata['energy'])
conjectured_examples, concept, metadata = mle
dfa = concept.dfa  # Most likely dfa

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

lstar_lm-0.2.1.tar.gz (5.9 kB view details)

Uploaded Source

Built Distribution

lstar_lm-0.2.1-py3-none-any.whl (7.3 kB view details)

Uploaded Python 3

File details

Details for the file lstar_lm-0.2.1.tar.gz.

File metadata

  • Download URL: lstar_lm-0.2.1.tar.gz
  • Upload date:
  • Size: 5.9 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/1.7.1 CPython/3.11.7 Linux/6.1.52-valve17

File hashes

Hashes for lstar_lm-0.2.1.tar.gz
Algorithm Hash digest
SHA256 42d398aed84f84757e38a8011acf982c292e42a90be9812b25d2bafb5357278b
MD5 808f712db03a0d6d0798d70c6cbe0209
BLAKE2b-256 6642d1c3c665be353e3b3ba2296bbe0cebd0cd46b9276cb54c11a8caf28d2f63

See more details on using hashes here.

File details

Details for the file lstar_lm-0.2.1-py3-none-any.whl.

File metadata

  • Download URL: lstar_lm-0.2.1-py3-none-any.whl
  • Upload date:
  • Size: 7.3 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/1.7.1 CPython/3.11.7 Linux/6.1.52-valve17

File hashes

Hashes for lstar_lm-0.2.1-py3-none-any.whl
Algorithm Hash digest
SHA256 9e301fc16ff2dda483faa02d7b9b7e8c9cb7b45742d34221ccb247c41a0c9379
MD5 08652ecb69955f7e30c01a53f8d35cb4
BLAKE2b-256 1fcc1811f198869316de6d72a4816f682de2b29abf57bc9d67d1ffb4a2937c17

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page