Week 09 · Decoding and adaptation

Compare greedy and sampled outputs, then measure a small adaptation.

← Week 8 · Subject contents · Week 10 →

Compare greedy and sampled outputs, then measure a small adaptation.

Work through the problem

Temperature divides logits by T before softmax. For logits [1,0], the first-token probability is about 0.881 at T=0.5 and 0.622 at T=2. Greedy decoding picks the highest score either way. Sampling makes the difference visible.

Adaptation changes the model. Here an initial two-token distribution comes from counts [8,2]. Add task examples and compare log loss on held-out task tokens. Adaptation helps only if those new examples move probabilities toward the evaluation distribution.

Run the Python lab

import numpy as np
rng = np.random.default_rng(55)
for T in [.5,2]:
    e = np.exp(np.array([1.,0.])/T)
    p = e/e.sum()
    print(T,"greedy",p.argmax(),"sample rate for 0",round(np.mean(rng.choice(2,8000,p=p)==0),3))
heldout = np.array([1,1,0,1,1])
for name, counts in [("Base",[8,2]),("Adapted",[9,11])]:
    p = np.array(counts)/sum(counts)
    print(name,"held-out loss",round(-np.log(p[heldout]).mean(),3))

Output from the lab

0.5 greedy 0 sample rate for 0 0.878
2 greedy 0 sample rate for 0 0.622
Base held-out loss 1.332
Adapted held-out loss 0.638

Practice

  1. Is changing temperature the same as training on domain examples?

Check your reasoning

  1. Temperature rescales existing logits without learning new distinctions or changing their order.

← Week 8 · Subject contents · Week 10 →

Further reading · Jurafsky and Martin · Speech and Language Processing