第9章リカレントニューラルネットワーク
9.6.2. Training and Predicting9.6.2 訓練と予測
Before training the model, let’s make a prediction with a model initialized with random weights. Given that we have not trained the network, it will generate nonsensical predictions.
英語のヒント
モデルを訓練する前に、ランダムな重みで初期化したモデルで予測をしてみよう。ネットワークを訓練していないので、無意味な予測を生成するだろう。
data = d2l.TimeMachine(batch_size=1024, num_steps=32)
rnn = RNN(num_inputs=len(data.vocab), num_hiddens=32)
model = RNNLM(rnn, vocab_size=len(data.vocab), lr=1)
model.predict('it has', 20, data.vocab)'it hasoadd dd dd dd dd dd 'Next, we train our model, leveraging the high-level API.
英語のヒント
次に、高水準APIを活用してモデルを訓練する。
trainer = d2l.Trainer(max_epochs=100, gradient_clip_val=1, num_gpus=1)
trainer.fit(model, data)Compared with Section 9.5, this model achieves comparable perplexity, but runs faster due to the optimized implementations. As before, we can generate predicted tokens following the specified prefix string.
英語のヒント
9.5節と比べると、このモデルは同程度のパープレキシティを達成するが、最適化された実装のおかげでより速く動く。前と同じように、指定した最初の文字列に続く予測トークンを生成できる。
model.predict('it has', 20, data.vocab, d2l.try_gpu())'it has and the trave the t'