プリンキピア

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

9.5.4. Training9.5.4 訓練

Using The Time Machine dataset (data), we train a character-level language model (model) based on the RNN (rnn) implemented from scratch. Note that we first calculate the gradients, then clip them, and finally update the model parameters using the clipped gradients.
英語のヒント
『タイム・マシン』のデータセット(data)を使って、ゼロから実装したRNN(rnn)にもとづく文字単位の言語モデル(model)を訓練する。まず勾配を計算し、次にそれをクリップし、最後にクリップした勾配を使ってモデルパラメータを更新することに注意してほしい。
data = d2l.TimeMachine(batch_size=1024, num_steps=32)
rnn = RNNScratch(num_inputs=len(data.vocab), num_hiddens=32)
model = RNNLMScratch(rnn, vocab_size=len(data.vocab), lr=1)
trainer = d2l.Trainer(max_epochs=100, gradient_clip_val=1, num_gpus=1)
trainer.fit(model, data)