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 tag, intent context_set, intent responses, intent flags}

Example

predictor.query('Turn on the lights') -> {'lights_on', None, 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":<Object - 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": None,
        "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": None,
        "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.1.1.tar.gz (6.2 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.1.1-py3-none-any.whl (6.4 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: alvan-text-predictor-1.1.1.tar.gz
  • Upload date:
  • Size: 6.2 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.1.1.tar.gz
Algorithm Hash digest
SHA256 fbf4b13b84239412f3de101e6e39dde863a70c9c9e1961c1df17a8383c9939c4
MD5 0b4d28ff16b6829432b2de9962366f09
BLAKE2b-256 561ec986c3432e990c7ea4fbdb1211ace3e6e385c0b5d624b6db14b81c5dfa8d

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for alvan_text_predictor-1.1.1-py3-none-any.whl
Algorithm Hash digest
SHA256 61711d24003626b0129f7ec1622fef0b1cac0b1d389a84a53e0511d8ea907f92
MD5 224662ef3d79c376edfdf57b1cba9f94
BLAKE2b-256 4b6e1b5f8ecd94c1dfe908c044c1fc36579fb807e2b9f8c0f8cbeb337d0ff749

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