using System; using LLama.Native; namespace LLama.Sampling.Tokens; /// /// Sample with TopK, removing all by the K most likely tokens. /// Top-K sampling described in academic paper "The Curious Case of Neural Text Degeneration" https://arxiv.org/abs/1904.09751 /// public sealed class TopKSampling : ITokenDataProcessor { /// /// Number of tokens to keep /// public int Count { get; set; } /// public void ProcessTokens(SafeLLamaContextHandle ctx, LLamaTokenDataArray tokens, ReadOnlySpan lastTokens) { tokens.TopK(ctx, Count); } /// public void AcceptToken(SafeLLamaContextHandle ctx, int token) { } /// public void Reset() { } /// public void Dispose() { } }