第12章最適化アルゴリズム
12.1.2. Optimization Challenges in Deep Learning12.1.2 深層学習での最適化の課題
In this chapter, we are going to focus specifically on the performance of optimization algorithms in minimizing the objective function, rather than a model’s generalization error. In Section 3.1 we distinguished between analytical solutions and numerical solutions in optimization problems. In deep learning, most objective functions are complicated and do not have analytical solutions. Instead, we must use numerical optimization algorithms. The optimization algorithms in this chapter all fall into this category.
英語のヒント
この章では、モデルの汎化誤差ではなく、目的関数を最小化するときの最適化アルゴリズムの性能に特に焦点を当てる。3.1節では、最適化問題の解析解と数値解を区別した。深層学習では、ほとんどの目的関数は複雑で、解析解をもたない。代わりに、数値的な最適化アルゴリズムを使わなければならない。この章の最適化アルゴリズムは、どれもこの部類に入る。
There are many challenges in deep learning optimization. Some of the most vexing ones are local minima, saddle points, and vanishing gradients. Let’s have a look at them.
英語のヒント
深層学習の最適化には多くの課題がある。最も厄介なものには、局所的な最小値、鞍点、勾配消失がある。それらを見ていこう。
12.1.2.1. Local Minima12.1.2.1 局所的な最小値
For any objective function , if the value of at is smaller than the values of at any other points in the vicinity of , then could be a local minimum. If the value of at is the minimum of the objective function over the entire domain, then is the global minimum.
英語のヒント
どんな目的関数についても、でのの値が、の近くのほかのどの点でのの値よりも小さければ、は局所的な最小値でありうる。でのの値が、定義域全体での目的関数の最小値であれば、は大域的な最小値である。
For example, given the function
英語のヒント
たとえば、次の関数が与えられたとする。
(12.1.1)
we can approximate the local minimum and global minimum of this function.
英語のヒント
この関数の局所的な最小値と大域的な最小値を近似できる。
x = torch.arange(-1.0, 2.0, 0.01)
d2l.plot(x, [f(x), ], 'x', 'f(x)')
annotate('local minimum', (-0.3, -0.25), (-0.77, -1.0))
annotate('global minimum', (1.1, -0.95), (0.6, 0.8))The objective function of deep learning models usually has many local optima. When the numerical solution of an optimization problem is near the local optimum, the numerical solution obtained by the final iteration may only minimize the objective function locally, rather than globally, as the gradient of the objective function’s solutions approaches or becomes zero. Only some degree of noise might knock the parameter out of the local minimum. In fact, this is one of the beneficial properties of minibatch stochastic gradient descent where the natural variation of gradients over minibatches is able to dislodge the parameters from local minima.
英語のヒント
深層学習のモデルの目的関数には、ふつう局所的な最適解がたくさんある。最適化問題の数値解が局所的な最適解の近くにあるとき、目的関数の解での勾配がゼロに近づくかゼロになるので、最後の反復で得られた数値解は、目的関数を大域的にではなく局所的にしか最小化しないかもしれない。パラメータを局所的な最小値からはじき出せるのは、ある程度のノイズくらいかもしれない。実際、これはミニバッチ確率的勾配降下法の役に立つ性質の一つである。そこでは、ミニバッチごとの勾配の自然なばらつきが、パラメータを局所的な最小値から追い出せる。
12.1.2.2. Saddle Points12.1.2.2 鞍点
Besides local minima, saddle points are another reason for gradients to vanish. A saddle point is any location where all gradients of a function vanish but which is neither a global nor a local minimum. Consider the function . Its first and second derivative vanish for . Optimization might stall at this point, even though it is not a minimum.
英語のヒント
局所的な最小値のほかに、鞍点も勾配が消える原因である。鞍点とは、関数のすべての勾配が消えるが、大域的な最小値でも局所的な最小値でもない位置のことである。関数を考えよう。その1階と2階の導関数はで消える。最小値でないにもかかわらず、最適化はこの点で止まってしまうかもしれない。
x = torch.arange(-2.0, 2.0, 0.01)
d2l.plot(x, [x**3], 'x', 'f(x)')
annotate('saddle point', (0, -0.2), (-0.52, -5.0))Saddle points in higher dimensions are even more insidious, as the example below shows. Consider the function . It has its saddle point at . This is a maximum with respect to and a minimum with respect to . Moreover, it looks like a saddle, which is where this mathematical property got its name.
英語のヒント
次の例が示すように、高次元の鞍点はさらに油断ならない。関数を考えよう。その鞍点はにある。これは、については最大値であり、については最小値である。さらに、それは鞍のように見え、この数学的な性質の名前はそこから来ている。
x, y = torch.meshgrid(
torch.linspace(-1.0, 1.0, 101), torch.linspace(-1.0, 1.0, 101))
z = x**2 - y**2
ax = d2l.plt.figure().add_subplot(111, projection='3d')
ax.plot_wireframe(x, y, z, **{'rstride': 10, 'cstride': 10})
ax.plot([0], [0], [0], 'rx')
ticks = [-1, 0, 1]
d2l.plt.xticks(ticks)
d2l.plt.yticks(ticks)
ax.set_zticks(ticks)
d2l.plt.xlabel('x')
d2l.plt.ylabel('y');We assume that the input of a function is a -dimensional vector and its output is a scalar, so its Hessian matrix will have eigenvalues. The solution of the function could be a local minimum, a local maximum, or a saddle point at a position where the function gradient is zero:
英語のヒント
関数の入力が次元のベクトルで、出力がスカラーだとすると、そのヘッセ行列は個の固有値をもつ。関数の勾配がゼロになる位置では、関数の解は、局所的な最小値、局所的な最大値、鞍点のいずれかでありうる。
- When the eigenvalues of the function’s Hessian matrix at the zero-gradient position are all positive, we have a local minimum for the function.
英語のヒント
勾配がゼロの位置での関数のヘッセ行列の固有値がすべて正のとき、関数は局所的な最小値をもつ。 - When the eigenvalues of the function’s Hessian matrix at the zero-gradient position are all negative, we have a local maximum for the function.
英語のヒント
勾配がゼロの位置での関数のヘッセ行列の固有値がすべて負のとき、関数は局所的な最大値をもつ。 - When the eigenvalues of the function’s Hessian matrix at the zero-gradient position are negative and positive, we have a saddle point for the function.
英語のヒント
勾配がゼロの位置での関数のヘッセ行列の固有値に負のものと正のものがあるとき、関数は鞍点をもつ。
For high-dimensional problems the likelihood that at least some of the eigenvalues are negative is quite high. This makes saddle points more likely than local minima. We will discuss some exceptions to this situation in the next section when introducing convexity. In short, convex functions are those where the eigenvalues of the Hessian are never negative. Sadly, though, most deep learning problems do not fall into this category. Nonetheless it is a great tool to study optimization algorithms.
英語のヒント
高次元の問題では、固有値の少なくともいくつかが負である見込みはかなり高い。このため、鞍点は局所的な最小値よりも起こりやすい。この状況のいくつかの例外は、次の節で凸性を紹介するときに論じる。手短に言えば、凸関数とは、ヘッセ行列の固有値がけっして負にならない関数である。しかし残念ながら、ほとんどの深層学習の問題はこの部類に入らない。それでも、凸性は最適化アルゴリズムを研究するためのすばらしい道具である。
12.1.2.3. Vanishing Gradients12.1.2.3 勾配消失
Probably the most insidious problem to encounter is the vanishing gradient. Recall our commonly-used activation functions and their derivatives in Section 5.1.2. For instance, assume that we want to minimize the function and we happen to get started at . As we can see, the gradient of is close to nil. More specifically, and thus . Consequently, optimization will get stuck for a long time before we make progress. This turns out to be one of the reasons that training deep learning models was quite tricky prior to the introduction of the ReLU activation function.
英語のヒント
出会う問題の中でおそらく最も油断ならないのは、勾配消失である。5.1.2節の、よく使う活性化関数とその導関数を思い出そう。たとえば、関数を最小化したいとして、たまたまから始めたとする。見てのとおり、の勾配はほとんどゼロである。もっと具体的には、であり、したがってである。その結果、最適化は前進する前に長いあいだ止まってしまう。これが、ReLU活性化関数が導入される前に、深層学習のモデルの訓練がかなり厄介だった理由の一つであることがわかっている。
x = torch.arange(-2.0, 5.0, 0.01)
d2l.plot(x, [torch.tanh(x)], 'x', 'f(x)')
annotate('vanishing gradient', (4, 1), (2, 0.0))As we saw, optimization for deep learning is full of challenges. Fortunately there exists a robust range of algorithms that perform well and that are easy to use even for beginners. Furthermore, it is not really necessary to find the best solution. Local optima or even approximate solutions thereof are still very useful.
英語のヒント
見てきたように、深層学習の最適化は課題だらけである。幸い、性能がよく、初心者にも使いやすい、しっかりしたアルゴリズムがひととおりそろっている。さらに、最良の解を見つけることは、実はそれほど必要ではない。局所的な最適解や、その近似解でさえ、十分に役に立つ。