Class RandomSampling
- Namespace
- LMKit.TextGeneration.Sampling
- Assembly
- LM-Kit.NET.dll
Handles random sampling strategy (also known as temperature-based sampling).
public sealed class RandomSampling : TokenSampling
- Inheritance
-
RandomSampling
- Inherited Members
Examples
The following example shows how to configure random sampling with custom parameters:
using LMKit.Model;
using LMKit.TextGeneration;
using LMKit.TextGeneration.Sampling;
LM model = LM.LoadFromModelID("gemma4:e4b");
var chat = new MultiTurnConversation(model);
// Configure random sampling with lower temperature for more focused output.
chat.SamplingMode = new RandomSampling
{
Temperature = 0.5f,
TopP = 0.9f,
TopK = 50,
MinP = 0.05f
};
var result = chat.Submit("Write a short poem about the sea.");
Console.WriteLine(result.Completion);
Properties
- DynamicTemperatureRange
Specifies the dynamic temperature strategy's intensity for decoding processes.
This property accepts a floating-point value ranging from 0 to 1, where 0 completely turns off dynamic temperature adjustments, and 1 applies the maximum intensity of temperature coefficient adjustments for dynamic decoding strategies.
- EpsilonCutoff
Specifies an ABSOLUTE probability floor: candidates below it are dropped whatever the rest of the distribution looks like.
Use 0 to disable.
- EtaCutoff
Specifies an entropy-aware probability floor: the cut is
min(eta, sqrt(eta) * exp(-H)), so the same setting truncates a confident prediction harder than an uncertain one.
Use 0 to disable.
- ExcludeTopChoicesProbability
Specifies how often the most predictable candidates are REMOVED, leaving a still-likely alternative to be sampled instead.
- ExcludeTopChoicesThreshold
Specifies the probability a candidate must reach to count as one of the "top choices" that ExcludeTopChoicesProbability may remove.
Values above 0.5 disable the stage, since at most one candidate could then qualify and the last qualifying candidate is always kept.
Use a floating-point value within the range [0, 0.5].
- LocallyTypical
Specifies diversity through Locally Typical sampling method.
Use a floating-point value within the range [0 , 1].
Use 1 to disable this sampler.
- MinP
Specifies diversity through MinP sampling method.
All tokens with a probability percentage exceeding the MinP threshold are taken into consideration.
Use a floating-point value within the range [0 , 1].
Use 0 to disable MinP sampling.
- SamplersSequence
Specifies an enumeration for RandomSamplers that outlines a customizable sequence of sampler algorithms.
This enumeration facilitates the dynamic arrangement of various sampling strategies, enabling precise control over the random sampling process.
- 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.
- SmoothingCurve
Shapes the far tail of SmoothingFactor: 1 is the pure quadratic form, and higher values add a cubic term that pushes distant candidates down harder.
Use a floating-point value within the range [1, 3].
- SmoothingFactor
Specifies the strength of the quadratic transform, an alternative to Temperature that compresses the head of the distribution instead of rescaling all of it.
- Temperature
Specifies output randomness level.
Lowering the temperature leads to fewer random completions.
As the temperature approaches zero, the model becomes more deterministic and repetitive.
Use a floating-point value within the range [0 (more deterministic), 1 (more random)].
- TopA
Specifies diversity through Top-A sampling, whose threshold scales with the SQUARE of the best candidate's probability.
A confident prediction is therefore truncated hard and an uncertain one is left almost intact, which is what makes this a set-and-forget alternative to retuning TopP per prompt.
Use 0 to disable.
- TopK
Specifies the vocabulary size considered during completion (or text generation).
Use an integer value within the range [1, 1000].
- TopNSigma
Keeps only candidates whose pre-softmax score is within this many standard deviations of the best one.
Because the cut is measured on raw scores, it holds steady as Temperature changes, which is what makes higher temperatures usable on reasoning tasks.
Use 0 to disable.
- TopP
Specifies diversity through nucleus sampling method.
The TopP algorithm computes the cumulative probability distribution and cuts off as soon as that distribution exceeds the value of TopP.
For example, a value of 0.8 implies that 80% of all likelihood-weighted options are considered.
This sampling strategy aims to strike a balance between diversity and quality, taking into account both the probability of tokens and the quantity of tokens to be sampled.
Use a floating-point value within the range [0 (more conservative), 1 (more diverse)].
Use 1 to disable TopP sampling.
Methods
- Clone()
Creates a deep copy of the current RandomSampling instance.