[1] 用 meta-learning 學(xué)樣本權(quán)重,可用于 class imbalance、noisy label 場景。之前對(duì)其 (7) 式中 ? i , t = 0 \epsilon_{i,t}=0 ?i,t?=0(對(duì)應(yīng) Algorithm 1 第 5 句、代碼 ex_wts_a = tf.zeros([bsize_a], dtype=tf.float32))不理解:如果 ? \epsilon ? 已知是 0,那 (4) 式的加權(quán) loss 不是恒為零嗎?(5) 式不是優(yōu)化了個(gè)吉而 θ ^ t + 1 ( ? ) ≡ θ t \hat\theta_{t+1}(\epsilon) \equiv \theta_t θ^t+1?(?)≡θt? ?有人在 issue 提了這個(gè)問題[2],但其人想通了沒解釋就關(guān)了 issue。
看到 [3] 代碼中對(duì)
?
\epsilon
? 設(shè)了 requires_grad=True
才反應(yīng)過來:用編程的話說,
?
\epsilon
? 不應(yīng)理解成常量,而是變量; 用數(shù)學(xué)的話說,(5) 的求梯度(
?
\nabla
?)是算子,而不是函數(shù),即 (5) 只是在借梯度下降建立
θ
^
t
+
1
\hat\theta_{t+1}
θ^t+1? 與
?
\epsilon
? 之間的函數(shù)(或用 TensorFlow 的話說,只是在建圖),即
θ
^
t
+
1
(
?
)
\hat\theta_{t+1}(\epsilon)
θ^t+1?(?),而不是基于常量
θ
t
\theta_t
θt?、
?
=
0
\epsilon=0
?=0 算了一步 SGD 得到一個(gè)常量
θ
^
t
+
1
\hat\theta_{t+1}
θ^t+1?。
一個(gè)符號(hào)細(xì)節(jié):無 hat 的 θ t + 1 \theta_{t+1} θt+1? 指由 (3) 用無 perturbation 的 loss 經(jīng) SGD 從 θ t \theta_t θt? 優(yōu)化一步所得; θ ^ t + 1 \hat\theta_{t+1} θ^t+1? 則是用 (4) perturbed loss。文中 (6)、(7) 有錯(cuò)用作 θ t + 1 \theta_{t+1} θt+1? 的嫌疑。
所以大思路是用 clean validation set 構(gòu)造一條關(guān)于 ? \epsilon ? 的 loss J ( ? ) J(\epsilon) J(?),然后用優(yōu)化器求它,即 ? t ? = arg ? min ? ? J ( ? ) \epsilon_t^*=\arg\min_\epsilon J(\epsilon) ?t??=argmin??J(?)。由 (4) - (6) 有: J ( ? ) = 1 M ∑ j = 1 M f j v ( θ ^ t + 1 ( ? ) ) ( 6 ) = 1 M ∑ j = 1 M f j v ( θ t ? α [ ? θ ∑ i = 1 n f i , ? ( θ ) ] ∣ θ = θ t ? g 1 ( ? ; θ t ) ) ( 5 ) = 1 M ∑ j = 1 M f j v ( θ t ? α [ ? θ ∑ i = 1 n ? i f i ( θ ) ] ∣ θ = θ t ) ( 4 ) = g 2 ( ? ; θ t ) \begin{aligned} J(\epsilon) &= \frac{1}{M}\sum_{j=1}^M f_j^v \left(\hat\theta_{t+1}(\epsilon) \right) & (6) \\ &= \frac{1}{M}\sum_{j=1}^M f_j^v \left(\theta_t - \alpha \underbrace{\left[ \nabla_{\theta} \sum_{i=1}^n f_{i,\epsilon}(\theta) \right] \bigg|_{\theta=\theta_t}}_{g_1(\epsilon; \theta_t)} \right) & (5) \\ &= \frac{1}{M}\sum_{j=1}^M f_j^v \left(\theta_t - \alpha \left[ \nabla_{\theta} \sum_{i=1}^n \epsilon_i f_i(\theta) \right] \bigg|_{\theta=\theta_t} \right) & (4) \\ &= g_2(\epsilon; \theta_t) \end{aligned} J(?)?=M1?j=1∑M?fjv?(θ^t+1?(?))=M1?j=1∑M?fjv? ?θt??αg1?(?;θt?) [?θ?i=1∑n?fi,??(θ)] ?θ=θt???? ?=M1?j=1∑M?fjv?(θt??α[?θ?i=1∑n??i?fi?(θ)] ?θ=θt??)=g2?(?;θt?)?(6)(5)(4)? 要注意的就是 (5) 那求導(dǎo)式,本質(zhì)是個(gè)函數(shù),而不是常量,其中 ? \epsilon ? 是自由的, θ \theta θ 由于被 ∣ θ = θ t |_{\theta=\theta_t} ∣θ=θt?? 指定了,所以看成常量,所以記為 g 1 ( ? ; θ t ) g_1(\epsilon;\theta_t) g1?(?;θt?),于是整個(gè) J ( ? ) J(\epsilon) J(?) 也可以看成一個(gè) g 2 ( ? ; θ t ) g_2(\epsilon; \theta_t) g2?(?;θt?)。
按 (6) 求 ? t ? \epsilon_t^* ?t?? 的思路就是:
- 隨機(jī)初始化 ? t ( 0 ) \epsilon_t^{(0)} ?t(0)?;
- ? t ( s + 1 ) ← ? t ( s ) ? η ? ? J ( ? ) ∣ ? = ? t ( s ) \epsilon^{(s+1)}_t \leftarrow \epsilon^{(s)}_t - \eta \nabla_{\epsilon} J(\epsilon) \big|_{\epsilon=\epsilon^{(s)}_t} ?t(s+1)?←?t(s)??η???J(?) ??=?t(s)??,即 (7) 右邊??赡苡捎? J ( ? ) J(\epsilon) J(?) 形式上是帶梯度的表達(dá)式, § \S § 3.3 就稱此為「unroll the gradient graph」,而求 ? t ( s + 1 ) \epsilon^{(s+1)}_t ?t(s+1)? 的這一步就稱為「backward-on-backward」吧。
而文章的 online approximation 就是:文章來源:http://www.zghlxwxcb.cn/news/detail-817937.html
- ? t ( 0 ) = 0 \epsilon^{(0)}_t=0 ?t(0)?=0
- ? t ? ≈ ? t ( 1 ) \epsilon^*_t \approx \epsilon^{(1)}_t ?t??≈?t(1)?
初始化為 0 可能不是最好的初始化方法,但不影響后續(xù)迭代優(yōu)化,可參考 LoRA[7],它也用到全零初始化。文章來源地址http://www.zghlxwxcb.cn/news/detail-817937.html
References
- (ICML’18) Learning to Reweight Examples for Robust Deep Learning - paper, code
- gradients of noisy loss w.r.t parameter \theta #2
- (PyTorch 復(fù)現(xiàn) 1)TinfoilHat0/Learning-to-Reweight-Examples-for-Robust-Deep-Learning-with-PyTorch-Higher
- (PyTorch 復(fù)現(xiàn) 2)danieltan07/learning-to-reweight-examples
- facebookresearch/higher
- Stateful vs stateless
- (ICLR’22) LoRA: Low-Rank Adaptation of Large Language Models - paper, code
到了這里,關(guān)于《Learning to Reweight Examples for Robust Deep Learning》筆記的文章就介紹完了。如果您還想了解更多內(nèi)容,請(qǐng)?jiān)谟疑辖撬阉鱐OY模板網(wǎng)以前的文章或繼續(xù)瀏覽下面的相關(guān)文章,希望大家以后多多支持TOY模板網(wǎng)!