Chatbot
Chatbot Xircuits Project Template
This template allows you to train a chat model and start a chatbot in a terminal.
It consists of 5 components:
Dataset preparation
- LoadData : Load CSV file that provides the
patterns
,intents
, andresponses
. To edit the training data, you may add/delete row/pattern/response in the existingresource/sample.csv
or provide your own CSV file path. See more at this section. - Tokenize : Tokenizer that turns the texts into space-separated sequences of words (by default all punctuations will be removed), and these sequences are then split into lists of tokens.
- LoadData : Load CSV file that provides the
Model training
- CustomModel : Custom neural network model that consists of Embedding layer, a Global Average Pooling 1D layer, a number of Dense layers with relu activation and lastly a Dense layer with softmax activation. Optimizer, loss function and metric can be adjusted.
- Train : Train model with defined epochs number and save model at
model_output_path
.training_sentences
andtraining_labels
will be used to train the model.
Inference
- SingleInference : Single sentence inference. This component takes one text input and predicts its intent. Also, gives a response if responses data is provided.
Prerequisites
Python 3.9
Installation
- Clone this repository
git clone https://github.com/XpressAI/template-chatbot
- Run the setup script that creates a virtual environment and install the required python packages
bash setup.sh
- Run xircuits from the root directory
xircuits
Workflow in this Template
Training
TrainChatModel.xircuits
Train a chat model that try to predict the intents based on sentences patterns.
What are/Why Patterns and Intents?
In order to answer questions, search from domain knowledge base and perform various other tasks to continue conversations with the user, a chatbot needs to understand what the users say or what they intend to do (identify user’s intention). The strategy here is to define different intents and make training samples for those intents.
Patterns in our case refer to training samples for different intents. Intents in case are the training categories/labels our model will predict. The model would try to match a particular input with its known intent.
See resource/sample.csv as dataset example.
How Can I Change the Training Data?
To edit the training data, you may add/delete row/pattern/response in the existing resource/sample.csv
. Or, provide your own CSV file and provide its path at LoadData
input, csv_file_path
. The input CSV file should provide these three columns patterns
, intents
, and responses
.
Terms We Use
Patterns
are training samples/possible user inputs for corresponding intent.Intents
are user intentions, also training categories/labels.Responses
are response texts to send to user after getting the predicted tag from model with user input (only used during inference but not model training). See the workflow Inference.xircuits
Example:
Inference
Inference.xircuits
Single prediction on input text.
Example: