プリンキピア

第10章現代のリカレントニューラルネットワーク

10.1.1. Gated Memory Cell10.1.1 ゲート付きメモリセル

Each memory cell is equipped with an internal state and a number of multiplicative gates that determine whether (i) a given input should impact the internal state (the input gate), (ii) the internal state should be flushed to 0 (the forget gate), and (iii) the internal state of a given neuron should be allowed to impact the cell’s output (the output gate).
英語のヒント
各メモリセルは、内部状態と、いくつかの乗算のゲートを備えている。ゲートは、(i)与えられた入力が内部状態に影響すべきか(入力ゲート)、(ii)内部状態を0に流し去るべきか(忘却ゲート)、(iii)あるニューロンの内部状態がセルの出力に影響するのを許すべきか(出力ゲート)を決める。

10.1.1.1. Gated Hidden State10.1.1.1 ゲート付きの隠れ状態

The key distinction between vanilla RNNs and LSTMs is that the latter support gating of the hidden state. This means that we have dedicated mechanisms for when a hidden state should be updated and also for when it should be reset. These mechanisms are learned and they address the concerns listed above. For instance, if the first token is of great importance we will learn not to update the hidden state after the first observation. Likewise, we will learn to skip irrelevant temporary observations. Last, we will learn to reset the latent state whenever needed. We discuss this in detail below.
英語のヒント
素のRNNとLSTMの鍵となる違いは、後者が隠れ状態のゲートの制御を備えていることである。つまり、隠れ状態をいつ更新すべきか、またいつリセットすべきかについて、専用の仕組みがある。これらの仕組みは学習され、上に挙げた懸念に対処する。たとえば、最初のトークンがとても重要なら、最初の観測の後で隠れ状態を更新しないことを学習する。同じように、無関係な一時的な観測を飛ばすことを学習する。最後に、必要なときにはいつでも潜在状態をリセットすることを学習する。以下でこれを詳しく論じる。

10.1.1.2. Input Gate, Forget Gate, and Output Gate10.1.1.2 入力ゲート、忘却ゲート、出力ゲート

