Skip to main content

The text prediction module for ALVAN 5.

Project description

A5-Server-Text-Prediction-Module

Module to predict which action a query best fits

To Install

pip install alvan-text-predictor

To Use

from prediction import predictor as pd

predictor = pd.Predictor('intents.json')

predictor.query('turn the lights off')

Predictor(intents_filename: str, pickle_file: str="data.pickle", intents_cache_file: str="intents_cache") -> Predictor

The constructor for the Predictor class takes in 1 required and 2 optional parameters: intents_filename, pickle_file, and intents_cache_file

Parameter Type Required Default Description
intents_filename str "" Filename for the intents file, used to train the model.
pickle_file str "data.pickle" Filename for the file that contains/will contain the serialized model-training output
intents_cache_file str "intents_cache" Filename for the intents cache. This is used to detect if any changes have been made to the original intents file. If the contents of this file differ from the file passed into the intents_filename, the model will be retrained and the contents of this file and the pickle_file will be overwritten with the contents of the intents_filename file, and the serialized output of the training.

query(query)

The query method takes in a query, compares it to the trained intents, and replies with an object indicating which intent it most closely matches.

The output has the following shape:

{intent responses, intent flags}

Example

predictor.query('Turn off the lights') -> {4, {"followup": 0}}

based on example below

Intents File

The intents file is a json file with the following shape:

{"intents": [
    <List of Objects representing intents with the following shape:
    {
        "tag":<String - human-readable descriptor>,
        "patterns": [<List of Strings - various ways a user could phrase their query],
        "responses": <Int - unique id of the intent>,
        "context_set":<String - currently unused metadata>,
        "flags": <Object with boolean values for flags used by the consumer>
    }
    >
]}

Example:

{"intents": [
    {
        "tag":"lights_on",
        "patterns": [
            "turn on the lights",
            "it is too dark in here",
            "I want the lights on",
            "I want it brighter in here"
        ],
        "responses":4,
        "context_set":"",
        "flags": {"followup": 0}
    },
    {
        "tag":"lights_off",
        "patterns": [
            "turn off the lights",
            "it is too bright in here",
            "I want the lights off",
            "I want it darker in here"
        ],
        "responses":5,
        "context_set":"",
        "flags": {"followup": 0}
    },
]}

Corequisites

nltk must be installed alongside.

pip install nltk

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

alvan-text-predictor-1.0.1.tar.gz (6.1 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

alvan_text_predictor-1.0.1-py3-none-any.whl (6.3 kB view details)

Uploaded Python 3

File details

Details for the file alvan-text-predictor-1.0.1.tar.gz.

File metadata

  • Download URL: alvan-text-predictor-1.0.1.tar.gz
  • Upload date:
  • Size: 6.1 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/5.0.0 CPython/3.9.18

File hashes

Hashes for alvan-text-predictor-1.0.1.tar.gz
Algorithm Hash digest
SHA256 ab5d707d913b8817405bde3fc872b393034a14e7e9f115fe8fd704dff5baae8f
MD5 fe650d3339ca5edea034f51ce88f61e6
BLAKE2b-256 8081b499ebe46cf84f3bc0aa0778d1bc8bd4a9f345eb571efef88ea468e002a1

See more details on using hashes here.

File details

Details for the file alvan_text_predictor-1.0.1-py3-none-any.whl.

File metadata

File hashes

Hashes for alvan_text_predictor-1.0.1-py3-none-any.whl
Algorithm Hash digest
SHA256 c6d7a56a1fb49c0cd290ce2328fa33c780393fb6d8a0db7f9757e79c5bf4d2f8
MD5 ac0ad9eb39cc88f4d83a6d30b466bbd9
BLAKE2b-256 1ba3d8493ede368f96b1e6e8ada1b89070a189d5d4fd1391047b2d374f9525f9

See more details on using hashes here.

Supported by

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