第10章現代のリカレントニューラルネットワーク
10.2.5. Concise Implementation10.2.5 簡潔な実装
In high-level APIs, we can directly instantiate a GRU model. This encapsulates all the configuration detail that we made explicit above.
英語のヒント
高水準APIでは、GRUモデルを直接インスタンス化できる。これは、上で明示したすべての設定の詳細をカプセル化する。
class GRU(d2l.RNN):
def __init__(self, num_inputs, num_hiddens):
d2l.Module.__init__(self)
self.save_hyperparameters()
self.rnn = nn.GRU(num_inputs, num_hiddens)The code is significantly faster in training as it uses compiled operators rather than Python.
英語のヒント
このコードは、Pythonではなくコンパイルされた演算子を使うので、訓練がずっと速い。
gru = GRU(num_inputs=len(data.vocab), num_hiddens=32)
model = d2l.RNNLM(gru, vocab_size=len(data.vocab), lr=4)
trainer.fit(model, data)After training, we print out the perplexity on the training set and the predicted sequence following the provided prefix.
英語のヒント
訓練の後、訓練集合でのパープレキシティと、与えた最初の部分に続く予測の系列を表示する。
model.predict('it has', 20, data.vocab, d2l.try_gpu())'it has so it and the time '