Evaluating Knowledge Interventions › Uncertainty under stochastic decoding

Michael BrenndoerferDecember 1, 20262 min read
Language AI HandbookAll chapters
Part 45 of 67Knowledge, Memory, Editing, and Unlearning
Chapter 351Evaluating Knowledge Interventions › Uncertainty under stochastic decoding
Reading section 7 of 16 · Uncertainty under stochastic decoding · 2 minSection 7 of 16 · 2 min

Section 7 of 16 · 2 min read

Reading settings

Definitions

Choose how many terms have tooltips.

Article links

Make inline references clickable

Notes & comments

Everything so far used greedy decoding (temperature=0), which is the right choice for reproducibility but hides the sampling variance that deployment will exhibit. Real evaluation should also measure the distribution of behavior under the deployment sampling configuration. We re-run the edit-surface and paraphrase slices at nonzero temperature and report the fraction of correct samples plus the spread.

PythonIn [21]
CollapseExpand
def sampled_eval(model_factory, edits, n_samples=200, temperature=0.7, seed=0):
    """Re-instantiate a model, apply edits, and sample many answers per item."""
    model = model_factory(temperature=temperature, seed=seed)
    for e in edits:
        model.edit(e["subject"], e["relation"], e["new_obj"])
    items = make_edit_surface(edits) + make_paraphrase_slice(edits)
    rng = np.random.default_rng(seed)
    per_item = []
    for item in items:
        correct = 0
        dist = model.answer_distribution(item["subject"], item["relation"])
        if not dist:
            raise ValueError(f"No candidate distribution for {item['prompt']}")
        outcomes = rng.choice(list(dist), size=n_samples, p=list(dist.values()))
        correct = sum(match(choice, item["expected"]) for choice in outcomes)
        per_item.append(
            {
                "prompt": item["prompt"],
                "slice": item["slice"],
                "p_correct": correct / n_samples,
            }
        )
    return per_item


def factory(temperature=0.7, seed=0):
    return ToyKnowledgeModel(KB, TEMPLATES, temperature=temperature, seed=seed)


sampled = sampled_eval(factory, edits, n_samples=200, temperature=2.0, seed=1)
ConsoleOut [22]
CollapseExpand
edit_surface   mean p(correct)=0.850 min=0.850 max=0.850
paraphrase     mean p(correct)=0.817 min=0.795 max=0.850

All four wordings reach the same stored distribution in this toy. Their true target probability at temperature 2.0 is about 0.820, and their sampled rates differ because of Monte Carlo variation. In a system whose decoder consumes the prompt, use replicated draws and a matched prompt design before attributing rate differences to wording.

With 200 independent draws, the per-prompt standard error of a Bernoulli proportion is at most about 0.035. More draws reduce Monte Carlo noise for the same prompt. Moving to more independently selected facts addresses a different question about transfer.

Comments

Add to the conversation

A question, a correction, or an example from your own work.

No comments yet. Be the first to share your thoughts!

Newsletter

Stay up to date

Get new articles, book updates, and notes on AI and technology.

Unsubscribe at any time. Privacy policy