class
Llama::Sampler::Penalties
- Llama::Sampler::Penalties
- Llama::Sampler::Base
- Reference
- Object
Overview
Penalties sampler
The Penalties sampler applies various penalties to token probabilities to reduce repetition and improve diversity in the generated text. It can penalize recently used tokens, frequent tokens, and more.
Example:
# Apply penalties to the last 64 tokens with a repetition penalty of 1.1
sampler = Llama::Sampler::Penalties.new(vocab, 64, 1.1, 0.0, 0.0)
Defined in:
llama/sampler/penalties.crConstructors
-
.new(vocab : Vocab, penalty_last_n : Int32, penalty_repeat : Float32, penalty_freq : Float32, penalty_present : Float32)
Creates a new Penalties sampler
-
.new(n_vocab : Int32, penalty_last_n : Int32, penalty_repeat : Float32, penalty_freq : Float32, penalty_present : Float32)
Creates a new Penalties sampler from a vocabulary size.
Instance methods inherited from class Llama::Sampler::Base
to_unsafe : Pointer(Llama::LibLlama::LlamaSampler)
to_unsafe
Constructor methods inherited from class Llama::Sampler::Base
new(handle : Pointer(LibLlama::LlamaSampler))
new
Constructor Detail
def self.new(vocab : Vocab, penalty_last_n : Int32, penalty_repeat : Float32, penalty_freq : Float32, penalty_present : Float32)
#
Creates a new Penalties sampler
Parameters:
- vocab: Vocabulary whose tokens will be sampled
- penalty_last_n: Last n tokens to penalize (0 = disable)
- penalty_repeat: Repetition penalty (1.0 = disabled)
- penalty_freq: Frequency penalty (0.0 = disabled)
- penalty_present: Presence penalty (0.0 = disabled)
Raises:
- Llama::Error if the sampler cannot be created
def self.new(n_vocab : Int32, penalty_last_n : Int32, penalty_repeat : Float32, penalty_freq : Float32, penalty_present : Float32)
#
Creates a new Penalties sampler from a vocabulary size.