sammo.mutators

sammo.mutators#

Module Contents#

Classes#

Data#

API#

sammo.mutators.logger = 'getLogger(...)'#
class sammo.mutators.MutatedCandidate(action, candidate, **kwargs)#

Initialization

with_parent(parent)#
class sammo.mutators.Mutator(starting_prompt: sammo.components.Output | beartype.typing.Callable | None = None, seed: int = 42, sample_for_init_candidates: bool = True)#

Bases: abc.ABC

applicable(candidate: sammo.components.Output) bool#

Returns True if this mutator can be applied to a candidate.

property priors#
property objective#
update_priors(priors: dict[dict])#
abstract async mutate(candidate: sammo.components.Output, data: sammo.data.DataTable, runner: sammo.base.Runner, n_mutations: int = 1, random_state: int = 42) list[sammo.mutators.MutatedCandidate]#

Returns a list of at most n_mutations new candidates.

async get_initial_candidates(runner: sammo.base.Runner | None, n_initial_candidates: int) list[sammo.mutators.MutatedCandidate]#
class sammo.mutators.SyntaxTreeMutator(css_selector: str, starting_prompt: sammo.components.Output | beartype.typing.Callable, cache: collections.abc.MutableMapping | None = None)#

Bases: sammo.mutators.Mutator

syntax_parser = None#
static parse_document(raw_doc)#
classmethod split_into_phrases(sent)#
classmethod get_phrases(raw_doc)#
applicable(candidate: sammo.components.Output)#
static replace_all_elements(l, needle, replacement)#
static delete_all_elements(l, needle)#
static swap_all_elements(lst, x, y)#
async mutate(candidate: sammo.components.Output, data: sammo.data.DataTable, runner: sammo.base.Runner, n_mutations: int = 1, random_state: int = 42) list[sammo.mutators.MutatedCandidate]#
class sammo.mutators.PruneSyntaxTree(css_selector: str | dict, starting_prompt: sammo.components.Output | beartype.typing.Callable, prune_metric: beartype.typing.Callable, cache: collections.abc.MutableMapping | None = None)#

Bases: sammo.mutators.SyntaxTreeMutator

async mutate(candidate: sammo.components.Output, data: sammo.data.DataTable, runner: sammo.base.Runner, n_mutations: int = 1, random_state: int = 42) list[sammo.mutators.MutatedCandidate]#
class sammo.mutators.Rewrite(css_selector: str, rewrite_instructions: str | None = None, deterministic=None, **kwargs)#

Bases: sammo.mutators.Mutator

TEMPLATE = <Multiline-String>#
DETERMINISTIC = True#
async mutate(candidate: sammo.components.Output, data: sammo.data.DataTable, runner: sammo.base.Runner, n_mutations: int = 1, random_state: int = 42) list[sammo.mutators.MutatedCandidate]#
applicable(candidate: sammo.components.Output)#
class sammo.mutators.SegmentToBulletPoints(css_selector: str, rewrite_instructions: str | None = None, deterministic=None, **kwargs)#

Bases: sammo.mutators.Rewrite

TEMPLATE = <Multiline-String>#
class sammo.mutators.Paraphrase(css_selector: str, rewrite_instructions: str | None = None, deterministic=None, **kwargs)#

Bases: sammo.mutators.Rewrite

TEMPLATE = <Multiline-String>#
DETERMINISTIC = False#
class sammo.mutators.ShortenSegment(css_selector: str, reduction_factor: float = 0.5)#

Bases: sammo.mutators.Rewrite

TEMPLATE = <Multiline-String>#
class sammo.mutators.APO(css_selector: str, starting_prompt: sammo.components.Output | beartype.typing.Callable | None, num_rewrites=2, num_sampled_errors=4, num_gradients=4, steps_per_gradient=2, minibatch_size=None, seed=42)#

Bases: sammo.mutators.Mutator

async mutate(candidate: sammo.components.Output, data: sammo.data.DataTable, runner: sammo.base.Runner, n_mutations: int = 1, random_state: int = 42) list[sammo.mutators.MutatedCandidate]#
class sammo.mutators.APE(css_selector: str, starting_prompt: sammo.components.Output | beartype.typing.Callable, d_incontext: sammo.data.DataTable, n_incontext_subsamples: int | None = None)#

