プリンキピア

第3章回帰のための線形ニューラルネットワーク

3.7.1. Norms and Weight Decay3.7.1 ノルムと重み減衰

Rather than directly manipulating the number of parameters, weight decay, operates by restricting the values that the parameters can take. More commonly called ℓ2 regularization outside of deep learning circles when optimized by minibatch stochastic gradient descent, weight decay might be the most widely used technique for regularizing parametric machine learning models. The technique is motivated by the basic intuition that among all functions f, the function f=0 (assigning the value 0 to all inputs) is in some sense the simplest, and that we can measure the complexity of a function by the distance of its parameters from zero. But how precisely should we measure the distance between a function and zero? There is no single right answer. In fact, entire branches of mathematics, including parts of functional analysis and the theory of Banach spaces, are devoted to addressing such issues.
英語のヒント
重み減衰は、パラメータの数を直接操作するのではなく、パラメータがとりうる値を制限することで働く。ミニバッチ確率的勾配降下法で最適化する場合、深層学習の界隈の外ではむしろℓ2正則化と呼ばれることが多い重み減衰は、パラメトリックな機械学習モデルを正則化するのに最も広く使われている技術かもしれない。この技術の動機は、すべての関数fのなかで、関数f=0(すべての入力に値0を割り当てる)がある意味で最も単純であり、関数の複雑さをそのパラメータのゼロからの距離で測れる、という基本的な直観である。しかし、関数とゼロとの距離を正確にはどう測るべきだろうか。唯一の正解はない。実際、関数解析の一部やバナッハ空間の理論を含め、数学の分野がまるごといくつも、こうした問題に取り組むことに捧げられている。
One simple interpretation might be to measure the complexity of a linear function f(𝐱)=𝐰⊤𝐱 by some norm of its weight vector, e.g., ∥𝐰∥2. Recall that we introduced the ℓ2 norm and ℓ1 norm, which are special cases of the more general ℓp norm, in Section 2.3.11. The most common method for ensuring a small weight vector is to add its norm as a penalty term to the problem of minimizing the loss. Thus we replace our original objective, minimizing the prediction loss on the training labels, with new objective, minimizing the sum of the prediction loss and the penalty term. Now, if our weight vector grows too large, our learning algorithm might focus on minimizing the weight norm ∥𝐰∥2 rather than minimizing the training error. That is exactly what we want. To illustrate things in code, we revive our previous example from Section 3.1 for linear regression. There, our loss was given by
英語のヒント
一つの単純な解釈は、線形関数f(𝐱)=𝐰⊤𝐱の複雑さを、その重みベクトルの何らかのノルム、たとえば∥𝐰∥2で測ることかもしれない。2.3.11節で、より一般的なℓpノルムの特別な場合であるℓ2ノルムとℓ1ノルムを紹介したことを思い出そう。重みベクトルを小さく保つ最もよくある方法は、損失を最小にする問題に、そのノルムを罰則項として加えることである。したがって、訓練ラベルでの予測損失を最小にするという元の目的を、予測損失と罰則項の和を最小にするという新しい目的に置き換える。こうすると、重みベクトルが大きくなりすぎたとき、学習アルゴリズムは訓練誤差を最小にするより、重みのノルム∥𝐰∥2を最小にすることに注力するかもしれない。それこそまさに望むことである。コードで示すために、3.1節の線形回帰の前の例を復活させよう。そこでは損失は次で与えられた。
L(𝐰,b)=1n∑i=1n12(𝐰⊤𝐱(i)+b−y(i))2.(3.7.1)
Recall that 𝐱(i) are the features, y(i) is the label for any data example i, and (𝐰,b) are the weight and bias parameters, respectively. To penalize the size of the weight vector, we must somehow add ∥𝐰∥2 to the loss function, but how should the model trade off the standard loss for this new additive penalty? In practice, we characterize this trade-off via the regularization constant λ, a nonnegative hyperparameter that we fit using validation data:
英語のヒント
𝐱(i)が特徴量、y(i)が任意のデータ事例iのラベル、(𝐰,b)がそれぞれ重みとバイアスのパラメータであることを思い出そう。重みベクトルの大きさに罰則を科すには、何らかの形で損失関数に∥𝐰∥2を加えなければならないが、モデルは標準の損失と、この新しい加法的な罰則とをどう釣り合わせるべきだろうか。実際には、この釣り合いを、検証データを使って当てはめる非負のハイパーパラメータである正則化定数λで特徴づける。
L(𝐰,b)+λ2∥𝐰∥2.(3.7.2)
For λ=0, we recover our original loss function. For λ>0, we restrict the size of ∥𝐰∥. We divide by 2 by convention: when we take the derivative of a quadratic function, the 2 and 1/2 cancel out, ensuring that the expression for the update looks nice and simple. The astute reader might wonder why we work with the squared norm and not the standard norm (i.e., the Euclidean distance). We do this for computational convenience. By squaring the ℓ2 norm, we remove the square root, leaving the sum of squares of each component of the weight vector. This makes the derivative of the penalty easy to compute: the sum of derivatives equals the derivative of the sum.
英語のヒント
λ=0なら、元の損失関数に戻る。λ>0なら、∥𝐰∥の大きさを制限する。慣例により2で割る。2次関数の導関数をとると2と1/2が打ち消し合い、更新の式がきれいで単純になるからである。鋭い読者は、なぜ標準のノルム(つまりユークリッド距離)ではなく二乗ノルムを使うのか疑問に思うかもしれない。これは計算の便利さのためである。ℓ2ノルムを二乗すると平方根がなくなり、重みベクトルの各成分の二乗和が残る。これにより罰則の導関数が計算しやすくなる。導関数の和は和の導関数に等しいのである。
Moreover, you might ask why we work with the ℓ2 norm in the first place and not, say, the ℓ1 norm. In fact, other choices are valid and popular throughout statistics. While ℓ2-regularized linear models constitute the classic ridge regression algorithm, ℓ1-regularized linear regression is a similarly fundamental method in statistics, popularly known as lasso regression. One reason to work with the ℓ2 norm is that it places an outsize penalty on large components of the weight vector. This biases our learning algorithm towards models that distribute weight evenly across a larger number of features. In practice, this might make them more robust to measurement error in a single variable. By contrast, ℓ1 penalties lead to models that concentrate weights on a small set of features by clearing the other weights to zero. This gives us an effective method for feature selection, which may be desirable for other reasons. For example, if our model only relies on a few features, then we may not need to collect, store, or transmit data for the other (dropped) features.
英語のヒント
さらに、そもそもなぜ、たとえばℓ1ノルムではなくℓ2ノルムを使うのかと問うかもしれない。実際、ほかの選択も正当で、統計学全体でよく使われている。ℓ2正則化した線形モデルが古典的なリッジ回帰のアルゴリズムをなす一方、ℓ1正則化した線形回帰も統計学で同じくらい基本的な手法で、ラッソ回帰としてよく知られている。ℓ2ノルムを使う理由の一つは、重みベクトルの大きな成分に大きすぎるほどの罰則を課すことである。これにより、学習アルゴリズムは、重みをより多くの特徴量に均等に分配するモデルに偏る。実際には、これで一つの変数の測定誤差に対してより頑健になるかもしれない。これに対して、ℓ1罰則は、ほかの重みをゼロにすることで、重みを少数の特徴量に集中させるモデルにつながる。これは特徴量選択の効果的な方法になり、ほかの理由から望ましいこともある。たとえば、モデルが少数の特徴量だけに頼るなら、ほかの(落とした)特徴量のデータを集めたり、保存したり、送ったりする必要がなくなるかもしれない。
Using the same notation in (3.1.11), minibatch stochastic gradient descent updates for ℓ2-regularized regression as follows:
英語のヒント
(3.1.11)と同じ記法を使うと、ℓ2正則化した回帰のミニバッチ確率的勾配降下法の更新は次のようになる。
𝐰←(1−ηλ)𝐰−η|ℬ|∑i∈ℬ𝐱(i)(𝐰⊤𝐱(i)+b−y(i)).(3.7.3)
As before, we update 𝐰 based on the amount by which our estimate differs from the observation. However, we also shrink the size of 𝐰 towards zero. That is why the method is sometimes called “weight decay”: given the penalty term alone, our optimization algorithm decays the weight at each step of training. In contrast to feature selection, weight decay offers us a mechanism for continuously adjusting the complexity of a function. Smaller values of λ correspond to less constrained 𝐰, whereas larger values of λ constrain 𝐰 more considerably. Whether we include a corresponding bias penalty b2 can vary across implementations, and may vary across layers of a neural network. Often, we do not regularize the bias term. Besides, although ℓ2 regularization may not be equivalent to weight decay for other optimization algorithms, the idea of regularization through shrinking the size of weights still holds true.
英語のヒント
前と同じく、推定値が観測とどれだけ違うかにもとづいて𝐰を更新する。しかし、𝐰の大きさもゼロに向かって縮める。だからこの手法は「重み減衰」と呼ばれることがある。罰則項だけを考えれば、最適化アルゴリズムは訓練の各ステップで重みを減衰させるのである。特徴量選択と違い、重み減衰は関数の複雑さを連続的に調整する仕組みを与えてくれる。λの値が小さいほど𝐰の制約はゆるく、λの値が大きいほど𝐰はより強く制約される。対応するバイアスの罰則b2を含めるかどうかは実装によって異なり、ニューラルネットワークの層によっても異なりうる。バイアス項は正則化しないことが多い。さらに、ほかの最適化アルゴリズムではℓ2正則化が重み減衰と同等でないことがあるが、重みの大きさを縮めることによる正則化という考え方はそのまま当てはまる。