Skip to content

General Overview

Marcos Gomez Vazquez edited this page Jun 26, 2023 · 5 revisions

General Overview

Bot creation

The first step is to register the bot by making a post request to /bot/new/. The BotRequestDTO argument must contain the name and the force_overwrite condition of the bot

The second step is to initialize the bot with a post request to /bot/{name}/initialize. The BotDTO argument contains the bot contexts/states, entities and intents.

Bot training

Each bot context contains a set of intent references, which reference to the subset of the bot intents that can be triggered from that context. Therefore, each context stores a neural network in charge of predicting the user input's intent. We need a NN for each context so that the prediction labels (i.e. the intents) and the training data (i.e. the intent's training sentences) are specific for each context.

To train the bot (i.e. to train the contexts NNs), make a post request to /bot/{name}/train/. The ConfigurationDTO argument contains the NNs and training parameters.

The train method in training.py iterates over each bot context and trains its underlying NN. The process of training a NN is the following:

  • Get a list with all the preprocessed training sentences, labelled with their respective intents (which will be the class to predict). A preprocessed training sentence is a training sentence after going through the preprocess pipeline, which includes:

    • If NER is enabled, replacing sentence parameters by their respective entity names (e.g. 'I want to travel from CITY1 to CITY2' => 'I want to travel from CITY_ENTITY to CITY_ENTITY')

    • Preprocess the text, typically using a stemmer.

  • Tokenize the training sentences

  • Define the model (the NN), compile it and fit it to the training data.

Predictions

Once your chatbot is running, it is expected to answer your questions. This tool will predict the user utterance's intent, so your bot can know it and act properly (moving to the state linked to a transition triggered by a specific intent).

To predict a utterance's intent, make a post request to /bot/{name}/predict/. The PredictRequestDTO argument contains the utterance and the name of the current chatbot context (necessary to run its NN). The result is a PredictResultDTO containing a list of classifications, each of them containing the score of a specific intent (from 0 to 1) and the matched parameters (bot entities). Then, your bot can read all the classifications and decide which intent is the winner (based on your preferred policy, e.g. get the highest scored intent, if all scores are < 0.5 don't get any intent, etc.)

The predict method in prediction.py performs the task of getting a score for each available intent in the current context. The next figure shows the pipeline with an example.

xatkit-nlu-server intent prediction

The first step is to perform Named Entity Recognition, to find entities within the utterance. Since each intent may have different parameters, this process is done at intent level, once for each intent. Then, for all different sentences, the Intent Classification NN is run. Note that when all intents have no parameters, no parameters are found or the same parameters are found, the context NN will be run only once. It will always be run as many times as different sentences are generated by the NER process.

Clone this wiki locally