第6章構築者のための手引き
6.2. Parameter Management6.2 パラメータの管理
Once we have chosen an architecture and set our hyperparameters, we proceed to the training loop, where our goal is to find parameter values that minimize our loss function. After training, we will need these parameters in order to make future predictions. Additionally, we will sometimes wish to extract the parameters perhaps to reuse them in some other context, to save our model to disk so that it may be executed in other software, or for examination in the hope of gaining scientific understanding.
英語のヒント
構造を選び、ハイパーパラメータを設定したら、訓練ループに進む。そこでの目標は、損失関数を最小にするパラメータの値を見つけることである。訓練の後は、今後の予測をするためにこれらのパラメータが必要になる。さらに、ときにはパラメータを取り出したいこともある。たとえば、別の文脈で使い回すため、ほかのソフトウェアで実行できるようにモデルをディスクに保存するため、あるいは科学的な理解を得ることを期待して調べるためである。
Most of the time, we will be able to ignore the nitty-gritty details of how parameters are declared and manipulated, relying on deep learning frameworks to do the heavy lifting. However, when we move away from stacked architectures with standard layers, we will sometimes need to get into the weeds of declaring and manipulating parameters. In this section, we cover the following:
英語のヒント
たいていは、パラメータがどう宣言され操作されるかという細かい細部は無視して、深層学習のフレームワークに力仕事を任せられる。しかし、標準的な層を積み重ねた構造から離れると、パラメータを宣言し操作する細部に踏み込む必要が出てくることもある。この節では、次のことを扱う。
- Accessing parameters for debugging, diagnostics, and visualizations.
英語のヒント
デバッグ、診断、可視化のためにパラメータにアクセスすること。 - Sharing parameters across different model components.
英語のヒント
モデルの異なる部品のあいだでパラメータを共有すること。
import torch
from torch import nnWe start by focusing on an MLP with one hidden layer.
英語のヒント
隠れ層が一つのMLPに注目することから始めよう。
net = nn.Sequential(nn.LazyLinear(8),
nn.ReLU(),
nn.LazyLinear(1))
X = torch.rand(size=(2, 4))
net(X).shapetorch.Size([2, 1])