Download the notebook and run it locally. Its environment requirements are listed inside.
Notebook contents
Readable on your phone. The code below has not been executed in the browser; download the notebook to run it.
DL · Residual vs plain: схлопывание представлений
Activity version: 1 · Seed:1 · Данные:N=128 почти ортогональных входов, ширина 64.
Интуиция из ResNet / init: deep plain ReLU (He) гонит примеры к одному направлению (рост средней |корреляции|), а residualh↦h+0.1F(h) сохраняет различие. Только forward.
Ожидаемые числа (depth 40, seed 1)
Model
mean off-diag ∥corr∥ at layer 40
Tolerance
plain
>0.7
residual
<0.35
plain − residual
>0.4
Самопроверка в ноутбуке
Не ImageNet. Не влияет на сертификат.
import numpy as nprng = np.random.default_rng(0)N, H, depth = 128, 64, 40X, _ = np.linalg.qr(rng.normal(size=(N, H)))def mean_abs_offdiag_corr(h): h = h - h.mean(axis=0, keepdims=True) h = h / (np.linalg.norm(h, axis=1, keepdims=True) + 1e-12) C = h @ h.T mask = ~np.eye(N, dtype=bool) return float(np.mean(np.abs(C[mask])))def run(residual, seed=1, gain=2.0, res_scale=0.1): rng = np.random.default_rng(seed) h = X.copy() last = None for _ in range(depth): W = rng.normal(0, np.sqrt(gain / H), size=(H, H)) a = np.maximum(0.0, h @ W) h = h + res_scale * a if residual else a last = mean_abs_offdiag_corr(h) return lastc_plain = run(False)c_res = run(True)print("plain corr", c_plain, "residual corr", c_res)assert c_plain > 0.7assert c_res < 0.35assert (c_plain - c_res) > 0.4print("OK: residual vs plain correlation collapse")