botiverse.bots.TaskBot package#

Submodules#

botiverse.bots.TaskBot.TaskBot module#

This module contains the base code and interface of deep Taskbot .

class botiverse.bots.TaskBot.TaskBot.TaskBot(domains=[], slot_list=[], start=[], templates=[], label_maps={}, policy='Priority', non_referable_slots=[], non_referable_pairs=[], from_scratch=True, BERT_config=<botiverse.models.BERT.config.BERTConfig object>, TRIPPY_config=<botiverse.models.TRIPPY.config.TRIPPYConfig object>, verbose=False, append_state=False)[source]#

Bases: object

Instantiate a Deep Task Oriented Dialogue System chat bot. It aims to assist the user in completing certain tasks in specific domains. The chat bot can use a Deep learning approach for training and inference.

Parameters:
  • domains (list[str]) – List of domain names.

  • slot_list (list[str]) – List of slot names.

  • start (list[dict]) – List of initial system utterances and corresponding system acts.

  • templates (list[dict]) – The predefined templates for generating responses.

  • label_maps (dict[str, list]) – Dictionary of the variants of the slot-values that are mapped to the canonical slot-values.

  • policy (str) – The dialogue policy to be used (‘Random’ or ‘Priority’).

  • non_referable_slots (list[str]) – List of non-referable slots, defaults to an empty list.

  • non_referable_pairs (list[tuple]) – List of non-referable slot-value pairs, defaults to an empty list.

  • from_scratch (bool) – Indicates whether to use BERT model implemented from scratch in the library, defaults to False.

  • BERT_config (BERTConfig) – The configuration of the BERT model, defaults to BERTConfig().

  • TRIPPY_config (TRIPPYConfig) – The configuration of the TRIPPY model, defaults to TRIPPYConfig().

  • verbose (bool) – Indicates whether to print the chatbot’s state after each inference, defaults to False.

  • append_state (bool) – Indicates whether to append the dialogue state to the response when all slots are filled, defaults to False.

save_model(model_path)[source]#

Save the trained DST model to the given path.

Parameters:

model_path (str) – Path to save the trained DST model.

read_data(train_path, dev_path=None, test_path=None)[source]#

Read the training, development and testing data and store them in the chatbot.

Parameters:
  • train_path (str) – Path to the training data file.

  • dev_path (str) – Path to the development data file, defaults to None.

  • test_path (str) – Path to the testing data file, defaults to None.

train()[source]#

Train the chatbot model with the given training data.

load_dst_model(model_path=None, pretrained='sim-R', test_path=None)[source]#

Load a trained DST model from the given path.

Parameters:
  • model_path (str) – Path to the trained DST model.

  • pretrained (str) – The pretrained model to be used defaults to ‘sim-R’.

  • test_path (str) – Path to the testing data file, if applicable, defaults to None.

infer(user_utter)[source]#

Infer a suitable response to the user’s utterance.

Parameters:

user_utter (str) – The user’s input utterance.

Returns:

The chatbot’s response.

Return type:

str

infer_with_state(user_utter, line_breaker='<br/>')[source]#

Infer a suitable response to the user’s utterance and return the dialogue state.

Parameters:

user_utter (str) – The user’s input utterance.

Returns:

The chatbot’s response and the dialogue state concatenated into a single string.

Return type:

str

suggest(template)[source]#

Set the system utterance and system act to suggest a specific response.

Parameters:

template (dict) – The template containing the suggested system utterance and system act.

get_dialogue_state()[source]#

Get the dialogue state.

Returns:

The dialogue state.

Return type:

dict

delete_slots(domain=None, slot=None)[source]#

Delete slots from the dialogue state.

Note that: if domain!=None will delete all slots in that domain. if slot!=None will delete that slot. if both are None will delete all slots in all domains.

Parameters:
  • domain (str) – The domain from which to delete slots, defaults to None.

  • slot (str) – The slot to delete, defaults to None.

reset()[source]#

Reset the chatbot’s state.

botiverse.bots.TaskBot.utils module#

This module ontains utility code used by the deep Taskbot module such as Natural Language Understanding (NLU), Dialogue State Tracker (DST) … etc.

class botiverse.bots.TaskBot.utils.PriorityDP[source]#

Bases: object

Dialogue Policy Optimizer that selects the next action based on priority.

This policy selects the action with the highest priority that does not conflict with the slots already filled in the dialogue state.

get_action(state, templates_slots)[source]#

Get the next action based on the given dialogue state and available action templates.

Parameters:
  • state (dict) – The current dialogue state.

  • templates_slots (list[tuple]) – The available different combinations of slots that can be filled by templates.

Returns:

The index of the selected action template, or None if no action is available.

Return type:

int or None

class botiverse.bots.TaskBot.utils.RandomDP[source]#

Bases: object

Dialogue Policy Optimizer that selects the next action randomly.

This policy selects the action randomly from the available action templates that do not conflict with the slots already filled in the dialogue state.

get_action(state, templates_slots)[source]#

Get the next action based on the given dialogue state and available action templates.

Parameters:
  • state (dict) – The current dialogue state.

  • templates_slots (list[tuple]) – The available different combinations of slots that can be filled by templates.

Returns:

The index of the selected action template, or None if no action is available.

Return type:

int or None

class botiverse.bots.TaskBot.utils.TemplateBasedNLG(templates)[source]#

Bases: object

Natural Language Generation module that generates responses based on predefined templates.

This module uses a set of predefined templates containing utterances and corresponding system acts. Given an index, it generates the corresponding system utterance and system act.

Parameters:

templates (list[dict]) – The predefined templates for generating responses.

get_templates()[source]#

Get the predefined templates.

Returns:

The predefined templates.

Return type:

list[dict]

get_templates_slots()[source]#

Get the slots associated with the predefined templates.

Returns:

The slots associated with the predefined templates.

Return type:

list[tuple]

generate(idx)[source]#

Generate a response based on the given index.

Parameters:

idx (int) – The index of the template to generate a response from.

Returns:

The generated system utterance and system act.

Return type:

tuple[str, list] or None

Module contents#