Complete the code to apply temperature scaling to logits before sampling.
scaled_logits = logits / [1]Temperature is used to scale logits before sampling to control randomness.
Complete the code to sample an index from the probability distribution after softmax.
probabilities = softmax(scaled_logits) sampled_index = [1](len(probabilities), p=probabilities)
np.random.choice can sample an index based on given probabilities.
Fix the error in the code to correctly apply temperature and sample from logits.
def sample_with_temperature(logits, temperature): scaled = logits * [1] probs = softmax(scaled) return np.random.choice(len(probs), p=probs)
Logits must be divided by temperature, which is equivalent to multiplying by 1/temperature.
Fill both blanks to create a function that returns probabilities after temperature scaling.
def temperature_scaled_probs(logits, [1]): scaled_logits = logits / [2] return softmax(scaled_logits)
The function takes temperature as input and divides logits by it before softmax.
Fill all three blanks to implement sampling with temperature scaling and softmax.
def sample(logits, [1]): scaled = logits / [2] probs = softmax([3]) return np.random.choice(len(probs), p=probs)
The function uses temperature to scale logits, applies softmax to scaled logits, then samples.