sammo.mutators

sammo.mutators#

Module Contents#

Classes#

MutatedCandidate

Mutator

SyntaxTreeMutator

PruneSyntaxTree

ShortenSegment

APO

APE

InduceInstructions

SegmentToBulletPoints

Paraphrase

ParaphraseStatic

RemoveStopWordsFromSegment

DropParameter

RepeatSegment

DropExamples

DropIntro

ReplaceParameter

ChangeDataFormat

ChangeSectionsFormat

DecreaseInContextExamples

BagOfMutators

StopwordsCompressor

Data#

logger

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(path_descriptor: str | dict, 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(path_descriptor: 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.ShortenSegment(path_descriptor: str | dict, reduction_factor: float = 0.5)#

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]#
applicable(candidate: sammo.components.Output)#
class sammo.mutators.APO(path_descriptor: str | dict, 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(path_descriptor: str | dict, 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(path_descriptor: 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.SegmentToBulletPoints(path_descriptor: str | dict, reduction_factor: float = 0.5)#

Bases: sammo.mutators.ShortenSegment

class sammo.mutators.Paraphrase(path_descriptor: str | dict, reduction_factor: float = 0.5)#

Bases: sammo.mutators.ShortenSegment

class sammo.mutators.ParaphraseStatic(path_descriptor: str | dict, static_content: str)#

Bases: sammo.mutators.ShortenSegment

class sammo.mutators.RemoveStopWordsFromSegment(path_descriptor: str | dict, choices: beartype.typing.Any)#

Bases: sammo.mutators.ShortenSegment

class sammo.mutators.DropParameter(path_descriptor: str | dict)#

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(path_descriptor: str | dict, after: str | dict)#

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(path_descriptor: str | dict)#

Bases: sammo.mutators.DropParameter

class sammo.mutators.DropIntro(path_descriptor: str | dict)#

Bases: sammo.mutators.DropParameter

class sammo.mutators.ReplaceParameter(path_descriptor: str | dict, 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(path_descriptor: str | dict, 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(path_descriptor: str | dict, 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)#
static draw_beta_bernoulli(n_samples: int, success_failure_pairs: list[tuple[int]], priors=(2, 6), seed=42)#
static draw_map_beta_bernoulli(n_samples: int, success_failure_pairs: list[tuple[int]], priors=(5, 5), seed=None)#
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)#