mellea.stdlib.sampling
class mellea.stdlib.sampling.SamplingResult(result: ModelOutputThunk, success: bool, sample_generations: list[ModelOutputThunk] | None = None, sample_validations: list[list[tuple[Requirement, bool]]] | None = None)
result
: The final output or result from applying the sampling strategy.success
: A boolean indicating whether the operation was successful.sample_generations
: A list containing intermediate generations produced during the process.sample_validations
: For each generation a list of a requirement and a boolean value indicating whether the requirement was met.class mellea.stdlib.sampling.SamplingStrategy()
mellea.stdlib.sampling.SamplingStrategy.sample(instruction: Instruction, generate_logs: list[GenerateLog] | None = None)
instruction
: Instruction
: The instruction object to be sampled.generate_logs
: Optional list of GenerateLog objects. If None, no collection happens.class mellea.stdlib.sampling.RejectionSamplingStrategy(loop_budget: int = 1, repair: Callable[[Instruction, list[tuple[Requirement, bool]], list[Instruction]], Instruction] = lambda i, r, h_i: i, select_from_failure: Callable[[Instruction, list[ModelOutputThunk], list[list[tuple[Requirement, bool]]]], ModelOutputThunk] = lambda _, results, __: results[0], validate: Callable[[list[Requirement], Any], list[bool]] | None = None, generate: Callable[[Instruction, list[GenerateLog] | None], ModelOutputThunk] | None = None, requirements: list[Requirement] | None = None)
loop_budget
: Number of times to iterate through the process. Must be greater than 0.repair
: Function to apply “repairs” to an instruction based on its requirements and validation results.select_from_failure
: Function to select a model output thunk from failed attempts.validate
: Function to validate the results against requirements. If None, validation is provided later through setter.generate
: Function to generate new model output thunks. If None, generate is provided later through setter.requirements
: List of requirements to test against. If None, test all requirements attached to the given instruction.mellea.stdlib.sampling.RejectionSamplingStrategy.sample(instruction: Instruction, show_progress: bool = True, generate_logs: list[GenerateLog] | None = None)
instruction
: The Instruction object containing the instruction to generate a valid model output thunk.show_progress
: if true, a tqdm progress bar is used. Otherwise messages will still be sent to flog.generate_logs
: If provided, the generations will be logged.SamplingResult
: A result object indicating the success or failure of the sampling process.