The data feeding into the LSTM gates are the input at the current time step and the hidden state of the previous time step, as illustrated in Fig. 10.1.1. Three fully connected layers with sigmoid activation functions compute the values of the input, forget, and output gates. As a result of the sigmoid activation, all values of the three gates are in the range of (0,1). Additionally, we require an input node, typically computed with a tanh activation function. Intuitively, the input gate determines how much of the input node’s value should be added to the current memory cell internal state. The forget gate determines whether to keep the current value of the memory or flush it. And the output gate determines whether the memory cell should influence the output at the current time step.
英語のヒント
LSTMのゲートに入るデータは、図10.1.1に示すように、現在の時間ステップの入力と前の時間ステップの隠れ状態である。シグモイド活性化関数をもつ三つの全結合層が、入力ゲート、忘却ゲート、出力ゲートの値を計算する。シグモイド活性化の結果、三つのゲートの値はすべて(0,1)の範囲にある。さらに、入力ノードが必要であり、これはふつうtanh活性化関数で計算される。直観的には、入力ゲートは、入力ノードの値のどれだけを現在のメモリセルの内部状態に加えるべきかを決める。忘却ゲートは、メモリの現在の値を保つか流し去るかを決める。そして出力ゲートは、メモリセルが現在の時間ステップの出力に影響すべきかどうかを決める。
Fig. 10.1.1図10.1.1
Computing the input gate, the forget gate, and the output gate in an LSTM model.
英語のヒント
LSTMモデルで、入力ゲート、忘却ゲート、出力ゲートを計算する。
Mathematically, suppose that there are h hidden units, the batch size is n, and the number of inputs is d. Thus, the input is 𝐗t∈ℝn×d and the hidden state of the previous time step is 𝐇t−1∈ℝn×h. Correspondingly, the gates at time step t are defined as follows: the input gate is 𝐈t∈ℝn×h, the forget gate is 𝐅t∈ℝn×h, and the output gate is 𝐎t∈ℝn×h. They are calculated as follows:
英語のヒント
数学的には、隠れユニットがh個、バッチサイズがn、入力の数がdだとする。すると、入力は𝐗t∈ℝn×d、前の時間ステップの隠れ状態は𝐇t−1∈ℝn×hである。これに対応して、時間ステップtのゲートは次のように定義される。入力ゲートは𝐈t∈ℝn×h、忘却ゲートは𝐅t∈ℝn×h、出力ゲートは𝐎t∈ℝn×hである。これらは次のように計算される。
𝐈t=σ(𝐗t𝐖xi+𝐇t−1𝐖hi+𝐛i),𝐅t=σ(𝐗t𝐖xf+𝐇t−1𝐖hf+𝐛f),𝐎t=σ(𝐗t𝐖xo+𝐇t−1𝐖ho+𝐛o),(10.1.1)
where 𝐖xi,𝐖xf,𝐖xo∈ℝd×h and 𝐖hi,𝐖hf,𝐖ho∈ℝh×h are weight parameters and 𝐛i,𝐛f,𝐛o∈ℝ1×h are bias parameters. Note that broadcasting (see Section 2.1.4) is triggered during the summation. We use sigmoid functions (as introduced in Section 5.1) to map the input values to the interval (0,1).
英語のヒント
ここで、𝐖xi,𝐖xf,𝐖xo∈ℝd×hと𝐖hi,𝐖hf,𝐖ho∈ℝh×hは重みパラメータ、𝐛i,𝐛f,𝐛o∈ℝ1×hはバイアスパラメータである。和をとるときにブロードキャスト(2.1.4節を参照)が働くことに注意してほしい。(5.1節で紹介した)シグモイド関数を使って、入力の値を区間(0,1)に写す。

10.1.1.3. Input Node10.1.1.3 入力ノード

Next we design the memory cell. Since we have not specified the action of the various gates yet, we first introduce the input node 𝐂˜t∈ℝn×h. Its computation is similar to that of the three gates described above, but uses a tanh function with a value range for (−1,1) as the activation function. This leads to the following equation at time step t:
英語のヒント
次に、メモリセルを設計する。さまざまなゲートの働きはまだ指定していないので、まず入力ノード𝐂˜t∈ℝn×hを導入する。その計算は上で説明した三つのゲートのものと似ているが、活性化関数として値の範囲が(−1,1)のtanh関数を使う。これにより、時間ステップtで次の式が得られる。
𝐂˜t=tanh(𝐗t𝐖xc+𝐇t−1𝐖hc+𝐛c),(10.1.2)
where 𝐖xc∈ℝd×h and 𝐖hc∈ℝh×h are weight parameters and 𝐛c∈ℝ1×h is a bias parameter.
英語のヒント
ここで、𝐖xc∈ℝd×hと𝐖hc∈ℝh×hは重みパラメータ、𝐛c∈ℝ1×hはバイアスパラメータである。
A quick illustration of the input node is shown in Fig. 10.1.2.
英語のヒント
入力ノードの簡単な図を図10.1.2に示す。
Fig. 10.1.2図10.1.2
Computing the input node in an LSTM model.
英語のヒント
LSTMモデルで、入力ノードを計算する。

10.1.1.4. Memory Cell Internal State10.1.1.4 メモリセルの内部状態

