botiverse.bots.BasicBot package#

Submodules#

botiverse.bots.BasicBot.BasicBot module#

class botiverse.bots.BasicBot.BasicBot.BasicBot(machine='nn', repr='tf-idf')[source]#

Bases: object

An interface for a basic chatbot model suitable for small datasets such as FAQs. Note that the underlying model is not sequential (either an NN or an SVM).

Instantiate a basic chat bot model that uses a classic feedforward neural network. Data can be then used to train the chatbot model.

Parameters:
  • name (string) – The chatbot’s name.

  • machine (string) – The machine learning model to use. Either ‘nn’ or ‘svm’, else must be a model object that has appropriate fit and predict methods.

  • repr (string) – The representation to use. Either ‘glove’, ‘tf-idf’, or ‘tf-idf-glove’ or ‘bow’, else must be a model object that has appropriate transform_list and transform methods.

read_data(path)[source]#

Read the data from a JSON file found in path for the chatbot to train on later.

Parameters:

path – The path to the JSON file

train(max_epochs=None, early_stop=False, **kwargs)[source]#

Train the chatbot model with previously read data.

Parameters:
  • max_epochs (int) – The maximum number of epochs to train for. If None, then the number of epochs is 30 * len(self.classes)

  • early_stop (bool) – Whether to use early stopping or not. If True, the models stops whenever the validation loss stops decreasing for 100 epochs.

  • kwargs – Any additional arguments to pass to the model’s fit method.

save(path)[source]#

Save the chatbot model to a file. Not supported yet for SVM models.

Parameters:

path – The path to the file

load(load_path, data_path)[source]#

Load the model from a file.

Parameters:
  • load_path (string) – The path to the file

  • data_path (string) – The path to the JSON file containing the data used to train the model to sample responses from.

infer(prompt, confidence=None, test=False)[source]#

Infer a suitable response to the given prompt.

Parameters:
  • prompt (string) – The user’s prompt

  • confidence (float) – The minimum confidence (probability) required for the chatbot to respond. If None, then the confidence is 2/len(self.classes)

  • test (bool) – Whether to return the class of the prompt instead of a response. Helpful to test on unkonwn data.

Returns:

The chatbot’s response or the class of the prompt if test is True.

Return type:

string

Module contents#