第10章現代のリカレントニューラルネットワーク
10.1.3. Concise Implementation10.1.3 簡潔な実装
Using high-level APIs, we can directly instantiate an LSTM model. This encapsulates all the configuration details that we made explicit above. The code is significantly faster as it uses compiled operators rather than Python for many details that we spelled out before.
英語のヒント
高水準APIを使えば、LSTMモデルを直接インスタンス化できる。これは、上で明示したすべての設定の詳細をカプセル化する。このコードは、前に詳しく書き出した多くの細部にPythonではなくコンパイルされた演算子を使うので、ずっと速い。
class LSTM(d2l.RNN):
def __init__(self, num_inputs, num_hiddens):
d2l.Module.__init__(self)
self.save_hyperparameters()
self.rnn = nn.LSTM(num_inputs, num_hiddens)
def forward(self, inputs, H_C=None):
return self.rnn(inputs, H_C)
lstm = LSTM(num_inputs=len(data.vocab), num_hiddens=32)
model = d2l.RNNLM(lstm, vocab_size=len(data.vocab), lr=4)
trainer.fit(model, data)model.predict('it has', 20, data.vocab, d2l.try_gpu())'it has a the time travelly'LSTMs are the prototypical latent variable autoregressive model with nontrivial state control. Many variants thereof have been proposed over the years, e.g., multiple layers, residual connections, different types of regularization. However, training LSTMs and other sequence models (such as GRUs) is quite costly because of the long range dependency of the sequence. Later we will encounter alternative models such as Transformers that can be used in some cases.
英語のヒント
LSTMは、自明でない状態の制御をもつ、典型的な潜在変数自己回帰モデルである。長年にわたって、多層化、残差接続、さまざまな種類の正則化など、その変種が数多く提案されてきた。しかし、LSTMやほかの系列モデル(GRUなど)を訓練するのは、系列の長距離の依存関係のせいでかなり費用がかかる。後で、場合によっては使える、Transformerのような代わりのモデルに出会う。