Two essential sampling controls for LLM text generation:
Signature: def apply_temperature_and_penalty(logits, temperature, past_token_ids, repetition_penalty=1.0)
logits: (vocab_size,)temperature: float > 0past_token_ids: list of int — tokens already generated (may contain duplicates)repetition_penalty: float ≥ 1.0 (1.0 = no penalty)(vocab_size,) — probability distribution after penalty + temperature + softmaxMath
Asked at
import numpy as np
def apply_temperature_and_penalty(...):
pass
Premium problem
Free accounts include problems #1–20. Upgrade to unlock the editor, hidden test cases, and reference solutions for every problem.
Already premium?