In LSTMs, the input gate 𝐈t governs how much we take new data into account via 𝐂˜t and the forget gate 𝐅t addresses how much of the old cell internal state 𝐂t−1∈ℝn×h we retain. Using the Hadamard (elementwise) product operator ⊙ we arrive at the following update equation:
英語のヒント
LSTMでは、入力ゲート𝐈tが𝐂˜tを通じて新しいデータをどれだけ考慮に入れるかを左右し、忘却ゲート𝐅tが古いセルの内部状態𝐂t−1∈ℝn×hのどれだけを保つかを扱う。アダマール(要素ごとの)積の演算子⊙を使うと、次の更新式にたどり着く。
𝐂t=𝐅t⊙𝐂t−1+𝐈t⊙𝐂˜t.(10.1.3)
If the forget gate is always 1 and the input gate is always 0, the memory cell internal state 𝐂t−1 will remain constant forever, passing unchanged to each subsequent time step. However, input gates and forget gates give the model the flexibility of being able to learn when to keep this value unchanged and when to perturb it in response to subsequent inputs. In practice, this design alleviates the vanishing gradient problem, resulting in models that are much easier to train, especially when facing datasets with long sequence lengths.
英語のヒント
忘却ゲートがいつも1で、入力ゲートがいつも0なら、メモリセルの内部状態𝐂t−1はいつまでも一定のままで、変わらずに続く各時間ステップへ渡される。しかし、入力ゲートと忘却ゲートは、この値をいつ変えずに保ち、いつ後続の入力に応じて乱すかを学習できる柔軟さをモデルに与える。実際には、この設計は勾配消失の問題を和らげ、特に系列の長いデータセットに直面したときに、ずっと訓練しやすいモデルをもたらす。
We thus arrive at the flow diagram in Fig. 10.1.3.
英語のヒント
こうして、図10.1.3の流れ図にたどり着く。
Fig. 10.1.3図10.1.3
Computing the memory cell internal state in an LSTM model.
英語のヒント
LSTMモデルで、メモリセルの内部状態を計算する。

10.1.1.5. Hidden State10.1.1.5 隠れ状態

Last, we need to define how to compute the output of the memory cell, i.e., the hidden state 𝐇t∈ℝn×h, as seen by other layers. This is where the output gate comes into play. In LSTMs, we first apply tanh to the memory cell internal state and then apply another point-wise multiplication, this time with the output gate. This ensures that the values of 𝐇t are always in the interval (−1,1):
英語のヒント
最後に、メモリセルの出力、つまりほかの層から見た隠れ状態𝐇t∈ℝn×hをどう計算するかを定める必要がある。ここで出力ゲートの出番となる。LSTMでは、まずメモリセルの内部状態にtanhを当てはめ、次に、今度は出力ゲートとのあいだで、もう一度点ごとの掛け算を当てはめる。これにより、𝐇tの値がいつも区間(−1,1)に入ることが保証される。
𝐇t=𝐎t⊙tanh⁡(𝐂t).(10.1.4)
Whenever the output gate is close to 1, we allow the memory cell internal state to impact the subsequent layers uninhibited, whereas for output gate values close to 0, we prevent the current memory from impacting other layers of the network at the current time step. Note that a memory cell can accrue information across many time steps without impacting the rest of the network (as long as the output gate takes values close to 0), and then suddenly impact the network at a subsequent time step as soon as the output gate flips from values close to 0 to values close to 1. Fig. 10.1.4 has a graphical illustration of the data flow.
英語のヒント
出力ゲートが1に近いときはいつも、メモリセルの内部状態が妨げられずに後続の層に影響するのを許す。一方、出力ゲートの値が0に近いときは、現在の時間ステップで、現在の記憶がネットワークのほかの層に影響するのを防ぐ。メモリセルは、(出力ゲートが0に近い値をとっているかぎり)ネットワークのほかの部分に影響せずに多くの時間ステップにわたって情報をため込み、そして出力ゲートが0に近い値から1に近い値へと切り替わるとすぐに、後の時間ステップで突然ネットワークに影響しうることに注意してほしい。図10.1.4に、データの流れを図で示す。
Fig. 10.1.4図10.1.4
Computing the hidden state in an LSTM model.
英語のヒント
LSTMモデルで、隠れ状態を計算する。