parlai.core.loader¶
Functions for loading modules for agents, tasks and teachers, worlds, and scripts.
These functions are largely for converting strings specified in opts (like for –task) to the appropriate module.
- class parlai.core.loader.script_registration(klass, hidden, aliases)¶
Bases:
tuple
- aliases¶
Alias for field number 2
Alias for field number 1
- klass¶
Alias for field number 0
- parlai.core.loader.register_agent(name: str) Callable[[Type], Type] [source]¶
Register an agent to be available in command line calls.
>>> @register_agent("my_agent") ... class MyAgent: ... pass
- parlai.core.loader.register_script(name: str, aliases=None, hidden=False)[source]¶
Register an agent to be available in command line calls.
>>> @register_script("my_script") ... class MyScript: ... pass
- parlai.core.loader.register_teacher(name: str) Callable[[Type], Type] [source]¶
Register a teacher to be available as a command line.
>>> @register_teacher("my_teacher") ... class MyTeacher: ... pass
- parlai.core.loader.load_agent_module(agent_path: str)[source]¶
Return the module for an agent specified by
--model
.Can be formatted in several different ways:
full: -m parlai.agents.seq2seq.seq2seq:Seq2seqAgent
shorthand: -m seq2seq, which will check both paths
parlai.agents.seq2seq.seq2seq:Seq2seqAgent
andparlai.agents.seq2seq.agents:Seq2seqAgent
half-shorthand:
-m seq2seq/variant
, which will check the path parlai.agents.seq2seq.variant:VariantAgent
The base path to search when using shorthand formats can be changed from “parlai” to “parlai_internal” by prepending “internal:” to the path, e.g. “internal:seq2seq”.
To use agents in projects, you can prepend “projects:” and the name of the project folder to model arguments, e.g. “projects:personachat:kvmemnn” will translate to
projects/personachat/kvmemnn
.- Parameters
agent_path – path to model class in one of the above formats.
- Returns
module of agent
- parlai.core.loader.load_task_module(taskname: str)[source]¶
Get the module containing all teacher agents for the task specified by –task.
- Parameters
taskname – path to task class in one of the formats
The valid formats for taskname are:
full:
-t parlai.tasks.babi.agents:DefaultTeacher
shorthand:
-t babi
, which will checkparlai.tasks.babi.agents:DefaultTeacher
shorthand specific:
-t babi:task10k
, which will checkparlai.tasks.babi.agents:Task10kTeacher
- Returns
module containing all teacher agents for a task
- parlai.core.loader.load_teacher_module(taskname: str)[source]¶
Get the module of the teacher agent specified by –task.
Can be formatted in several different ways:
full:
-t parlai.tasks.babi.agents:DefaultTeacher
shorthand:
-t babi
, which will checkparlai.tasks.babi.agents:DefaultTeacher
shorthand specific:
-t babi:task10k
, which will checkparlai.tasks.babi.agents:Task10kTeacher
The base path to search when using shorthand formats can be changed from “parlai” to “parlai_internal” by prepending “internal:” to the path, e.g. “internal:babi”.
Options can be sent to the teacher by adding an additional colon, for example
-t babi:task10k:1
directs the babi Task10kTeacher to use task number 1.- Parameters
taskname – path to task class in one of the above formats.
- Returns
teacher module
- parlai.core.loader.load_world_module(taskname: str, interactive_task: bool = False, selfchat_task: bool = False, num_agents: Optional[int] = None, default_world=None)[source]¶
Load the world module for the specific environment. If not enough information is to determine which world should be loaded, returns None.
- Parameters
taskname – path to task class in one of the above formats
interactive_task – whether or not the task is interactive
num_agents – number of agents in the world; this may not be known a priori
default_world – default world to return if specified
- Returns
World module (or None, if not enough info to determine is present)