This module provides a set of basic agents:
Agent(object)base class for all other agents, implements the
observe()method which receives an observation/action dict and the
act()method which returns a dict in response.
Teacher(Agent)also implements the
report()method for returning metrics. All ParlAI tasks implement the
MultiTaskTeacher(Teacher)creates a set of teachers based on a “task string” passed to the
Teacher, creating multiple teachers within it and alternating between them.
All agents are initialized with the following parameters:
opt– contains any options needed to set up the agent. This generally contains all command-line arguments recognized from
core.params, as well as other options that might be set through the framework to enable certain modes.
shared(optional) – if not
None, contains any shared data used to construct this particular instantiation of the agent. This data might have been initialized by another agent, so that different agents can share the same data (possibly in different Processes).
This module also provides a utility method:
create_task_agents(str): instantiate task-specific agents (e.g. a teacher) from a given task string (e.g. ‘babi:task1k:1’ or ‘squad’). Used by
Base class for all other agents.
Receive an observation/action dict.
Return an observation/action dict based upon given observation.
If applicable, save any parameters needed to recreate this agent from loaded parameters.
If applicable, share any parameters needed to create a shared version of this agent.
Perform any final cleanup if needed.
Basic Teacher agent which keeps track of how many times it’s received messages. Teachers provide the
report()method to get back metrics.
In addition to default Agent shared parameters, share metrics.
Creates a teacher that is actually a set of teachers each based on a task string–each of these teachers will get called in turn, either randomly or in order. They are all in the same world (they are the same agent switching tasks).
The task string format is described for the
Shutdown each agent.
Create an agent from the options
model_file. The input is either of the form
parlai.agents.ir_baseline.agents:IrBaselineAgent(i.e. the path followed by the class name) or else just
ir_baselinewhich assumes the path above, and a class name suffixed with ‘Agent’.
If ``model-file’’ is available in the options this function can also attempt to load the model from that location instead. This avoids having to specify all the other options necessary to set up the model including its name as they are all loaded from the options file if it exists (the file opt[‘model_file’] + ‘.opt’ must exist and contain a pickled dict containing the model’s options).
Creates task agent(s) assuming the input
e.g. def_string is a shorthand path like
#babior a complete path like
parlai.tasks.babi.agents:Task1kTeacher:1, which essentially performs
from parlai.tasks.babi import Task1kTeacherwith the parameter
opt['task']to be used by the class