温度缩放 Softmax

🖼️ Temperature-Scaled Softmax Visualizer

See how a temperature parameter sharpens or flattens a softmax distribution, which is the basis of model calibration.

📐 计算公式 / 原理
Pᵢ(T) = e^(zᵢ/T) / Σⱼ e^(zⱼ/T);分布熵 H = −Σ Pᵢ ln Pᵢ
温度 T 控制分布锐度:T→0 趋近 one-hot(更确定),T→∞ 趋近均匀分布。训练时用高温做知识蒸馏可暴露类别间关系;但温度缩放只改变锐度不改变排序,不能修复模型本身的排序错误。

📐 计算公式与说明

Pᵢ = e^(zᵢ/T) / Σe^(zⱼ/T)
T→0 更尖锐,T→∞ 更均匀

知识蒸馏中常用温度缩放。

📚 深度解析:温度缩放 Softmax

💡 常见使用场景

温度影响分布
logits=[2,1,0.5]:T=1 → 概率≈[0.6285,0.2312,0.1402];T×2=2 → [0.4810,0.2918,0.2272] 更平滑;T/2=0.5 → [0.8438,0.1142,0.0420] 更尖锐。三个温度下的 argmax 始终为第 1 类,说明温度只改变置信度分布、不改变预测类别。

❓ 常见问题(FAQ)

温度能校准模型吗?
温度缩放是最简单的后校准方法,调 T 使输出置信度匹配实际准确率;但它只缩放分布、不能修正错误预测的方向。
生成时温度设多高?
创意写作用较高 T(0.7~1.0)增多样性,事实问答用低 T(0~0.3)增确定性;过高会胡言乱语,过低则重复僵化。
页面上为什么要同时给出 T=1、T/2、T×2 三行?
单看一个温度看不出趋势。三行分别代表基准、低温(更尖锐、更自信)与高温(更平缓、更不确定),可直接读出「T 减半最大概率从 62.85% 升到 84.38%、T 翻倍降到 48.10%」这种量级变化,便于判断该往哪个方向调。温度必须大于 0,T=0 时 logits÷T 无定义。

Formula & Standard References

Item Formula / Note Source / Standard
Temperature formula temperature softmax divides logits by the temperature before exponentiation and normalisation Hinton et al. 2015, knowledge distillation
Temperature effect temperatures above one flatten the distribution and below one sharpen it Guo et al. 2017, ICML calibration
Probability property components are nonnegative and sum to one forming a valid discrete distribution Bridle 1990, Neural Computation