知识卡片
直接对数归一化更稳健
计算 token 对数概率应优先使用稳定的 log_softmax,而非先计算可能下溢的 softmax 再取对数。更换数值表示时也要对应更换聚合:概率乘积对应对数求和,不能用概率求和或对数相乘替代同一个序列概率。
这张卡片看不懂?
这张卡片已通过人工审查,不再接受失败反馈。
已有反馈 · 0 条
还没有人提交反馈。
在整书笔记中的位置
原书出处 · 1 处
- · 查看原书依据
natural logarithm, where 𝑙𝑜𝑔(0.0090) = -4.7109 and vice versa 𝑒-4.7109 = 0.0090. Instead of chaining torch.log(torch.softmax(...)), PyTorch also has an optimized torch.log_softmax function that combines these two operations: log_probas = torch.log_softmax(logits, dim=-1) print(log_probas) Similar to before, this returns: tensor([-4.7109, -4.0442, -3.3776, -2.7109, -2.0442, -1.3776, -0.7109]) Note that the log-scaling only changes the magnitude of the values, not the ordering, so a sequence with a higher
参考来源
- 位置:《Build a Reasoning Model (From Scratch)》第05章《自我修正与推理时扩展》(来源项目:a19c7933-4eda-4176-aebd-30fe7e1ad292;源文件:extracted/Build a Reasoning Model (From Scratch)/_epub-src/OEBPS/Text/chapter-5.html)
- 结论依据:摘录中关于直接对数归一化更稳健的定义、比较或条件支撑卡片;原书表述不严谨的范围已在覆盖记录逐项限定,不把案例结果外推为普遍结论。
- 原始内容:natural logarithm, where 𝑙𝑜𝑔(0.0090) = -4.7109 and vice versa 𝑒-4.7109 = 0.0090. Instead of chaining torch.log(torch.softmax(...)), PyTorch also has an optimized torch.log_softmax function that combines these two operations: log_probas = torch.log_softmax(logits, dim=-1) print(log_probas) Similar to before, this returns: tensor([-4.7109, -4.0442, -3.3776, -2.7109, -2.0442, -1.3776, -0.7109]) Note that the log-scaling only changes the magnitude of the values, not the ordering, so a sequence with a higher