agents.coopgame_agent

Collection of agents participating in cooperative goal-based conversational games. One such game, named Task n’ Talk is described in the paper “Natural Language Does Not Emerge ‘Naturally’ in Multi-Agent Dialog (Kottur et al. 2017)”. General properties of such cooperative games are:

  • Two agents: Questioner and Answerer, occasionally may be more.
  • Information Asymmetry:
    • Answerer agent has information about visual content (real/synthetic image), but doesn’t know the goal of conversation.
    • Questioner agent is blind and has a goal unknown to the answerer agent. It asks questions in order to accomplish the goal. At the end of dialog episode, it makes a prediction.
  • Same reward: Both the agents can observe their own, as well as others’ actions. At the end of dialog episode, both agents are given same reward based on questioner’s prediction. Hence both must cooperate to maximize the reward.

Specifically for Task n’ Talk (taken from Kottur et al. 2017):

_images/taskntalk.png

Information Asymmetry: Answerer has an image described by attributes. Questioner cannot see the image, and has a task of finding two attributes of the image.

class parlai.agents.coopgame_agent.coopgame_agent.CooperativeGameAgent(opt, shared=None)

Base class for both, the questioner and answerer. It can be extended to create custom players of games, other than questioner and answerer. It has separate modules to listen (observe), speak (act) and update its internal state. Each module is a collection of one or more pytorch modules, and can be extended and replaced in the agent as per task requirements.

static dictionary_class()

If different strategy for tokenization and de-tokenization of actions is required, override this method to return custom subclass.

static add_cmdline_args(argparser)

Add command-line arguments specifically for this agent.

modules

Property to return a list of pytorch modules. Override this method while subclassing, if extra modules are added (for example, image feature extractor in answerer).

setup_optimizer()

Return a torch.nn.optim.optimizer according to command-line argument --optimizer. Override this method to setup optimizer with non-default parameters or use custom optimizer not available as choice.

tokenize(text)

Convert text observaton (string) to a torch.autograd.Variable of tokens using DictionaryAgent.

detokenize(vec)

Convert a torch.autograd.Variable of tokens into a string.

observe(observation)

Update state, given a previous reply by other agent. In case of questioner, it can be goal description at start of episode.

act()

Based on current state, utter a reply (string) for next round.

reset(retain_actions=False)

Reset internal state (and actions, if specified).

class parlai.agents.coopgame_agent.coopgame_agent.QuestionerAgent(opt, shared=None)

Base class for questioner agent. It is blindfolded, and has an extra predict method, which performs action at the end of dialog episode to accomplish the goal.

static add_cmdline_args(argparser)

Add command-line arguments specifically for this agent. Default values at according to (Kottur et al. 2017).

predict(tasks, num_tokens)

Extra method to be executed at the end of episode to carry out goal and decide reward on the basis of prediction.

class parlai.agents.coopgame_agent.coopgame_agent.AnswererAgent(opt, shared=None)

Base class for answerer agent. It holds visual information, and has an extra img_embed method, which extracts features from visual content.

static add_cmdline_args(argparser)

Add command-line arguments specifically for this agent. Default values at according to (Kottur et al. 2017).

img_embed(image)

Extra method to be executed at the end of episode to carry out goal and decide reward on the basis of prediction.

Building-block Modules

These are set of modules essential for agents in cooperative and goal-based conversational games. These agents use following modules, each module can be subclassed and replaced in agent according to need. All modules are extended from torch.nn.Module.

parlai.agents.coopgame_agent.modules.xavier_init(module)

Xavier initializer for module parameters.

class parlai.agents.coopgame_agent.modules.ImgNet(feature_size, input_size=None)

Module to embed the visual information. Used by answerer agent. In forward: Embed image attributes and concatenate them together.

Note: parlai.core.image_featurizers.ImageLoader can also be used instead.

class parlai.agents.coopgame_agent.modules.ListenNet(in_size, embed_size)

Module for listening the sequence spoken by other agent. In forward: Generate token embeddings.

class parlai.agents.coopgame_agent.modules.StateNet(embed_size, state_size)

Module for containing the state update mechanism for an agent. In forward: Update states by passing the embeddings through LSTMCell.

class parlai.agents.coopgame_agent.modules.SpeakNet(state_size, out_size)

Module for speaking a token based on current state. In forward: Return a probability distribution of utterances of tokens.

class parlai.agents.coopgame_agent.modules.PredictNet(embed_size, state_size, out_size)

Module to make a prediction as per goal. Used by questioner agent. In forward: Return a probability distribution of utterances of tokens.