tatk.dialog_agent package

Submodules

tatk.dialog_agent.agent module

Dialog agent interface and classes.

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

Bases: abc.ABC

Interface for dialog agent classes.

abstract __init__(name: str)

Initialize self. See help(type(self)) for accurate signature.

abstract init_session()

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 tatk.dialog_agent.agent.PipelineAgent(nlu: tatk.nlu.nlu.NLU, dst: tatk.dst.dst.DST, policy: tatk.policy.policy.Policy, nlg: tatk.nlg.nlg.NLG, name: str)

Bases: tatk.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

__init__(nlu: tatk.nlu.nlu.NLU, dst: tatk.dst.dst.DST, policy: tatk.policy.policy.Policy, nlg: tatk.nlg.nlg.NLG, name: str)

The constructor of PipelineAgent class.

Here are some special combination cases:

  1. If you use word-level DST (such as Neural Belief Tracker), you should set the nlu_model paramater to None. The agent will combine the modules automitically.

  2. If you want to aggregate DST and Policy as a single module, set tracker to None.

Args:
nlu (NLU):

The natural langauge understanding module of agent.

dst (DST):

The dialog state tracker of agent.

policy (Policy):

The dialog policy module of agent.

nlg (NLG):

The natural langauge generator module of agent.

get_in_da()
get_out_da()
get_reward()
init_session()

Init the attributes of DST and Policy module.

is_terminated()
response(observation)

Generate agent response using the agent modules.

tatk.dialog_agent.env module

Created on Wed Jul 17 14:27:34 2019

@author: truthless

class tatk.dialog_agent.env.Environment(sys_nlg, usr, sys_nlu, sys_dst)

Bases: object

__init__(sys_nlg, usr, sys_nlu, sys_dst)

Initialize self. See help(type(self)) for accurate signature.

reset()
step(action)

tatk.dialog_agent.session module

Dialog controller classes.

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

Bases: tatk.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__(sys_agent: tatk.dialog_agent.agent.Agent, user_agent: tatk.dialog_agent.agent.Agent, kb_query=None, evaluator=None)
Args:
sys_agent (Agent):

An instance of system agent.

user_agent (Agent):

An instance of user agent.

kb_query (KBquery):

An instance of database query tool.

evaluator (Evaluator):

An instance of evaluator.

init_session()

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 tatk.dialog_agent.session.DealornotSession(alice, bob)

Bases: tatk.dialog_agent.session.Session

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

__init__(alice, bob)

Initialize self. See help(type(self)) for accurate signature.

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 tatk.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.