class Llama::Sampler::Penalties

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(64, 1.1, 0.0, 0.0)

Defined in:

llama/sampler/penalties.cr

Constructors

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(penalty_last_n : Int32, penalty_repeat : Float32, penalty_freq : Float32, penalty_present : Float32) #

Creates a new Penalties sampler

Parameters:

  • penalty_last_n: Last n tokens to penalize (0 = disable, -1 = context size)
  • 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

[View source]