Bases: sammo.mutators.ShortenSegment

RESAMPLE = 'dedent(...)'#
async get_initial_candidates(runner: sammo.base.Runner, n_initial_candidates: int) list[sammo.mutators.MutatedCandidate]#
class sammo.mutators.InduceInstructions(css_selector: str | dict, d_incontext: sammo.data.DataTable)#

Bases: sammo.mutators.APE

async mutate(candidate: sammo.components.Output, data: sammo.data.DataTable, runner: sammo.base.Runner, n_mutations: int = 1, random_state: int = 42) list[sammo.mutators.MutatedCandidate]#
class sammo.mutators.RemoveStopWordsFromSegment(css_selector: str | dict, choices: beartype.typing.Any)#

Bases: sammo.mutators.Rewrite

class sammo.mutators.DropParameter(css_selector: str)#

Bases: sammo.mutators.Mutator

applicable(candidate: sammo.components.Output)#
async mutate(candidate: sammo.components.Output, data: sammo.data.DataTable, runner: sammo.base.Runner, n_mutations: int = 1, random_state: int = 42) list[sammo.mutators.MutatedCandidate]#
class sammo.mutators.RepeatSegment(css_selector: str, after: str)#

Bases: sammo.mutators.DropParameter

applicable(candidate: sammo.components.Output)#
async mutate(candidate: sammo.components.Output, data: sammo.data.DataTable, runner: sammo.base.Runner, n_mutations: int = 1, random_state: int = 42) list[sammo.mutators.MutatedCandidate]#
class sammo.mutators.DropExamples(css_selector: str)#

Bases: sammo.mutators.DropParameter

class sammo.mutators.DropIntro(css_selector: str)#

Bases: sammo.mutators.DropParameter

class sammo.mutators.ReplaceParameter(css_selector: str, choices: beartype.typing.Any)#

Bases: sammo.mutators.DropParameter

async mutate(candidate: sammo.components.Output, data: sammo.data.DataTable, runner: sammo.base.Runner, n_mutations: int = 1, random_state: int = 42) list[sammo.mutators.MutatedCandidate]#
class sammo.mutators.ChangeDataFormat(css_selector: str, choices: beartype.typing.Any)#

Bases: sammo.mutators.ReplaceParameter

async mutate(candidate: sammo.components.Output, data: sammo.data.DataTable, runner: sammo.base.Runner, n_mutations: int = 1, random_state: int = 42) list[sammo.mutators.MutatedCandidate]#
class sammo.mutators.ChangeSectionsFormat(css_selector: str, choices: beartype.typing.Any)#

Bases: sammo.mutators.ReplaceParameter

class sammo.mutators.DecreaseInContextExamples(d_incontext, reduction_factor=0.8, min_examples=1)#

Bases: sammo.mutators.Mutator

applicable(candidate: sammo.components.Output)#
async mutate(candidate: sammo.components.Output, data: sammo.data.DataTable, runner: sammo.base.Runner, n_mutations: int = 1, random_state=42) list[sammo.mutators.MutatedCandidate]#
class sammo.mutators.BagOfMutators(starting_prompt: sammo.components.Output | beartype.typing.Callable, *bag, seed: int = 42, sample_for_init_candidates: bool = True)#

Bases: sammo.mutators.Mutator

applicable(candidate: sammo.components.Output)#
async mutate(candidate: sammo.components.Output, data: sammo.data.DataTable, runner: sammo.base.Runner, n_mutations: int = 1, random_state=None) list[sammo.mutators.MutatedCandidate]#
class sammo.mutators.StopwordsCompressor(filter_stopwords: beartype.typing.Literal[reuters, spacy, none], remove_punctuation=False, remove_whitespace=False)#

Bases: sammo.base.Component

REUTERS_STOPLIST = ['a', 'an', 'and', 'are', 'as', 'at', 'be', 'by', 'for', 'from', 'has', 'he', 'in', 'it', 'it', 'its...#
compress(x: str)#