botiverse.bots.BasicTaskBot package#
Submodules#
botiverse.bots.BasicTaskBot.BasicTaskBot module#
This module contains the base code and interface of basic Taskbot.
- class botiverse.bots.BasicTaskBot.BasicTaskBot.BasicTaskBot(domains_slots, templates, domains_pattern, slots_pattern, verbose=False, append_state=False)[source]#
Bases:
objectInstantiate a 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 fully Rule-Based approach which required no data for training and can also include Deep learning and data can be then used to train the chatbot model.
- Parameters:
domains_slots (dict[str, list[str]]) – The slots of each domain in the system.
templates (dict[str, dict[str, list[str]]]) – The predefined templates, where templates[“domain”][“slot”] is a list of questions asking about slot “slot” in domain “domain”.
domains_pattern (dict[str, str]) – Dictionary where the key is a name of a domain and the value is a Regex that is used to capture that domain.
slots_pattern (dict[str, dict[str, str]]) – Dictionary where the key is a name of a domain and the value is another dictionary where the key is a name of a slot inside the domain and the value is a Regex that is used to capture that slot.
verbose (bool) – Whether to print the internal state of the chatbot.
append_state (bool) – Whether to append the internal state of the chatbot to the response.
- read_data(data)[source]#
Read the chatbot training data, redundant here as we are using a fully classical approach.
- Parameters:
data – any
- Returns:
None
- Return type:
NoneType
- train()[source]#
Train the chatbot model with the given data in read_data, redundant here as we are using a fully classical approach.
- Parameters:
data – any
- Returns:
None
- Return type:
NoneType
- infer(prompt)[source]#
Infer a suitable response to the given prompt.
- Parameters:
promp – The user’s prompt
- Returns:
When all slots in the current domain are filled it returns empty string, otherwise it returns the response.
- Return type:
str
botiverse.bots.BasicTaskBot.utils module#
This module ontains utility code used by the basic Taskbot module such as Natural Language Understanding (NLU), Dialogue State Tracker (DST) … etc.
- class botiverse.bots.BasicTaskBot.utils.RuleBasedNLU(domains_pattern, slots_pattern)[source]#
Bases:
objectInstantiate a Rule-Based Natural Language Understanding module. It uses Regex to extract domain and slot-fillers from the user’s utterance.
- Parameters:
domains_pattern (dict[str, str]) – Dictionary where the key is a name of a domain and the value is a Regex that is used to capture that domain.
slots_pattern (dict[str, dict[str, str]]) – Dictionary where the key is a name of a domain and the value is another dictionary where the key is a name of a slot inside the domain and the value is a Regex that is used to capture that slot.
- get_domain(prev_domain, utterance)[source]#
Takes previously extracted domain and the user’s utterance and extract the domain from it, if no domain can be extracted it returns prev_domain.
- Parameters:
prev_domain (str) – The domain from previous user’s utterance.
utterance (str) – The user’s utterance.
- Returns:
The success of the domain extraction & The extracted domain.
- Return type:
tuple[bool, str]
- get_slot_fillers(current_domain, utterance)[source]#
Takes the current extracted domain and the user’s utterance and extract the slot-fillers.
- Parameters:
current_domain – The domain extracted from the current user’s utterance.
utterance (str) – The user’s utterance.
- Returns:
The success of the slot-fillers extraction, the extracted slots & the extracted slot-values.
- Return type:
tuple[bool, list[str], list[str]]
- class botiverse.bots.BasicTaskBot.utils.MostRecentDST(domains_slots)[source]#
Bases:
objectInstantiate a Dialogue State Tracker module. It maintains the state of the dialogue which is mainly represented in the slots and the slots-values that are extracted from the user’s utterances. It is a most recent tracker which means it only keeps track of the recent value in case if multiple values appear for the same slot.
- Parameters:
domains_slots (dict[str, list[str]]) – The slots of each domain in the system.
- update_state(domain, slots, values)[source]#
Update the slots values of a certain domain.
- Parameters:
domain (str) – The domain of the slots to be updated.
slots (list[str]) – List the of the slots to be updated.
values (list[str]) – List of the values of the slots.
- get_dialogue_state()[source]#
Gets the dialogue state.
- Returns:
The dialogue state, where state[“domain”][“slot”] indicates value of slot “slot” in domain “domain”.
- Return type:
dict[str, dict[str, str]]
- class botiverse.bots.BasicTaskBot.utils.RandomDP[source]#
Bases:
objectInstantiate a Random Dialogue Policy module. Randomly determines the next action which is the next empty slot to ask user about.
- get_action(current_domain, state)[source]#
Takes the current domain and dialogue state and return the next action which is the next empty slot to ask user about.
- Parameters:
current_domain (str) – The current extracted domain.
state (dict[str, dict[str, str]]) – The current state of the dialogue.
- Returns:
The next empty slot to ask the user about.
- Return type:
str
- class botiverse.bots.BasicTaskBot.utils.TemplateBasedNLG(templates)[source]#
Bases:
objectInstantiate a Template Based Natural Language Generation module. It uses a predefined templates to generate a response to the user and ask about empty slots.
- Parameters:
templates (dict[str, dict[str, list[str]]]) – The predefined templates, where templates[“domain”][“slot”] is a list of questions asking about slot “slot” in domain “domain”.