parlai.core.mutators

parlai.core.mutators.setup_mutator_registry()[source]

Loads the mutators so that @register_mutator is hit for all.

parlai.core.mutators.register_mutator(name: str) Callable[[Type], Type][source]

Register a mutator.

class parlai.core.mutators.Mutator(opt)[source]

Bases: ABC

Base class for mutators.

Users are not advised to use this class.

classmethod load_mutator_types(mutator_names: Optional[str]) List[Type][source]

Map mutator names to actual classes via the registry.

Parameters

mutator_names – A list of one or more mutators separated by ‘+’. E.g. ‘flatten+word_shuffle’.

Returns

a list of mutators

__init__(opt)[source]
class parlai.core.mutators.MessageMutator(opt)[source]

Bases: Mutator

Message-level mutators.

Message-level mutators have a function applied per-utterance. They are ideal for transformations of data which don’t create any new conversations or turns, but only apply simple text-transformations.

Examples include:

  • Shuffling words in context

  • Adding a special token based on a non-text field

  • Replacing words with synonyms or other simple augmentations

abstract message_mutation(message: Message) Message[source]

Abstract message mutation.

The main method to implement when implementing an MessageMutator.

Parameters

message – An individual message you should mutate.

Returns

The mutated message.

class parlai.core.mutators.EpisodeMutator(opt)[source]

Bases: Mutator

Episode-level mutators.

abstract episode_mutation(episode: List[Message]) List[Message][source]

Abstract episode mutation.

The main method to implement when implementing an EpisodeMutator.

The “episode_done” field will be automatically stripped before providing as input, and automatically added back to the finalized episode.

Parameters

messages – All the messages in one episode. You may manipulate any or all of them, or change the ordering entirely.

Returns

The new, mutated episode.

class parlai.core.mutators.ManyEpisodeMutator(opt)[source]

Bases: Mutator

Episode mutator than can map one episode to zero or more.

abstract many_episode_mutation(episode: List[Message]) List[List[Message]][source]

Abstract many-episode mutation.

The main method to implement when creation a ManyEpisodeMutator. You should map this episode to zero-or-more episodes.

If you wish to create multiple episodes, you need to output one-sublist-per-new-episode. As with EpisodeMutator, “episode_done” will be automatically stripped and re-inserted for you.

Parameters

episode – A single episode (provided list of Messages).

Returns

A list of list of messages. Each sub-list will be turned into a new episode.