L17|權重初始化與正規化
為什麼每層的輸出要保持平均 0、標準差 1:介紹 Glorot/Kaiming 初始化、廣義 ReLU、LSUV、LayerNorm 與 BatchNorm,並實驗優化器與批次大小。
L17|權重初始化與正規化(Initialization/normalization)
為什麼每層的輸出要保持平均 0、標準差 1:介紹 Glorot/Kaiming 初始化、廣義 ReLU、LSUV、LayerNorm 與 BatchNorm,並實驗優化器與批次大小。 (Why each layer's outputs should keep mean 0 and standard deviation 1: Glorot/Kaiming init, Generalized ReLU, LSUV, LayerNorm and BatchNorm, plus experiments with optimizers and batch sizes.)
| 項目 | 內容 |
|---|---|
| 所屬 | Part 2:Deep Learning Foundations to Stable Diffusion |
| 影片 | YouTube |
| 對應書本章節 | 無對應章節(Part 2 以 notebook 為主) |
| 原始頁面 | Lessons/lesson17 |
| 難度(F3 視角) | ★★★★★ 大學程度(F3 只求理解概念) |
影片
本課重點
- miniai 更新:加入 HooksCallback 和 ActivationStats,更方便視覺化每層的激活值。
- 平均 0、標準差 1:訊號經過很多層後若越乘越大會爆炸,越乘越小會消失。好的初始化讓每層輸出維持在平均 0、標準差 1 附近。
- 初始化方法:Glorot(Xavier)初始化依輸入數量縮放權重;Kaiming(He)初始化考慮 ReLU 會砍掉一半,多乘 √2。順便複習變異數、標準差與共變異數。
- 廣義 ReLU 與 LSUV:自製 GeneralRelu(可平移、可設上限);LSUV 逐層實際跑一批資料,再調整權重讓輸出變異數為 1,適用任何網路。
- 正規化層:LayerNorm 與 BatchNorm 在訓練中持續把激活值調回標準範圍;也提到 InstanceNorm、GroupNorm。最後比較加速 SGD、RMSProp、Adam。
關鍵概念
| 英文術語 | 中文 | 一句話解釋 |
|---|---|---|
| Initialization | 初始化 | 訓練開始前權重的設定方式 |
| Glorot / Xavier init | Glorot 初始化 | 依輸入(與輸出)數量縮放權重 |
| Kaiming / He init | Kaiming 初始化 | 為 ReLU 設計,標準差為 √(2 ÷ 輸入數) |
| Variance | 變異數 | 與平均差距平方的平均 |
| LSUV | 逐層單位變異數 | 實際跑資料後逐層調整,讓輸出變異數為 1 |
| BatchNorm / LayerNorm | 批次/層正規化 | 訓練時把激活值調回平均 0、標準差 1 |
認識關聯圖與重點圖
練習題
- 一層有 100 個輸入。用簡化版「1 ÷ √n_in」初始化,權重標準差是多少?用 Kaiming「√(2 ÷ n_in)」呢?
- 如果每一層都把訊號放大 1.5 倍,經過 20 層後大約放大多少倍?這說明了什麼?
- BatchNorm 解決了什麼問題?
- 中文學生作答:L17_中文F3學生_202611041526
- English student answers: L17_EN_F3_Student_202611041526
資源連結
英文延伸資源(零基礎可以先略過,點開看)
Papers from the lesson
- Discuss this lesson
- Understanding the difficulty of training deep feedforward neural networks - Xavier Glorot, Yoshua Bengio
- Delving Deep into Rectifiers: Surpassing Human-Level Performance on ImageNet Classification - Kaiming He et al
- LSUV - All you need is a good init - Dmytro Mishkin, Jiri Matas
- Batch Normalization: Accelerating Deep Network Training by Reducing Internal Covariate Shift - Sergey Ioffe, Christian Szegedy
- Layer Normalization - Ba, Kiros, Hinton