Table of Contents

Class RepetitionPenalty

Namespace
LMKit.TextGeneration.Sampling
Assembly
LM-Kit.NET.dll

Configures repetition penalties applied during text generation to reduce redundant or monotonous output.

public sealed class RepetitionPenalty
Inheritance
RepetitionPenalty
Inherited Members

Constructors

RepetitionPenalty()

Initializes a new instance of the RepetitionPenalty class with TokenCount set to 0, effectively disabling all penalties.

RepetitionPenalty(int)

Initializes a new instance of the RepetitionPenalty class with the specified lookback window size.

Properties

FrequencyPenalty

Specifies an additive penalty that scales with how often a token has appeared in the lookback window.
Higher values more strongly discourage tokens that have been used frequently.
Positive values reduce repetition; negative values encourage it; zero disables this penalty.
Use a floating-point value within the range [-2, 2].

PresencePenalty

Specifies an additive penalty applied to any token that has appeared at least once in the lookback window.
Unlike FrequencyPenalty, this penalty does not scale with occurrence count.
Positive values encourage the model to explore new topics; negative values encourage staying on topic; zero disables this penalty.
Use a floating-point value within the range [-2, 2].

RepeatPenalty

Specifies a multiplicative penalty applied to any token that has already appeared in the lookback window.
Unlike FrequencyPenalty, this penalty is applied uniformly regardless of how many times the token occurred.
Values greater than 1 discourage repetition; a value of 1 disables this penalty.
Use a floating-point value within the range [0, 2].

TokenCount

Specifies the lookback window size, in tokens, for applying repetition penalties.
Only tokens within this window are considered when calculating penalties.
One token is roughly equivalent to 4 characters in standard English text.
Use a value within the range [0, 2048].
Use 0 to disable all repetition penalties.

Methods

Clone()

Creates a new instance of RepetitionPenalty that is a copy of the current instance.

Disable()

Disables all repetition penalties by setting TokenCount to 0, RepeatPenalty to 1, and both FrequencyPenalty and PresencePenalty to 0.