第9章リカレントニューラルネットワーク
9.6. Concise Implementation of Recurrent Neural Networks9.6 リカレントニューラルネットワークの簡潔な実装
Like most of our from-scratch implementations, Section 9.5 was designed to provide insight into how each component works. But when you are using RNNs every day or writing production code, you will want to rely more on libraries that cut down on both implementation time (by supplying library code for common models and functions) and computation time (by optimizing the heck out of these library implementations). This section will show you how to implement the same language model more efficiently using the high-level API provided by your deep learning framework. We begin, as before, by loading The Time Machine dataset.
英語のヒント
ゼロからの実装のほとんどと同じように、9.5節は、各部品がどう働くかについての洞察を与えるように作られていた。しかし、RNNを毎日使ったり、実運用のコードを書いたりするときには、実装の時間(よくあるモデルや関数のためのライブラリのコードを提供することで)と計算の時間(そうしたライブラリの実装をとことん最適化することで)の両方を減らしてくれるライブラリにもっと頼りたくなるだろう。この節では、深層学習のフレームワークが提供する高水準APIを使って、同じ言語モデルをもっと効率よく実装する方法を示す。前と同じように、『タイム・マシン』のデータセットを読み込むことから始める。
import torch
from torch import nn
from torch.nn import functional as F
from d2l import torch as d2l