Sub topic 2
How Sampling and Temperature Shape Variability
Assume you understand basic chat-based LLM use, token prediction, and Python syntax. This chapter focuses on why outputs vary and how that variation can expose unreliable answers.
Sampling and temperature
An LLM assigns a score, called a logit, to each possible next token. A sampling method converts those scores into probabilities and selects a token. Temperature changes how concentrated those probabilities are:
- A low temperature favors the highest-probability token, so answers are more repeatable.
- A high temperature spreads probability across more tokens, so answers are more varied.
- Temperature changes variation, not factual knowledge. A confident-sounding error can appear at any setting.
import math
def softmax(logits, temperature=1.0):
scaled = [x / temperature for x in logits]
top = max(scaled)
values = [math.exp(x - top) for x in scaled]
total = sum(values)
return [value / total for value in values]
scores = [2.0, 1.0, 0.5]
print(softmax(scores, temperature=1.0))
print(softmax(scores, temperature=0.5))Why models guess
The model is optimized to produce a plausible continuation, not to pause when evidence is missing. Training and interface design can reward useful-looking answers. As a result, the model may complete a pattern with a specific name, date, or citation instead of stating that it lacks information.
A prompt can also create a false premise. If it asks, “Why did the 2024 law change?” the model may accept that the law changed and invent an explanation. Missing, contradictory, or ignored context causes similar failures.
Where fabrication is likely
Risk increases for:
- Obscure people, organizations, and events
- Exact numbers, dates, quotations, and legal claims
- Citations, URLs, and document titles
- Recent or rapidly changing information
- Questions containing an incorrect assumption
Warning signs
Look for false precision, unverifiable references, changing details between retries, and confidence without supporting evidence. Separate a fluent explanation from a verified claim. Check important claims against a primary source, such as the original paper, law, dataset, or official record.
Exercise
You receive three different dates for the same obscure event. What should you conclude?
Show answer
The disagreement is a warning sign that the answer needs source verification. It does not identify which date is correct.