Table of Contents

Class AdaptivePSampling

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

Samples toward a TARGET CONFIDENCE rather than toward the mode: each step aims at a probability the caller chooses, and a running average of what the model actually emitted corrects the aim.

public sealed class AdaptivePSampling : TokenSampling
Inheritance
AdaptivePSampling
Inherited Members

Examples

The following example samples at a steady, moderately committed confidence:

using LMKit.Model;
using LMKit.TextGeneration;
using LMKit.TextGeneration.Sampling;

LM model = LM.LoadFromModelID("gemma4:e4b");
var chat = new MultiTurnConversation(model);

chat.SamplingMode = new AdaptivePSampling { Target = 0.55f };

var result = chat.Submit("Write the opening of a short story.");
Console.WriteLine(result.Completion);

Remarks

Temperature and the truncation family shape the distribution and let the confidence of the pick fall wherever it lands, which is why one temperature reads as flat on one prompt and unhinged on the next: the same setting means something different on a peaked distribution than on a diffuse one. This strategy steers the quantity that actually correlates with how the text reads, so a long completion holds a stable level of commitment whatever the local distribution looks like.

A high Target keeps the model close to its preferred continuation; a low one pushes it consistently toward less obvious choices. Because the average corrects over time, a stretch of forced tokens (a name, a closing bracket) is compensated afterwards instead of skewing the whole passage.

Properties

Decay

Specifies how much history the running average keeps: roughly 1 / (1 - decay) tokens.
Lower values react faster to a run of over- or under-confident picks; higher ones hold a steadier aim.
Use a floating-point value within the range [0, 0.99].

Seed

Specifies the seed used for random number generation.
If set, the seed ensures reproducibility of the sampling process by controlling the randomness in token generation.
When not set (null), the model's behavior is non-deterministic as it relies on a system-generated random seed.
Use an unsigned integer (uint) value to define the seed for reproducibility, or leave it null for standard random behavior.

Target

Specifies the probability each step aims at.

TopK

Specifies how many of the highest-scoring candidates are considered before the re-scoring runs.
Use an integer value within the range [1, 1000].

Methods

Clone()

Creates a deep copy of the current AdaptivePSampling instance.

Share