pydialogue.policies package#
Submodules#
pydialogue.policies.agent_policies module#
This module lists the policies that the agent uses respond to the dialogue.
- class pydialogue.policies.agent_policies.DropItemPolicy(player=None, go_location_policy=None, action_item_obstacle_steps=None, dialogue=None)[source]#
Bases:
ActionPolicyThe agent’s self when the user asks the agent to drop an entity at a specific location.
- parse(last_user_command)[source]#
Parses the sentence last_user_command and checks if it matches the user request outputted from the self user_policies.DropPolicy. Then it returns the list of possible utterances and the goal of the agent self.player.
- Parameters:
last_user_command (Sentence) –
One of the following requests (queries.drop):
<agent>, drop (a) <entity> <target_location>
then <agent>, drop (a) <entity> <target_location>
where the <target_location> is a list of two values: the first is a preposition in/on/under and the second value is an Entity. The second sentence form is used in the user_policies.AndPolicy.
- task(item, prepos_location=None)[source]#
Computes the steps and the goal necessary for self.player successfully dropping the item at the target location.
- Parameters:
item (Entity) – The entity to be dropped by self.player at the location.
prepos_location (list, optional) – If provided, prepos_location is the target location where the item should be dropped. Otherwise, the target location will be the player’s location. The prepos_location is a list of two values: the first is a preposition in/on/under, and the second value is an Entity.
- class pydialogue.policies.agent_policies.GetItemPolicy(player=None, go_location_policy=None, action_item_obstacle_steps=None, dialogue=None)[source]#
Bases:
ActionPolicyThe agent’s self when the user asks the agent to get an entity
- parse(last_user_command)[source]#
Parses the sentence last_user_command and checks if it matches the user request outputted from the self user_policies.GetItemPolicy. Then it returns the list of possible utterances and the goal of the agent self.player.
- Parameters:
last_user_command (Sentence) –
One of the following requests (queries.open or queries.close):
<agent>, get (a) <entity> <entity_location>
then <agent>, get (a) <entity> <entity_location>
where the <entity_location> is the entity’s location, and it is a list of two values: the first is a preposition in/on/under, and the second value is an Entity. The second sentence is encountered in the user_policies.AndPolicy.
- task(item, prepos_location=None)[source]#
Computes the steps and the goal necessary for self.player successfully getting the item at the target location.
- Parameters:
item (Entity) – The entity to be taken by the agent.
prepos_location (list) – The location of the item. The location does not necessarily have to be the top location. (read more entity.top loc) The entity’s location is a list of two values: the first is a preposition in/on/under, and the second value is an Entity.
- class pydialogue.policies.agent_policies.GoDirectionPolicy(player=None, dialogue=None)[source]#
Bases:
BasePolicyThe agent’s self when the user asks the agent to go in a direction.
- initial_loc#
This is the location where the agent should try going in a specific direction.
- Type:
- parse(last_user_command)[source]#
Parses the user request outputted from the self user_policies.GoDirectionPolicy. Then it returns the list of possible utterances and the goal of the agent self.player.
- Parameters:
last_user_command (Sentence) –
One of the following requests (queries.go):
<agent>, go <direction>
then <agent>, go <direction>
The second sentence is encountered in the user_policies.AndPolicy, and it is parsed in the agent_policies.AndPolicy
- Returns:
steps (list) – The valid utterances.
goal (Goal) – The goal of the agent self.player.
- task(direction, last_user_command=None)[source]#
Computes the steps and the goal necessary for self.player successfully going in a specific direction.
- Parameters:
direction (str) – The direction in which self.player is headed.
last_user_command (Sentence) – The user’s request is asking self.player to go <direction>. Refer to self.parse for the format of the sentence. If there is a new request, the initial location of the self.player is changed.
- class pydialogue.policies.agent_policies.GoDirectionPolicyOld(player=None, dialogue=None)[source]#
Bases:
ActionPolicyThe agent’s self when the user asks the agent to go in a direction.
- initial_loc#
This is the location where the agent should try going in a specific direction.
- Type:
- parse(last_user_command)[source]#
Parses the user request outputted from the self user_policies.GoDirectionPolicy. Then it returns the list of possible utterances and the goal of the agent self.player.
- Parameters:
last_user_command (Sentence) –
One of the following requests (queries.go):
<agent>, go <direction>
then <agent>, go <direction>
The second sentence is encountered in the user_policies.AndPolicy, and it is parsed in the agent_policies.AndPolicy
- Returns:
steps (list) – The valid utterances.
goal (Goal) – The goal of the agent self.player.
- task(direction, last_user_command=None)[source]#
Computes the steps and the goal necessary for self.player successfully going in a specific direction.
- Parameters:
direction (str) – The direction in which self.player is headed.
last_user_command (Sentence) – The user’s request is asking self.player to go <direction>. Refer to self.parse for the format of the sentence. If there is a new request, the initial location of the self.player is changed.
- class pydialogue.policies.agent_policies.GoLocationPolicy(go_dir_policy, player=None, dialogue=None)[source]#
Bases:
ActionPolicyThis class represents the agent’s self when the user asks the agent to go to an object’s location.
- go_dir_policy#
This self is used to compute the directions to the object’s location.
- Type:
- parse(last_user_command)[source]#
Parses the user request that comes from the self user_policies.GoLocPolicy in order to extract the necessary parameters to call self.task. Later it calls self.task with the extracted parameters to compute the agent’s valid utterances and the goal.
- Parameters:
last_user_command (Sentence) –
One of the following requests (queries.go):
<agent>, go to (a) <object>
then <agent>, go to (a) <object>
The second sentence is used in the AndPolicy.
- Returns:
steps (list) – The valid utterances.
goal (Goal) – The goal of the agent self.player.
- task(item, prepos_location=None, preconditions=True)[source]#
Computes the steps that are necessary for self.player to successfully go to the location of the item. Furthermore, it computes the goal of self.player.
- Parameters:
item (Entity) – The item’s top location is used as the target location for the agent.
prepos_location (list, optional) – If the prepos location is not None it is used as the target location for the agent. This is done in requests like get the apple in the kitchen and even though the location of the apple is not revealed, the kitchen’s location is known.
preconditions (bool, optional) – If True it checks whether all necessary entities for accomplishing the task have their location revealed.
- Returns:
steps (list) – The list of possible utterances for the agent self.player.
goal (Goal) – The goal of the agent self.player.
- class pydialogue.policies.agent_policies.LookItemPolicy(player=None, go_location_policy=None, action_item_obstacle_steps=None, dialogue=None)[source]#
Bases:
ActionPolicyThe agent’s self when the user requests the agent to look at an item.
- parse(last_user_command)[source]#
Parses the sentence last_user_command and checks if it matches the user request outputted from the self user_policies.LookItemPolicy. Then it returns the list of possible utterances and the goal of the agent self.player.
- Parameters:
last_user_command (Sentence) –
One of the following requests (queries.look):
<agent>, look <preposition> (a) <entity> <entity_location>
then <agent>, look <preposition> (a) <entity> <entity_location>
where <preposition> is world.location_positions and <entity_location> is the location of the <entity>. The <entity_location> is the entity’s location, and it is a list of two values: the first is a preposition in/on/under and the second value is an Entity. The second type of user request is encountered in the user_policies.AndPolicy and it is parsed in the agent_policies.AndPolicy
- task(item, thing_looked_prepos, prepos_location=None)[source]#
Computes the steps and the goal necessary for self.player successfully looking in/on/under an item.
- Parameters:
item (Entity) – The entity that player looks at.
thing_looked_prepos (str) – The preposition where the player looks. For example, this can be in/on/under. See world.location_positions
prepos_location (list, optional) – The location of the item. The location does not necessarily have to be the top location. (read more env_main.top_loc)
pydialogue.policies.base_policies module#
This module lists the self interface and other base policies that are inherited by the agent/user policies.
- class pydialogue.policies.base_policies.ActionPolicy(player=None, go_location_policy=None, action_item_obstacle_steps=None, dialogue=None)[source]#
Bases:
BasePolicy,ABC- compute_policy_steps(item, can_not_action_res, target_location, prepos_location, action_func, action_params, action_res, action_step)[source]#
Computes the next policy steps and the goal for the agent, given the current context.
Computes the agent’s response to the user request:
<policy.player> <action> (preposition) <item> <preposition> <location>
The general algorithm works in such a way that if the player has the knowledge that it can not execute the action, then it has to provide a response in the following form:
<policy.player> says: neg_res
In case multiple neg_res are possible, they are prioritized in the following way:
The neg_res is because the <action> can not be executed for a specific reason.
The neg_res is because the item’s location is not revealed.
The neg_res is because the GoItemPolicy returned negative response (due to an obstacle or when the path is not revealed)
For example, if the request is: Hannah, get the static toys container, and it was previously revealed that static items are not gettable, it is not important whether the location of the toys container is revealed nor whether there is a path to the toys container since the entity is not gettable anyway.
Note that in each of the 1..3 cases, there might be multiple responses as well. For this reason, the goal
goals.multiple_correct()is used.If the <action> can be executed by the agent, then it utters the next step that leads the agent closer to the goal. During the dialogue turn, just the first step is taken, so it suffices to provide a single step.
- Parameters:
item (Entity) – The <item> in the user request.
can_not_action_res (Sentence) – A sentence in the form: <policy.player> can not (preposition) <action> <item> <preposition> <location>
target_location (Entity) – This is the location where the agent should go to act on the item. For example, for the action get, this is the item’s location, and for the action drop, this is the location where the item should be dropped.
prepos_location (list) – A list consisting of two elements, namely preposition (in, on, under) and location (Entity) This is the location where the item is supposedly at. Note that sometimes, prepos_location might not be the same as the target location. For example, the request can be: get the item <from_wrong_location> The prepos_location is allowed to be None as well.
action_func (function) – A function that comes from the module environment.actions and is used to get the environment response.
action_params (dict or tuple) – A dictionary mapping param_name: param_value, containing the parameters of the action_func or an ordered tuple (param_value1, param_value2 …)
action_res (Sentence) – A sentence in the form: <policy.player> <action> (preposition) <item> <preposition> <location>. It is used for checking whether the environment returns a positive response.
action_step (Sentence) – The step in the form: <policy.player> tries (preposition) <action> <item> <preposition> <location>
- Returns:
steps (list) – The agent’s next response. The list is in case multiple responses are valid.
goal (Goal) – The goal of the agent’s policy.
- one_task(item, neg_response, neg_res_func, last_user_command, **task_params)[source]#
Runs the agent’s self for the following user request:
<agent> <action> (preposition) a <item> <location>
For example, “Max, look in a plastic container”
The agent should accomplish the user request for one item that exists in the world and that fits the item’s description provided by the user. This function calls self.task for each item that fits the description.
In case the agent issues several steps but during the process it discovers that the action can not be done, then it should switch to another similar item. If the action is not possible for all the items that fit the description, then the neg_response should be outputted.
- Parameters:
item (BaseEntity) – The item that describes the kind of object the agent should act upon. It contains the properties and attributes that describe the object. Additionally, it contains an ‘abstract’ attribute to indicate that it does not exist in the material world.
neg_response (Sentence) – In case the action can not be achieved for all items in the world, a negative response (neg_response) is returned. An example is, “Hans can not get a big red item.”
neg_res_func (function) – A function that returns a negative response. For example, for the action get, this would be: <agent> can not get <object>. The neg_res_func requires only one argument because the <agent> is embedded in the sentence using self.player. This function is used to check if self.task returns a negative response.
last_user_command (Sentence) – The last user request to the agent.
**task_params (dict) – Additional self-specific parameters that might be required for execution.
- Returns:
steps (list) – A list of valid responses.
goal (Goal) – The goal is to check if the action is successful for at least one of the items in the world.
- class pydialogue.policies.base_policies.AutoPolicy(list_policies, dialogue)[source]#
Bases:
PolicyThis class allows the automatic selection of the right policies (in case there are multiple). The criterion for selection is if the policies output a response or a goal that is not None when executed.
- list_policies#
A list of instances that inherit the Policy class.
- Type:
list
- execute(include_goal=False, **params)[source]#
Runs the self.
- Parameters:
include_goal (bool, optional) – Whether to include the goal of the self. The default is False.
**params (dict) – Additional parameters that some policies in self.list_policies might require.
- Returns:
steps (list) – The list of valid utterances.
goal (Goal, optional) – The goal of the self.
- parse(**params)[source]#
Iterates through all policies in the list_policies and returns the ones that outputs a step or a goal. If multiple policies output a valid response, then all the responses are returned and their goals are merged into one or_goal.
- class pydialogue.policies.base_policies.BasePolicy(player=None, dialogue=None)[source]#
Bases:
Policy,ABCThe base self is used in cases where the user issues a request to an agent and the agent has to return an appropriate response.
- execute(include_goal=False, say_last_user_command=None, **params)[source]#
Runs the self.
- Parameters:
include_goal (bool, optional) – Whether to include the self’s goal or not. The default is False.
say_last_user_command (Sentence, optional) – A say sentence in the following format responses.say(queries.<x>). For example, “Jim says: Max, change the toy’s color to red!” If this sentence is not provided, the first dialogue utterance is expected to be the user’s request.
- Returns:
steps (list) – A list of valid responses.
goal (Goal, optional) – The goal of the self.
- extract_inner_sentence(say_last_user_command=None)[source]#
Extract the inner sentence from the responses.say sentence.
- Parameters:
say_last_user_command (Sentence, optional) – A say sentence in the following format responses.say(queries.<x>). For example, “Jim says: Max, change the toy’s color to red.” If it’s not provided, the first dialogue utterance is expected to be the user’s request.
- Returns:
last_user_command – The extracted inner sentence, if found. Otherwise, None is returned.
- Return type:
- abstract parse(last_user_command)[source]#
Extracts the parameters of the user request necessary to compute the agent’s self logic and implements the logic as well.
- Parameters:
last_user_command (Sentence) –
- A user request sentence (queries.<x>) that does not mention the user. For example,
”Max, change the toy’s color to red.”
- Returns:
steps (list) – The list of valid responses.
goal (Goal, optional) – The goal of the self.
- class pydialogue.policies.base_policies.Policy(player=None, dialogue=None)[source]#
Bases:
ABCThis class sets up an interface that every self should implement.
- player#
The player or agent that acts according to the self. If None it is assumed that the environment responds.
- Type:
Entity, optional
- abstract execute(include_goal=False, **params)[source]#
Runs the self.
- Parameters:
include_goal (bool) – If true, returns the goal. Otherwise, return only the steps.
params (dict) – Additional parameters that might modify the behavior of the self.
- Returns:
steps (list) – Since there can be more than one valid response in a specific context, the list of valid responses is returned.
goal (Goal, optional) – The goal of the self.
- abstract get_goal(**params)[source]#
Returns the goal of the self. This function can be useful if the goal is computed separately from the steps.
- abstract get_steps(**params)[source]#
Returns the list of steps/valid utterances of the self. This function can be useful if the steps are computed separately from the goal.
pydialogue.policies.env_policies module#
This module lists the policies that the environment uses to provide feedback to the player.
- class pydialogue.policies.env_policies.DropPolicy(dialogue=None)[source]#
Bases:
EnvPolicyThis self is used for providing a response when a player tries dropping an entity in the world.
- parse(last_utter)[source]#
Parses the player’s utterance into an actions.drop method call that provides the environmental feedback. The utterance has to be in the following form:
<player> tries dropping <entity> <location_position> <location>
The location refers to the one where the entity should be dropped. For example, The big person tries dropping the small ball in the toy’s container.
- class pydialogue.policies.env_policies.EmptyPolicy(dialogue=None)[source]#
Bases:
EnvPolicyThis self is used when a player issues an empty sentence (that does not contain any verbs or describers).
- class pydialogue.policies.env_policies.EnvAutoPolicy(list_policies, dialogue)[source]#
Bases:
AutoPolicyA self that automatically selects the right self out of a list of environmental policies.
- execute(include_goal=False, **params)[source]#
Runs the self and returns a list of valid environment responses.
Additionally, the goal is returned if include_goal is set to True. If all the policies in self.list_policies return None, then the environment returns:
<player> issued an unrecognizable sentence.
- class pydialogue.policies.env_policies.EnvPolicy(dialogue=None)[source]#
Bases:
PolicyThe environment self provides a response to every player’s action. The player is None, since the environment is not governed by any entity.
- execute(include_goal=False, last_utter=None)[source]#
Returns the environment response as feedback to the last utterance of the agent.
- Parameters:
include_goal (bool, optional) – Whether to include the goal of the environment.
last_utter (Sentence, optional) – If the last utterance is not provided, the last dialogue utterance is taken.
- Returns:
list – Returns multiple valid environmental responses.
None, optional – The goal of the environment is None, since the goal is currently generated in the agent’s self.
- get_goal(**params)[source]#
Returns the goal of the environment. The environment goal is None since the agents have goals.
- class pydialogue.policies.env_policies.GetPolicy(dialogue=None)[source]#
Bases:
EnvPolicyThis self is used for providing feedback when a player tries getting an entity in the world.
- parse(last_utter)[source]#
Parses the player’s utterance into an actions.get method call that provides the environmental feedback.
The utterance has to be in the form:
<player> tries getting <entity> <location_preposition> <location>
The location refers to the entity’s location. For example, Hannah tries getting the plastic container under the table. Here the plastic container’s location is under the table.
- class pydialogue.policies.env_policies.GoPolicy(dialogue=None)[source]#
Bases:
EnvPolicyThis self is used for providing feedback when a player tries moving in the world.
- class pydialogue.policies.env_policies.LookPolicy(dialogue=None)[source]#
Bases:
EnvPolicyThis self provides a response when a player tries looking at an entity in the world.
- parse(last_utter)[source]#
Parses the player’s utterance into an actions.look method call that provides the environmental feedback.
The utterance has to be in the form:
<player> tries looking <location_preposition1> <entity> <location_preposition2> <location>
The location refers to the entity’s location. For example, John tries looking in the toys container in the bedroom.
- class pydialogue.policies.env_policies.SayPolicy(dialogue=None)[source]#
Bases:
EnvPolicyThis self provides a response when a player says a sentence
- parse(last_utter)[source]#
Checks whether a sentence is in the format <user> says to <agent>: <inner_sentence> and if so, it returns an empty sentence with speaker=None. speaker=None indicates that the sentence is uttered by the environment. The empty sentence is returned because there is no need to implement actions.say. The agent can say anything, and the agent’s utterance is anyway added to the context.
pydialogue.policies.goals module#
This module lists the dialogue goals that the goal generators generate.
- class pydialogue.policies.goals.Goal(func, *args, **kwargs)[source]#
Bases:
objectThis class represents the dialogue’s goal.
The execute function indicates the progress of the player towards the goal. Usually, it is a value ranging from 0 to 1, but it can also vary and can be used as a reward function.
- func#
The goal is a function.
- Type:
function
- args#
The positional arguments of the goal function.
- Type:
tuple
- kwargs#
The keyword arguments of the goal function.
- Type:
dict
- pydialogue.policies.goals.correct_steps_sublist(dialogue, player, steps, start_id)[source]#
Find if the steps are a sublist of the player utterances starting from a specific point in the dialogue.
- pydialogue.policies.goals.find_and_replace_params(func, args, kwargs, **params_replace)[source]#
Replaces the parameters found in args and kwargs with other set of params (params_replace).
- pydialogue.policies.goals.get_player_utters(dialogue, player, start_id)[source]#
Get all the player’s utterances from the dialogue starting from a specific point in the dialogue.
- pydialogue.policies.goals.go_to_loc_goal(dialogue, player, location, start_id)[source]#
Checks if the player went to the target location starting from a specific point of time in the dialogue.
- pydialogue.policies.goals.goal_and(goals)[source]#
Checks if all the goals in the list return 1. If one of the goals is None or returns 0, then the final result is 0. Each of the goal types is data.goals.Goal
- pydialogue.policies.goals.goal_or(goals)[source]#
Checks whether one of the goals returns 1. Each of the goal types is
Goal
- pydialogue.policies.goals.is_sublist(_list, sub_list, eq_func=None)[source]#
Checks whether the elements of the sub_list are part of the _list. The order of the elements is considered as well.
The eq_func is a function with two parameters that defines their equality. The first parameter represents an element from the list and the second one an element from the sublist.
pydialogue.policies.other_policies module#
- class pydialogue.policies.other_policies.ItemPropRevealedPolicy(item, prop_key, prop_val, dialogue=None)[source]#
Bases:
PolicyThe agent’s policy when the user asks the agent whether an item has a specific property pair (key, value).
- execute(include_goal=False, **params)[source]#
Runs the self.
- Parameters:
include_goal (bool) – If true, returns the goal. Otherwise, return only the steps.
params (dict) – Additional parameters that might modify the behavior of the self.
- Returns:
steps (list) – Since there can be more than one valid response in a specific context, the list of valid responses is returned.
goal (Goal, optional) – The goal of the self.
pydialogue.policies.policies_helpers module#
This module lists the functions that help with the implementation of the policies.
- pydialogue.policies.policies_helpers.add_can_not(can_not_action_res, steps)[source]#
Add the can_not_action_res to the list of the following sentences:
player says: <inner_sentence>
so that the resulting one is:
player says: <can_not_action_res>. <inner_sentence>
- pydialogue.policies.policies_helpers.check_loc(know_base, item, item_loc)[source]#
Checks whether the agent has seen where the item is located. The checking is done recursively so in case the item’s location is in a container or another place those locations are checked as well.
- Parameters:
know_base (KnowledgeBase) – The knowledge base stores the information that the agent has seen.
item (Entity) – The item that location is checked.
item_loc (Entity) – The location of the item.
- Returns:
The first non-revealed location on the way to the top location. Otherwise, None is returned.
- Return type:
Entity or None
- pydialogue.policies.policies_helpers.check_path(know_base, iloc, directions, dir_idx, tloc)[source]#
Checks whether the path from the intermediate location to the target location (tloc) is revealed to the agent.
- Parameters:
know_base (KnowledgeBase) – The knowledge base is used to check whether the agent knows that the intermediate location has a direction that brings the agent one step closer to the target location.
iloc (Entity) – The intermediate location.
directions (list) – The list of directions that make up the path.
dir_idx (int) – The current index in the directions list that shows how to transition from iloc to the next location.
tloc (Entity) – The target location.
- Returns:
If the path is not revealed, a sentence is returned. Otherwise, None is returned.
- Return type:
Sentence or None
- pydialogue.policies.policies_helpers.compute_say_steps(flattened_env_res, orig_env_res, player, knowledge_base)[source]#
Creates “player says <environment_response>” sentences from the environment’s responses (orig_res)
Furthermore, it separates them into two lists, depending on whether the reduced environment sentences (flattened_res) are seen/known by the player (steps_checked) or not (steps_not_checked).
- Parameters:
flattened_env_res (list of lists) – The environment can return multiple valid responses. flattened_env_res is all the responses reduced.
orig_env_res (list) – The environment’s responses.
player (Entity) – The player that produces the steps.
knowledge_base (KnowledgeBase) – The knowledge base is used to check whether the agent has seen the environment responses in the past.
- Returns:
steps_checked (list) – The steps that the player is aware of.
steps_not_checked (list) – The steps that the player is not aware of.
- pydialogue.policies.policies_helpers.extract_inner_sent(say_sentence)[source]#
Extract the request from the following sentence:
player says: <request_sent>
Make sure it comes from a trusted source.
- pydialogue.policies.policies_helpers.extract_reasons(orig_env_res)[source]#
Extract the reasons why some action can not be done. The orig_env_res is a list of sentences having the following format:
player can not <action> … <reason_why>
- pydialogue.policies.policies_helpers.find_last_command(dialogue)[source]#
Find the last user request from the list of dialogue utterances.
- pydialogue.policies.policies_helpers.go_dir_obstacle_steps(go_dir_policy, direction, initial_loc)[source]#
- pydialogue.policies.policies_helpers.make_item_reachable(player, sloc, tloc, world)[source]#
The player’s path is cleared of obstacles in order to see if there is another reason the player can not act upon the item.
- pydialogue.policies.policies_helpers.open_all_containers(player, item, world)[source]#
If the item is potentially located in a container, it opens/unlocks the container. Additionally, it opens all containers on the way until the top location is reached (if that container is part of another container).
For actions.opens to work, we have to open the innermost container first.
- pydialogue.policies.policies_helpers.path_revealed(dialogue, player, sloc, tloc, neg_res)[source]#
Check whether the path from the source loc (sloc) to the target location (tloc) is revealed to the player. In case it’s not, a negative response (neg_res) is returned.
- Parameters:
dialogue (Dialogue) – The dialogue that the player is part of.
player (Entity) – The agent whose self calls this function.
sloc (Entity) – The starting point.
tloc (Entity) – The finishing point.
neg_res (Sentence, optional) – A sentence indicating the action can not be completed. For example, John can not get the cat.
- Returns:
steps – If the path is revealed, None is returned. Otherwise, returns a list comprising a single sentence saying why the path is not revealed.
- Return type:
list or None
- pydialogue.policies.policies_helpers.prec_action_item(dialogue, player, items, neg_response=None)[source]#
For all items, it checks whether the player is aware of their locations.
This function is used in the agents’ policies.
- Parameters:
dialogue (Dialogue) – The dialogue is needed to create the goal which might be part of the dialogue.
player (Entity) – The agent whose self calls this function.
items (list) – The items whose locations are checked.
neg_response (Sentence, optional) – A sentence indicating the action can not be completed. For example, John can not get the cat.
- Returns:
steps (list or None) – The list of valid responses. If all items’ locations are revealed, None is returned.
goal (Goal or None) – If all items’ locations are revealed, None is returned. Otherwise, the agent’s goal is to output one sentence saying which item’s location is not revealed.
- pydialogue.policies.policies_helpers.reduce_and_check_say(steps, target_sent)[source]#
- Reduces the sentences in the steps (check Sentence.reduce) and checks whether at least one of the sentences
- is in the format:
<player> says: neg_sent
- Parameters:
steps (list) – A list of sentences.
target_sent (Sentence) – The inner sentence that is checked if it exists.
- Returns:
found_flag – True if the neg_sent is found in one of the sentences. Otherwise, False.
- Return type:
bool
pydialogue.policies.user_policies module#
This module lists the user policies that the user uses to respond to the dialogue.
- class pydialogue.policies.user_policies.ActionItemPolicy(player, item=None, agent=None, location=None, location_position=None, dialogue=None)[source]#
Bases:
BaseItemPolicy,ABCAction self that covers the user requests in the following format:
<agent>, <action> (a) <item> <location_position> <location>
For example, Hans, get the red ball in the kitchen.
- class pydialogue.policies.user_policies.BaseItemPolicy(player, item=None, agent=None, dialogue=None)[source]#
Bases:
UserPolicy,ABCBase self that covers the user requests in the following format:
<player> says: <agent>, <action> (a) <item>
For example, Andy says: Hans, get a red ball
- abstract generate_response(item, agent_desc_elems, tmp)[source]#
Generate the user request that the agent has to complete.
- Parameters:
item (Entity) – The entity that the agent acts upon.
agent_desc_elems (list) – List of elements, property keys, attributes, or other strings for the agent description.
tmp (tuple) – The tmp element is used for temporal words/phrases. The first element of the tuple can be a string or a list and the second one Word or Phrase.
- Returns:
The user request.
- Return type:
- class pydialogue.policies.user_policies.DropItemPolicy(player, item=None, agent=None, location=None, location_position=None, dialogue=None)[source]#
Bases:
ActionItemPolicyThe self for the user request: <agent>, drop (a) item <location_position> <location>
- generate_response(item, agent_desc_elems, tmp)[source]#
Generate the user request that the agent has to complete.
- Parameters:
item (Entity) – The entity that the agent acts upon.
agent_desc_elems (list) – List of elements, property keys, attributes, or other strings for the agent description.
tmp (tuple) – The tmp element is used for temporal words/phrases. The first element of the tuple can be a string or a list and the second one Word or Phrase.
- Returns:
The user request.
- Return type:
- class pydialogue.policies.user_policies.GetItemPolicy(player, item=None, agent=None, location=None, location_position=None, dialogue=None)[source]#
Bases:
ActionItemPolicyThe self for the user request: <agent>, get (a) item <location_position> <location>
- generate_response(item, agent_desc_elems, tmp)[source]#
Generate the user request that the agent has to complete.
- Parameters:
item (Entity) – The entity that the agent acts upon.
agent_desc_elems (list) – List of elements, property keys, attributes, or other strings for the agent description.
tmp (tuple) – The tmp element is used for temporal words/phrases. The first element of the tuple can be a string or a list and the second one Word or Phrase.
- Returns:
The user request.
- Return type:
- class pydialogue.policies.user_policies.GoDirectionPolicy(player, agent=None, direction=None, dialogue=None)[source]#
Bases:
UserPolicyAction self that covers the user requests in the following format:
<player> says: <agent>, go <direction>
For example, the big person says: John, go north
- class pydialogue.policies.user_policies.GoLocationPolicy(player, item=None, agent=None, location=None, location_position=None, dialogue=None)[source]#
Bases:
ActionItemPolicyThe self for the user request: <agent>, go to (a) item
- generate_response(item, agent_desc_elems, tmp)[source]#
Generate the user request that the agent has to complete.
- Parameters:
item (Entity) – The entity that the agent acts upon.
agent_desc_elems (list) – List of elements, property keys, attributes, or other strings for the agent description.
tmp (tuple) – The tmp element is used for temporal words/phrases. The first element of the tuple can be a string or a list and the second one Word or Phrase.
- Returns:
The user request.
- Return type:
- class pydialogue.policies.user_policies.LookItemPolicy(player, item=None, agent=None, location=None, location_position=None, dialogue=None)[source]#
Bases:
ActionItemPolicyThe self for the user request: <agent>, look <location_position> (a) item in <location>
- generate_response(item, agent_desc_elems, tmp)[source]#
Generate the user request that the agent has to complete.
- Parameters:
item (Entity) – The entity that the agent acts upon.
agent_desc_elems (list) – List of elements, property keys, attributes, or other strings for the agent description.
tmp (tuple) – The tmp element is used for temporal words/phrases. The first element of the tuple can be a string or a list and the second one Word or Phrase.
- Returns:
The user request.
- Return type:
- class pydialogue.policies.user_policies.UserPolicy(player=None, dialogue=None)[source]#
Bases:
Policy,ABCThe self for the user issuing a request.
The goal is always None since the goal is defined in the agent self (see base_policies.ActionPolicy).
- execute(include_goal=False, **params)[source]#
Runs the self.
- Parameters:
include_goal (bool) – If true, returns the goal. Otherwise, return only the steps.
params (dict) – Additional parameters that might modify the behavior of the self.
- Returns:
steps (list) – Since there can be more than one valid response in a specific context, the list of valid responses is returned.
goal (Goal, optional) – The goal of the self.
pydialogue.policies.vocab module#
- pydialogue.policies.vocab.compute_input_vocab(world)[source]#
Computes all the input vocabulary words by merging the words returned from the user, agent and environment policies. Additionally, all property keys and values are added from the world.
- pydialogue.policies.vocab.compute_policies_words()[source]#
Computes all the words that are used in the rule-based policies.