parlai.core.worlds¶
Worlds are the basic environments which define how agents interact with one another.
World(object)
provides a generic parent class, including__enter__
and__exit__
statements which allow you to guarantee that the shutdown method is called.
DialogPartnerWorld(World)
provides a two-agent turn-based dialog setting.
MultiAgentDialogWorld(World)
provides a multi-agent setting.
MultiWorld(World)
creates a set of environments (worlds) for the same agent to multitask over, a different environment will be chosen per episode.
BatchWorld(World)
is a container for doing minibatch training over a world by collecting batches of N copies of the environment (each with different state).
All worlds are initialized with the following parameters:
opt
– contains any options needed to set up the agent. This generally containsall command-line arguments recognized from core.params, as well as other options that might be set through the framework to enable certain modes.
agents
– the set of agents that should be attached to the world,e.g. for DialogPartnerWorld this could be the teacher (that defines the task/dataset) and the learner agent. This is ignored in the case of sharing, and the shared parameter is used instead to initialize agents.
shared
(optional) – if not None, contains any shared data used to constructthis particular instantiation of the world. This data might have been initialized by another world, so that different agents can share the same data (possibly in different Processes).
- parlai.core.worlds.validate(observation)[source]¶
Make sure the observation table is valid, or raise an error.
- class parlai.core.worlds.World(opt: Opt, agents=None, shared=None)[source]¶
Bases:
object
Empty parent providing null definitions of API functions for Worlds.
All children can override these to provide more detailed functionality.
- parley()[source]¶
Perform one step of actions for the agents in the world.
This is empty in the base class.
- display()[source]¶
Return a string describing the current state of the world.
Useful for monitoring and debugging. By default, display the messages between the agents.
- epoch_done()[source]¶
Whether the epoch is done or not.
Not all worlds have the notion of an epoch, but this is useful for fixed training, validation or test sets.
Share the world.
- class parlai.core.worlds.DialogPartnerWorld(opt: Opt, agents=None, shared=None)[source]¶
Bases:
World
Simple world for two agents communicating synchronously.
This basic world switches back and forth between two agents, giving each agent one chance to speak per turn and passing that back to the other one.
- classmethod add_cmdline_args(parser: ParlaiParser, partial_opt: Optional[Opt] = None) ParlaiParser [source]¶
Return the parser as-is.
Self-chat-specific world flags can be added here.
- class parlai.core.worlds.MultiAgentDialogWorld(opt: Opt, agents, shared=None)[source]¶
Bases:
World
Basic world where each agent gets a turn in a round-robin fashion.
Each agent receives as input the actions of all other agents since its last act().
- class parlai.core.worlds.MultiWorld(opt: Opt, agents=None, shared=None, default_world=None)[source]¶
Bases:
World
Container for multiple worlds.
Container for a set of worlds where each world gets a turn in a round-robin fashion. The same user_agents are placed in each, though each world may contain additional agents according to the task that world represents.
Share all the subworlds.
- class parlai.core.worlds.BatchWorld(opt: Opt, world)[source]¶
Bases:
World
BatchWorld contains many copies of the same world.
Create a separate world for each item in the batch, sharing the parameters for each.
The underlying world(s) it is batching can be either
DialogPartnerWorld
,MultiAgentWorld
, orMultiWorld
.- batch_observe(index, batch_actions, index_acting)[source]¶
Observe corresponding actions in all subworlds.
- class parlai.core.worlds.DynamicBatchWorld(opt: Opt, world: Union[DialogPartnerWorld, MultiWorld])[source]¶
Bases:
World
- __init__(opt: Opt, world: Union[DialogPartnerWorld, MultiWorld])[source]¶
- epoch_done()[source]¶
Whether the epoch is done or not.
Not all worlds have the notion of an epoch, but this is useful for fixed training, validation or test sets.
- class parlai.core.worlds.BackgroundDriverWorld(opt: Opt, world: World)[source]¶
Bases:
World
- class parlai.core.worlds.BackgroundWorkerDynamicBatchWorld(opt: Opt, model_agent=None, process_queue=None)[source]¶
Bases:
DynamicBatchWorld
- parlai.core.worlds.create_task_world(opt: Opt, user_agents, default_world=None)[source]¶
Instantiate a world with the supplied options and user agents.
(A world factory.)
- parlai.core.worlds.create_task(opt: Opt, user_agents, default_world=None)[source]¶
Create a world + task_agents (aka a task).
Assuming
opt['task']="task_dir:teacher_class:options"
e.g."babi:Task1k:1"
or"#babi-1k"
or"#QA"
, seeparlai/tasks/tasks.py
and seeparlai/tasks/task_list.py
for list of tasks.