convlab2.dialog_agent package

Submodules

convlab2.dialog_agent.agent module

Dialog agent interface and classes.

class convlab2.dialog_agent.agent.Agent(name: str)

Bases: abc.ABC

Interface for dialog agent classes.

abstract init_session(**kwargs)

Reset the class variables to prepare for a new session.

abstract response(observation)

Generate agent response given user input.

The data type of input and response can be either str or list of tuples, condition on the form of agent.

Example:

If the agent is a pipeline agent with NLU, DST and Policy, then type(input) == str and type(response) == list of tuples.

Args:
observation (str or list of tuples):

The input to the agent.

Returns:
response (str or list of tuples):

The response generated by the agent.

class convlab2.dialog_agent.agent.PipelineAgent(nlu: convlab2.nlu.nlu.NLU, dst: convlab2.dst.dst.DST, policy: convlab2.policy.policy.Policy, nlg: convlab2.nlg.nlg.NLG, name: str)

Bases: convlab2.dialog_agent.agent.Agent

Pipeline dialog agent base class, including NLU, DST, Policy and NLG.

The combination modes of pipeline agent modules are flexible. The only thing you have to make sure is that the API of agents are matched.

Example:

If agent A is (nlu, tracker, policy), then the agent B should be like (tracker, policy, nlg) to ensure API matching.

The valid module combinations are as follows:

NLU

DST

Policy

NLG

In

Out

+

+

+

+

nl

nl

o

+

+

+

da

nl

o

+

+

o

da

da

+

+

+

o

nl

da

o

o

+

o

da

da

get_in_da()
get_out_da()
get_reward()
init_session(**kwargs)

Init the attributes of DST and Policy module.

is_terminated()
response(observation)

Generate agent response using the agent modules.

state_replace(agent_state)

this interface is reserved to replace all interal states of agent the code snippet example below is for the scenario when the agent state only depends on self.history and self.dst.state

state_return()

this interface is reserved to return all interal states of agent the code snippet example below is for the scenario when the agent state only depends on self.history and self.dst.state

convlab2.dialog_agent.env module

Created on Wed Jul 17 14:27:34 2019

@author: truthless

class convlab2.dialog_agent.env.Environment(sys_nlg, usr, sys_nlu, sys_dst, evaluator=None)

Bases: object

reset()
step(action)

convlab2.dialog_agent.session module

Dialog controller classes.

class convlab2.dialog_agent.session.BiSession(sys_agent: convlab2.dialog_agent.agent.Agent, user_agent: convlab2.dialog_agent.agent.Agent, kb_query=None, evaluator=None)

Bases: convlab2.dialog_agent.session.Session

The dialog controller which aggregates several agents to conduct a complete dialog session.

Attributes:
sys_agent (Agent):

system dialog agent.

user_agent (Agent):

user dialog agent.

kb_query (KBquery):

knowledge base query tool.

dialog_history (list):

The dialog history, formatted as [[user_uttr1, sys_uttr1], [user_uttr2, sys_uttr2], …]

init_session(**kwargs)

Init the agent variables for a new session.

next_agent()

The user and system agent response in turn.

next_response(observation)

Generated the next response.

Args:

observation (str or dict): The agent observation of next agent.

Returns:

response (str or dict): The agent’s response.

next_turn(last_observation)

Conduct a new turn of dialog, which consists of the system response and user response.

The variable type of responses can be either 1) str or 2) dialog act, depends on the dialog mode settings of the two agents which are supposed to be the same.

Args:
last_observation:

Last agent response.

Returns:
sys_response:

The response of system.

user_response:

The response of user simulator.

session_over (boolean):

True if session ends, else session continues.

reward (float):

The reward given by the user.

train_policy()

Train the parameters of system agent policy.

class convlab2.dialog_agent.session.DealornotSession(alice, bob)

Bases: convlab2.dialog_agent.session.Session

A special session for Deal or Not dataset, which is a object dividing negotiation task.

get_rewards(ctxs)

Return the rewards of alice and bob.

Returns:
reward_1 (float):

Reward of Alice.

reward_2 (float):

Reward of Bob.

init_session()

Init the agent variables for a new session.

is_terminated()
next_agent()

Alice and Bob agents response in turn.

next_response(observation)

Generated the next response.

Args:

observation (str or dict): The agent observation of next agent.

Returns:

response (str or dict): The agent’s response.

class convlab2.dialog_agent.session.Session

Bases: abc.ABC

Base dialog session controller, which manages the agents to conduct a complete dialog session.

abstract init_session()

Init the agent variables for a new session.

abstract next_agent()

Decide the next agent to generate a response.

