samplers
[ allennlp.nn.samplers.samplers ]
MultinomialSampler#
@Sampler.register("multinomial")
class MultinomialSampler(Sampler):
| def __init__(
| self,
| temperature: float = 1.0,
| filter_val: float = -float("inf")
| ) -> None
Represents a sampler to choose values from a multinomial distribution.
Registered as a Sampler
with name "multinomial".
__call__#
class MultinomialSampler(Sampler):
| ...
| def __call__(
| self,
| logits: torch.Tensor,
| num_samples: int = 1,
| with_replacement: bool = True
| ) -> torch.Tensor
TopKSampler#
@Sampler.register("top-k")
class TopKSampler(Sampler):
| def __init__(
| self,
| k: int = 1,
| temperature: float = 1.0,
| filter_val: float = -float("inf")
| )
Represents a Sampler
which redistributes the probability mass function among
the top k
choices then selects from that subset
logits
is a tensor of log-probabilities to be selected from.
k
is the number of highest-probability options that the returned choice will be selected from
temperature
modules the probabilitis of the selected tokens. A temperature
below 1.0 produces a
sharper probability distribution and a temperature
above 1.0 produces a flatter probability
distribution.
Registered as a Sampler
with name "top-k".
__call__#
class TopKSampler(Sampler):
| ...
| def __call__(
| self,
| logits: torch.Tensor,
| num_samples: int = 1,
| with_replacement: bool = True
| ) -> torch.Tensor
TopPSampler#
@Sampler.register("top-p")
class TopPSampler(Sampler):
| def __init__(
| self,
| p: float = 0.9,
| temperature: float = 1.0,
| filter_val: float = -float("inf")
| )
Represents a Sampler
which redistributes the probability mass function among
the top choices with a cumulative probability of at least p
then selects from that subset
p
if minimum cumulative probability of highest-probability options that the returned
choice will be selected from temperature
modules the probabilitis of the selected tokens.
A temperature
below 1.0 produces a sharper probability distribution and a temperature
above 1.0 produces a flatter probability distribution.
Registered as a Sampler
with name "top-p".
__call__#
class TopPSampler(Sampler):
| ...
| def __call__(
| self,
| logits: torch.Tensor,
| num_samples: int = 1,
| with_replacement: bool = True
| ) -> torch.Tensor
Performs top-p sampling on the given logits
.
logits
is a tensor of log-probabilities to be selected from.
Returns the