samplers package

Submodules

samplers.accumulation_sampler module

class samplers.accumulation_sampler.AccumulationSampler(distribution, total_size=512)[source]

Bases: Sampler

Utility class to accumulate samples, up to a total size

sample(sampling_size=32, context='')[source]

accumulates batches of samples from the distribution

Parameters:
sampling_size: int

number of requested samples per individual sampling

context: text

contextual text for which to sample

Returns:
a tuple of accumulated samples and scores

samplers.quasi_rejection_sampler module

class samplers.quasi_rejection_sampler.QuasiRejectionSampler(target, proposal, beta=1)[source]

Bases: Sampler

Quasi Rejection-Sampling class

get_acceptance_rate()[source]

Computes the acceptance rate, that is the number of accepted samples over the total sampled ones

Returns:
acceptance rate as float between 0 and 1
sample(sampling_size=32, context='')[source]

Generates samples according to the QRS algorithm

Parameters:
sampling_size: int

number of requested samples when sampling

context: text

contextual text for which to sample

Returns:
tuple of accepted samples and their log-scores

samplers.sampler module

class samplers.sampler.Sampler(target, proposal)[source]

Bases: ABC

Top-level abstract class for all samplers

abstract sample()[source]

Module contents