対数・サプライザル・情報量の単位
予測と観測の証跡を記録した後にのみ補助を利用できます。
前提条件
Day 26(確率変数と標本抽出)を完了すること。行き詰まった場合は記載の回復リンク(Day 21)を使う。
学習目標
$-\log p$ を結果のサプライザル(情報量)として解釈し、ビット($\log_2$)とナット($\ln$)を変換し、$\log(0)$ を安全に扱う。
手順
確率 $p$ の結果が持つシャノン情報量は $-\log_2 p$ ビット(または $-\ln p$ ナット)。1 ビット $= \ln 2 \approx 0.6931$ ナット。まれな結果ほど情報量が大きい。極限として $p \to 0^+$ のとき $\log p \to -\infty$(拡張実数の約束では $\log(0) = -\infty$ と書く)——これは極限の約束であり API の保証ではない:この環境の Python 標準ライブラリでは math.log(0) も math.log1p(-1) も ValueError を送出し、他の数値ライブラリの振る舞いは異なり得る。そこで実装は確率をクリップ($p \leftarrow \max(p,\varepsilon)$)するか、1 に近い引数に限り math.log1p(x) = ln(1+x) を使い、log1p(p-1) で ln p を正確に求める。p = 0 には別の方針が必要(正の下限へのクリップ、平滑化、または無限損失の明示)— log1p と名付けるだけではゼロ確率への対策にならない。
演習と予測記録
$p\in\{0.5,0.25,0.125,0.8,0.1\}$ のサプライザル表をビットとナットで作れ。さらに 2 ビットをナットに換算し、$-\ln(0.1)\approx2.3026$ が $-\ln(0.8)\approx0.2231$ の約 10 倍になる理由を説明せよ。
$-\log_2 0.5=1$、$-\log_2 0.25=2$、$-\log_2 0.125=3$。ナット = ビット $\times \ln 2$。math.log2 と math.log で各セルを確認せよ。
ビット:$0.5\to1$、$0.25\to2$、$0.125\to3$、$0.8\to0.3219$、$0.1\to3.3219$。ナット:$0.6931, 1.3863, 2.0794, 0.2231, 2.3026$。$2$ ビット $=1.3863$ ナット。$p$ が小さいほどサプライザルは大きく、ありえないトークンほど損失が約 10 倍かかる。過信した誤予測を強く罰する非対称性である。
表が両単位で検証済みの値に一致し、$\log(0)$ の失敗と具体的な対策(クリッピング/正の下限、または p が 1 に近い場合に限る log1p)に加えて、明示した p=0 方針(下限・平滑化・宣言した無限損失)を 1 つ述べられること。
公式ソースリソースと権利証跡
Information Theory, Inference, and Learning Algorithms
該当セクション・タイムスタンプ: Chapter 2: Probability, Entropy, and Inference (Shannon information content)
検証バージョンと日付: Cambridge University Press 2003, authorized free PDF (Verified: 2026-10-30)
Freely available textbook introducing surprisal -log p with worked numerical exercises.
Probability foundations (Day 25-26)
All required definitions, tables, and worked answers are reproduced locally in this lesson.
比較対象候補リソースと選定評価 (3)
The standard rigorous reference; paywalled, so it is cited alongside MacKay only via linking rather than as the sole learner-facing text.
Gentler introduction freely readable on arXiv; less depth on coding and inference connections needed for the language-model-loss bridge.
Historical primary source; valuable citation but dated notation makes it supplementary rather than primary for learners.
Python 3 math: Mathematical functions
該当セクション・タイムスタンプ: math.log, math.log2, math.log1p (log bases and near-zero precision)
検証バージョンと日付: Python 3.12 documentation (Verified: 2026-10-30)
Normative reference for the log-base and log1p calls used in the surprisal table.
Basic Python syntax
Use the installed interpreter's help(math) and the included deterministic commands.
比較対象候補リソースと選定評価 (2)
Vectorized logs arrive with the tensor track; scalar math functions keep Day 27 dependency-free.
Decimal-precision reference rather than binary float math; math remains the correct module for the operators and constants these days use.