In this base class, this function returns the index randomly.

Returns:

next_agent (Agent): The index of the next agent.

abstract next_response(observation)

Generated the next response.

Args:

observation (str or dict): The agent observation of next agent.

Returns:

response (str or dict): The agent’s response.

Module contents

class convlab2.dialog_agent.Agent(name: str)

Bases: abc.ABC

Interface for dialog agent classes.

abstract init_session(**kwargs)

Reset the class variables to prepare for a new session.

abstract response(observation)

Generate agent response given user input.

The data type of input and response can be either str or list of tuples, condition on the form of agent.

Example:

If the agent is a pipeline agent with NLU, DST and Policy, then type(input) == str and type(response) == list of tuples.

Args:
observation (str or list of tuples):

The input to the agent.

Returns:
response (str or list of tuples):

The response generated by the agent.

class convlab2.dialog_agent.BiSession(sys_agent: convlab2.dialog_agent.agent.Agent, user_agent: convlab2.dialog_agent.agent.Agent, kb_query=None, evaluator=None)

Bases: convlab2.dialog_agent.session.Session

The dialog controller which aggregates several agents to conduct a complete dialog session.

Attributes:
sys_agent (Agent):

system dialog agent.

user_agent (Agent):

user dialog agent.

kb_query (KBquery):

knowledge base query tool.

dialog_history (list):

The dialog history, formatted as [[user_uttr1, sys_uttr1], [user_uttr2, sys_uttr2], …]

init_session(**kwargs)

Init the agent variables for a new session.

next_agent()

The user and system agent response in turn.

next_response(observation)

Generated the next response.

Args:

observation (str or dict): The agent observation of next agent.

Returns:

response (str or dict): The agent’s response.

next_turn(last_observation)

Conduct a new turn of dialog, which consists of the system response and user response.

The variable type of responses can be either 1) str or 2) dialog act, depends on the dialog mode settings of the two agents which are supposed to be the same.

Args:
last_observation:

Last agent response.

Returns:
sys_response:

The response of system.

user_response:

The response of user simulator.

session_over (boolean):

True if session ends, else session continues.

reward (float):

The reward given by the user.

train_policy()

Train the parameters of system agent policy.

class convlab2.dialog_agent.DealornotSession(alice, bob)

Bases: convlab2.dialog_agent.session.Session

A special session for Deal or Not dataset, which is a object dividing negotiation task.

get_rewards(ctxs)

Return the rewards of alice and bob.

Returns:
reward_1 (float):

Reward of Alice.

reward_2 (float):

Reward of Bob.

init_session()

Init the agent variables for a new session.

is_terminated()
next_agent()

Alice and Bob agents response in turn.

next_response(observation)

Generated the next response.

Args:

observation (str or dict): The agent observation of next agent.

Returns:

response (str or dict): The agent’s response.

class convlab2.dialog_agent.PipelineAgent(nlu: convlab2.nlu.nlu.NLU, dst: convlab2.dst.dst.DST, policy: convlab2.policy.policy.Policy, nlg: convlab2.nlg.nlg.NLG, name: str)

Bases: convlab2.dialog_agent.agent.Agent

Pipeline dialog agent base class, including NLU, DST, Policy and NLG.

The combination modes of pipeline agent modules are flexible. The only thing you have to make sure is that the API of agents are matched.

Example:

If agent A is (nlu, tracker, policy), then the agent B should be like (tracker, policy, nlg) to ensure API matching.

The valid module combinations are as follows:

NLU

DST

Policy

NLG

In

Out

+

+

+

+

nl

nl

o

+

+

+

da

nl

o

+

+

o

da

da

+

+

+

o

nl

da

o

o

+

o

da

da

get_in_da()
get_out_da()
get_reward()
init_session(**kwargs)

Init the attributes of DST and Policy module.

is_terminated()
response(observation)

Generate agent response using the agent modules.

state_replace(agent_state)

this interface is reserved to replace all interal states of agent the code snippet example below is for the scenario when the agent state only depends on self.history and self.dst.state

state_return()

this interface is reserved to return all interal states of agent the code snippet example below is for the scenario when the agent state only depends on self.history and self.dst.state

class convlab2.dialog_agent.Session

Bases: abc.ABC

Base dialog session controller, which manages the agents to conduct a complete dialog session.

abstract init_session()

Init the agent variables for a new session.

abstract next_agent()

Decide the next agent to generate a response.

In this base class, this function returns the index randomly.

Returns:

next_agent (Agent): The index of the next agent.

abstract next_response(observation)

Generated the next response.

Args:

observation (str or dict): The agent observation of next agent.

Returns:

response (str or dict): The agent’s response.