Expand description
Sequence generation and decoding algorithms.
This module provides decoding strategies for sequence-to-sequence models:
- Greedy decoding: Select the most likely token at each step
- Beam search: Maintain top-k candidates at each step
- Nucleus (top-p) sampling: Sample from the smallest set of tokens with cumulative probability >= p
- Top-k sampling: Sample from the k most likely tokens
- Temperature sampling: Scale logits before sampling
§Example
ⓘ
use aprender::nn::generation::{BeamSearch, NucleusSampler, GenerationConfig};
// Beam search decoding
let beam = BeamSearch::new(5); // beam_size=5
let output = beam.generate(&model, &input, 50);
// Nucleus sampling
let sampler = NucleusSampler::new(0.95); // top_p=0.95
let output = sampler.sample(&logits);§References
- Holtzman, A., et al. (2020). The Curious Case of Neural Text Degeneration. ICLR. (Nucleus sampling)
- Freitag, M., & Al-Onaizan, Y. (2017). Beam Search Strategies for Neural Machine Translation. ACL Workshop.
Structs§
- Beam
Hypothesis - A single beam hypothesis in beam search.
- Beam
Search - Beam search decoder for sequence generation.
- Generation
Config - Configuration for text generation.
- Greedy
Decoder - Greedy decoder - always selects the most likely token.
- Nucleus
Sampler - Nucleus (top-p) sampler for diverse text generation.
- Teacher
Forcing - Teacher Forcing scheduler for seq2seq training.
- TopK
Sampler - Top-k sampler for text generation.
Enums§
- Teacher
Forcing Schedule - Teacher forcing schedule type.
Functions§
- apply_
repetition_ penalty - Apply repetition penalty to logits.
- apply_
temperature - Apply temperature scaling to logits.