pydialogue package#

Subpackages#

Submodules#

pydialogue.dialogue_generator module#

This module contains the class for generating dialogues.

class pydialogue.dialogue_generator.DialogueGenerator(world, log_filename, context_strings_filename=None, primitive_templates=None)[source]#

Bases: object

This class contains all the components needed to generate/simulate dialogues.

Here is an example of how to quickly generate a dialogue:

easy_world = easy_env.build_world()
generator = DialogueGenerator(easy_world, "error.log", "context_sentences.txt")
dialogue = generator.generate_dialogue()
dialogue.run()
world#

The world where the simulation occurs.

Type:

World

context_strings#

The list where all dialogue utterances, including the environmental feedback, are stored in a string form.

Type:

ContextListDb

context#

The list of instances (type Sentence) where all dialogue utterances, including the environmental feedback, are stored.

Type:

ContextListDb

meta_context#

This list is used to save all additional information that is carried by the uttered sentences. Please check lc.Phrase for more information about the meta sentences.

Type:

ContextListDb

knowledge_base#

The knowledge base stores additional information, and it is used in rule-based policies to quickly fetch information. It is updated each time an agent utters.

Type:

KnowledgeBase

primitive_templates#

A list of functions that are used to generate the primitive dialogues.

Type:

list

curr_prim_params#

This field serves as a temporary memory to hold all primitive template parameters while they are generated. This field is helpful in case the generation of parameterA depends on the generation of another parameterB. The parameterA generator can fetch the value of parameterB using curr_prim_params[“parameterB”] After the primitive template is generated this dictionary is cleared.

Type:

dict

prim_param_generators#

A list of tuples (param_name, function). The function generates a random parameter value for the primitive templates.

Type:

list

agent_policy_database#

A dictionary that maps each agent (Entity) to all of its policies (list). The agent is the one who fulfills the user’s requests.

Type:

dict

user_policy_database#

A dictionary that maps each user (Entity) to all of its policies (list). The user issues the requests to the agent.

Type:

dict

agent_auto_policy_database#

A dictionary that maps each agent (Entity) to all of its policies.AutoPolicy policies (list).

Type:

dict

user_auto_policy_database#

A dictionary that maps each user (Entity) to all of its policies.AutoPolicy policies (list).

Type:

dict

env_policy_database#

A list of all environmental policies.

Type:

list

env_auto_policy#

The environment automatic self automatically selects the right self from the environment database when an agent utters. Once selected, it provides feedback to the agent.

Type:

EnvAutoPolicy

execute_utters(utterances, random_gen=None, fake=False, skip_env=False)[source]#

Adds the agent/user utterances to the context, to the meta_context, and it updates the knowledge base. Moreover, the env_policy is executed so the environment can provide feedback to each of the utterances.

This function is used by the Dialogue class.

Parameters:
  • utterances (list) – The list of utterances to be executed.

  • random_gen (random.Random) – The random generator used for randomly selecting a valid response from the environmental feedback. It makes the Dialogue reproducible.

  • fake (bool, optional) – If True the dia_generator state is not updated with the new information.

  • skip_env (bool, optional) – If True the env_policy is not executed.

Returns:

responses – The list of players’ utterances, including the environment’s responses.

Return type:

list

flush()[source]#

Flushes the dialogue generator state in order to save memory.

generate_dialogue(structure_list=None, default_args_list=None)[source]#

Generates a single dialogue.

Parameters:
  • structure_list (list, optional) – If the template type is complex, the structure list contains both primitive and complex templates that appear as parameters in another complex template. If the template type is primitive, the structure_list consists of a single tuple. More information can be found on helpers.generate_complex_structure and helpers.generate_primitive_structure

  • default_args_list (list, optional) – List of dictionaries that match the length of the structure list. The default is None.

Returns:

The generated dialogue.

Return type:

Dialogue

init_agent_auto_policy_db(players)[source]#

Initializes all the auto policies for each agent in the agents (players) list.

init_agent_policy_db(players)[source]#

Initializes all individual policies for the specified agents (players) in the world. The dialogue at this stage is None.

init_env_policy_db()[source]#

Initializes all environment policies.

init_param_generators()[source]#

Initializes the parameter generators for the primitive and complex templates.

init_user_auto_policy_db(players)[source]#

Initialize all the auto policies for each user in the users (players) list.

init_user_policy_db(players)[source]#

Initializes all individual policies for the specified users (players) in the world. The dialogue at this stage is None.

recover_state(state)[source]#

Recovers the state of all class members that change with time.

run(num_dialogues, flush_after=None, save_dialogues=False, notebook_run=False)[source]#

Generates and runs a number of dialogues. The policies used in the dialogue are rule-based, and the dialogue should evaluate to 1. In case the dialogue does not evaluate to 1, an error is logged together with the dialogue utterances.

Parameters:
  • num_dialogues (int) – The number of dialogues to be generated

  • flush_after (int) – Flushes the dia_generator state after a specific number of generated dialogues is reached.

  • save_dialogues (bool) – Whether to keep the dialogues in a list. It’s useful sometimes to either not keep the dialogues or remove their utterances in order to save RAM.

  • notebook_run (bool) – This parameter indicates whether the function is run from a jupyter notebook (True) or not (False). This parameter ensures the progress bars are shown correctly in a jupyter notebook.

Returns:

dialogues – A list of Dialogue-s or an empty list if the save_dialogues is False.

Return type:

list

save_state()[source]#

Saves the state of all class members that change with time.

select_primitive_template(templates_list, default_args=None)[source]#

Selects a primitive template, and it randomly generates its parameters.

When creating the user request, if the parameter determiner_a is True, this means that the item is not concrete, i.e. it does not belong to a specific item in the world. For example, a big red ball. Therefore, an abstract item is used (a BaseEntity with an attribute “abstract”). If the determiner_a is False, a concrete Entity is taken from the world’s object list.

Parameters:
  • templates_list (list) – The list of templates (functions) from which one is randomly selected.

  • default_args (dict, optional) – This dictionary is used for overriding the default random generation of parameters. The default is None.

Returns:

  • template_rand (function) – The randomly selected template.

  • params (dict) – The generated parameters for the template.

Module contents#