プリンキピア

第9章リカレントニューラルネットワーク

9.4. Recurrent Neural Networks9.4 リカレントニューラルネットワーク

In Section 9.3 we described Markov models and n-grams for language modeling, where the conditional probability of token xt at time step t only depends on the n−1 previous tokens. If we want to incorporate the possible effect of tokens earlier than time step t−(n−1) on xt, we need to increase n. However, the number of model parameters would also increase exponentially with it, as we need to store |𝒱|n numbers for a vocabulary set 𝒱. Hence, rather than modeling P(xt∣xt−1,…,xt−n+1) it is preferable to use a latent variable model,
英語のヒント
9.3節では、言語のモデリングのためのマルコフモデルとnグラムを説明した。そこでは、時間ステップtのトークンxtの条件付き確率は、直前のn−1個のトークンだけに依存する。時間ステップt−(n−1)より前のトークンがxtに与えうる影響を取り込みたいなら、nを増やす必要がある。しかし、そうするとモデルのパラメータの数も指数関数的に増えてしまう。語彙集合𝒱に対して|𝒱|n個の数を保存する必要があるからである。そのため、P(xt∣xt−1,…,xt−n+1)をモデル化するよりも、潜在変数モデルを使うほうが望ましい。
P(xt∣xt−1,…,x1)≈P(xt∣ht−1),(9.4.1)
where ht−1 is a hidden state that stores the sequence information up to time step t−1. In general, the hidden state at any time step t could be computed based on both the current input xt and the previous hidden state ht−1:
英語のヒント
ここで、ht−1は時間ステップt−1までの系列の情報を保存する隠れ状態である。一般に、任意の時間ステップtの隠れ状態は、現在の入力xtと前の隠れ状態ht−1の両方にもとづいて計算できる。
ht=f(xt,ht−1).(9.4.2)
For a sufficiently powerful function f in (9.4.2), the latent variable model is not an approximation. After all, ht may simply store all the data it has observed so far. However, it could potentially make both computation and storage expensive.
英語のヒント
(9.4.2)の関数fが十分に強力なら、潜在変数モデルは近似ではない。結局のところ、htはそれまでに観測したデータをすべて単純に保存してしまえばよい。しかし、そうすると計算と記憶の両方が高くつくおそれがある。
Recall that we have discussed hidden layers with hidden units in Section 5. It is noteworthy that hidden layers and hidden states refer to two very different concepts. Hidden layers are, as explained, layers that are hidden from view on the path from input to output. Hidden states are technically speaking inputs to whatever we do at a given step, and they can only be computed by looking at data at previous time steps.
英語のヒント
第5章で、隠れユニットをもつ隠れ層を論じたことを思い出そう。隠れ層と隠れ状態は、まったく異なる二つの概念を指すことは注目に値する。隠れ層は、説明したとおり、入力から出力への経路の上で外から見えない層である。隠れ状態は、技術的に言えば、あるステップで行うことが何であれ、それへの入力であり、前の時間ステップのデータを見ることでしか計算できない。
Recurrent neural networks (RNNs) are neural networks with hidden states. Before introducing the RNN model, we first revisit the MLP model introduced in Section 5.1.
英語のヒント
リカレントニューラルネットワーク(RNN)は、隠れ状態をもつニューラルネットワークである。RNNのモデルを紹介する前に、まず5.1節で紹介したMLPのモデルを振り返ろう。
import torch
from d2l import torch as d2l