第23章付録:深層学習のための道具
23.8.1. Classes23.8.1 クラス
class d2l.torch.AdditiveAttention(num_hiddens, dropout, **kwargs)- Bases:
Module英語のヒント
基底クラス:ModuleAdditive attention.英語のヒント
加法注意。forward(queries, keys, values, valid_lens)- Defines the computation performed at every call.
英語のヒント
呼び出しのたびに実行される計算を定義する。Should be overridden by all subclasses.英語のヒント
すべてのサブクラスでオーバーライドされるべきである。Note注意
Although the recipe for forward pass needs to be defined within this function, one should call theModuleinstance afterwards instead of this since the former takes care of running the registered hooks while the latter silently ignores them.英語のヒント
順伝播の手順はこの関数の中で定義する必要があるが、その後はこの関数ではなくModuleのインスタンスを呼び出すべきである。前者は登録されたフックの実行を引き受けるが、後者はそれらを黙って無視するからである。
class d2l.torch.AddNorm(norm_shape, dropout)- Bases:
Module英語のヒント
基底クラス:ModuleThe residual connection followed by layer normalization.英語のヒント
残差接続とその後の層正規化。forward(X, Y)- Defines the computation performed at every call.
英語のヒント
呼び出しのたびに実行される計算を定義する。Should be overridden by all subclasses.英語のヒント
すべてのサブクラスでオーバーライドされるべきである。Note注意
Although the recipe for forward pass needs to be defined within this function, one should call theModuleinstance afterwards instead of this since the former takes care of running the registered hooks while the latter silently ignores them.英語のヒント
順伝播の手順はこの関数の中で定義する必要があるが、その後はこの関数ではなくModuleのインスタンスを呼び出すべきである。前者は登録されたフックの実行を引き受けるが、後者はそれらを黙って無視するからである。
class d2l.torch.AttentionDecoder- The base attention-based decoder interface.
英語のヒント
注意機構にもとづくデコーダの基底インターフェース。property attention_weights
class d2l.torch.Classifier(plot_train_per_epoch=2, plot_valid_per_epoch=1)- The base class of classification models.
英語のヒント
分類モデルの基底クラス。accuracy(Y_hat, Y, averaged=True)- Compute the number of correct predictions.
英語のヒント
正しい予測の数を計算する。
layer_summary(X_shape)
loss(Y_hat, Y, averaged=True)
validation_step(batch)
class d2l.torch.DataModule(root='../data', num_workers=4)- The base class of data.
英語のヒント
データの基底クラス。get_dataloader(train)
get_tensorloader(tensors, train, indices=slice(0, None, None))
train_dataloader()
val_dataloader()
class d2l.torch.Decoder- Bases:
Module英語のヒント
基底クラス:ModuleThe base decoder interface for the encoder–decoder architecture.英語のヒント
エンコーダ・デコーダ構造のためのデコーダの基底インターフェース。forward(X, state)- Defines the computation performed at every call.
英語のヒント
呼び出しのたびに実行される計算を定義する。Should be overridden by all subclasses.英語のヒント
すべてのサブクラスでオーバーライドされるべきである。Note注意
Although the recipe for forward pass needs to be defined within this function, one should call theModuleinstance afterwards instead of this since the former takes care of running the registered hooks while the latter silently ignores them.英語のヒント
順伝播の手順はこの関数の中で定義する必要があるが、その後はこの関数ではなくModuleのインスタンスを呼び出すべきである。前者は登録されたフックの実行を引き受けるが、後者はそれらを黙って無視するからである。
init_state(enc_all_outputs, *args)
class d2l.torch.DotProductAttention(dropout)- Bases:
Module英語のヒント
基底クラス:ModuleScaled dot product attention.英語のヒント
スケール化内積注意。forward(queries, keys, values, valid_lens=None)- Defines the computation performed at every call.
英語のヒント
呼び出しのたびに実行される計算を定義する。Should be overridden by all subclasses.英語のヒント
すべてのサブクラスでオーバーライドされるべきである。Note注意
Although the recipe for forward pass needs to be defined within this function, one should call theModuleinstance afterwards instead of this since the former takes care of running the registered hooks while the latter silently ignores them.英語のヒント
順伝播の手順はこの関数の中で定義する必要があるが、その後はこの関数ではなくModuleのインスタンスを呼び出すべきである。前者は登録されたフックの実行を引き受けるが、後者はそれらを黙って無視するからである。
class d2l.torch.Encoder- Bases:
Module英語のヒント
基底クラス:ModuleThe base encoder interface for the encoder–decoder architecture.英語のヒント
エンコーダ・デコーダ構造のためのエンコーダの基底インターフェース。forward(X, *args)- Defines the computation performed at every call.
英語のヒント
呼び出しのたびに実行される計算を定義する。Should be overridden by all subclasses.英語のヒント
すべてのサブクラスでオーバーライドされるべきである。Note注意
Although the recipe for forward pass needs to be defined within this function, one should call theModuleinstance afterwards instead of this since the former takes care of running the registered hooks while the latter silently ignores them.英語のヒント
順伝播の手順はこの関数の中で定義する必要があるが、その後はこの関数ではなくModuleのインスタンスを呼び出すべきである。前者は登録されたフックの実行を引き受けるが、後者はそれらを黙って無視するからである。
class d2l.torch.EncoderDecoder(encoder, decoder)- The base class for the encoder–decoder architecture.
英語のヒント
エンコーダ・デコーダ構造のための基底クラス。forward(enc_X, dec_X, *args)- Defines the computation performed at every call.
英語のヒント
呼び出しのたびに実行される計算を定義する。Should be overridden by all subclasses.英語のヒント
すべてのサブクラスでオーバーライドされるべきである。Note注意
Although the recipe for forward pass needs to be defined within this function, one should call theModuleinstance afterwards instead of this since the former takes care of running the registered hooks while the latter silently ignores them.英語のヒント
順伝播の手順はこの関数の中で定義する必要があるが、その後はこの関数ではなくModuleのインスタンスを呼び出すべきである。前者は登録されたフックの実行を引き受けるが、後者はそれらを黙って無視するからである。
predict_step(batch, device, num_steps, save_attention_weights=False)
class d2l.torch.FashionMNIST(batch_size=64, resize=(28, 28))- The Fashion-MNIST dataset.
英語のヒント
Fashion-MNISTのデータセット。get_dataloader(train)
text_labels(indices)- Return text labels.
英語のヒント
テキストのラベルを返す。
visualize(batch, nrows=1, ncols=8, labels=[])
class d2l.torch.GRU(num_inputs, num_hiddens, num_layers, dropout=0)- The multilayer GRU model.
英語のヒント
多層のGRUモデル。
class d2l.torch.HyperParameters- Bases:
object英語のヒント
基底クラス:objectThe base class of hyperparameters.英語のヒント
ハイパーパラメータの基底クラス。save_hyperparameters(ignore=[])- Save function arguments into class attributes.
英語のヒント
関数の引数をクラスの属性に保存する。
class d2l.torch.LeNet(lr=0.1, num_classes=10)- The LeNet-5 model.
英語のヒント
LeNet-5のモデル。
class d2l.torch.LinearRegression(lr)- The linear regression model implemented with high-level APIs.
英語のヒント
高水準のAPIで実装した線形回帰のモデル。configure_optimizers()
forward(X)
get_w_b()
loss(y_hat, y)
class d2l.torch.LinearRegressionScratch(num_inputs, lr, sigma=0.01)- The linear regression model implemented from scratch.
英語のヒント
ゼロから実装した線形回帰のモデル。configure_optimizers()
forward(X)
loss(y_hat, y)
class d2l.torch.Module(plot_train_per_epoch=2, plot_valid_per_epoch=1)- The base class of models.
英語のヒント
モデルの基底クラス。apply_init(inputs, init=None)
configure_optimizers()
forward(X)- Defines the computation performed at every call.
英語のヒント
呼び出しのたびに実行される計算を定義する。Should be overridden by all subclasses.英語のヒント
すべてのサブクラスでオーバーライドされるべきである。Note注意
Although the recipe for forward pass needs to be defined within this function, one should call theModuleinstance afterwards instead of this since the former takes care of running the registered hooks while the latter silently ignores them.英語のヒント
順伝播の手順はこの関数の中で定義する必要があるが、その後はこの関数ではなくModuleのインスタンスを呼び出すべきである。前者は登録されたフックの実行を引き受けるが、後者はそれらを黙って無視するからである。
loss(y_hat, y)
plot(key, value, train)- Plot a point in animation.
英語のヒント
アニメーションで点をプロットする。
training_step(batch)
validation_step(batch)
class d2l.torch.MTFraEng(batch_size, num_steps=9, num_train=512, num_val=128)- The English-French dataset.
英語のヒント
英語・フランス語のデータセット。build(src_sentences, tgt_sentences)
get_dataloader(train)
class d2l.torch.MultiHeadAttention(num_hiddens, num_heads, dropout, bias=False, **kwargs)- Multi-head attention.
英語のヒント
マルチヘッド注意。forward(queries, keys, values, valid_lens)- Defines the computation performed at every call.
英語のヒント
呼び出しのたびに実行される計算を定義する。Should be overridden by all subclasses.英語のヒント
すべてのサブクラスでオーバーライドされるべきである。Note注意
Although the recipe for forward pass needs to be defined within this function, one should call theModuleinstance afterwards instead of this since the former takes care of running the registered hooks while the latter silently ignores them.英語のヒント
順伝播の手順はこの関数の中で定義する必要があるが、その後はこの関数ではなくModuleのインスタンスを呼び出すべきである。前者は登録されたフックの実行を引き受けるが、後者はそれらを黙って無視するからである。
transpose_output(X)- Reverse the operation of transpose_qkv.
英語のヒント
transpose_qkvの演算を逆にする。
transpose_qkv(X)- Transposition for parallel computation of multiple attention heads.
英語のヒント
複数の注意ヘッドを並列に計算するための転置。
class d2l.torch.PositionalEncoding(num_hiddens, dropout, max_len=1000)- Bases:
Module英語のヒント
基底クラス:ModulePositional encoding.英語のヒント
位置符号化。forward(X)- Defines the computation performed at every call.
英語のヒント
呼び出しのたびに実行される計算を定義する。Should be overridden by all subclasses.英語のヒント
すべてのサブクラスでオーバーライドされるべきである。Note注意
Although the recipe for forward pass needs to be defined within this function, one should call theModuleinstance afterwards instead of this since the former takes care of running the registered hooks while the latter silently ignores them.英語のヒント
順伝播の手順はこの関数の中で定義する必要があるが、その後はこの関数ではなくModuleのインスタンスを呼び出すべきである。前者は登録されたフックの実行を引き受けるが、後者はそれらを黙って無視するからである。
class d2l.torch.PositionWiseFFN(ffn_num_hiddens, ffn_num_outputs)- Bases:
Module英語のヒント
基底クラス:ModuleThe positionwise feed-forward network.英語のヒント
位置ごとのフィードフォワードネットワーク。forward(X)- Defines the computation performed at every call.
英語のヒント
呼び出しのたびに実行される計算を定義する。Should be overridden by all subclasses.英語のヒント
すべてのサブクラスでオーバーライドされるべきである。Note注意
Although the recipe for forward pass needs to be defined within this function, one should call theModuleinstance afterwards instead of this since the former takes care of running the registered hooks while the latter silently ignores them.英語のヒント
順伝播の手順はこの関数の中で定義する必要があるが、その後はこの関数ではなくModuleのインスタンスを呼び出すべきである。前者は登録されたフックの実行を引き受けるが、後者はそれらを黙って無視するからである。
class d2l.torch.ProgressBoard(xlabel=None, ylabel=None, xlim=None, ylim=None, xscale='linear', yscale='linear', ls=['-', '--', '-.', ':'], colors=['C0', 'C1', 'C2', 'C3'], fig=None, axes=None, figsize=(3.5, 2.5), display=True)- The board that plots data points in animation.
英語のヒント
データ点をアニメーションでプロットするボード。draw(x, y, label, every_n=1)
class d2l.torch.Residual(num_channels, use_1x1conv=False, strides=1)- Bases:
Module英語のヒント
基底クラス:ModuleThe Residual block of ResNet models.英語のヒント
ResNetのモデルの残差ブロック。forward(X)- Defines the computation performed at every call.
英語のヒント
呼び出しのたびに実行される計算を定義する。Should be overridden by all subclasses.英語のヒント
すべてのサブクラスでオーバーライドされるべきである。Note注意
Although the recipe for forward pass needs to be defined within this function, one should call theModuleinstance afterwards instead of this since the former takes care of running the registered hooks while the latter silently ignores them.英語のヒント
順伝播の手順はこの関数の中で定義する必要があるが、その後はこの関数ではなくModuleのインスタンスを呼び出すべきである。前者は登録されたフックの実行を引き受けるが、後者はそれらを黙って無視するからである。
class d2l.torch.ResNeXtBlock(num_channels, groups, bot_mul, use_1x1conv=False, strides=1)- Bases:
Module英語のヒント
基底クラス:ModuleThe ResNeXt block.英語のヒント
ResNeXtブロック。forward(X)- Defines the computation performed at every call.
英語のヒント
呼び出しのたびに実行される計算を定義する。Should be overridden by all subclasses.英語のヒント
すべてのサブクラスでオーバーライドされるべきである。Note注意
Although the recipe for forward pass needs to be defined within this function, one should call theModuleinstance afterwards instead of this since the former takes care of running the registered hooks while the latter silently ignores them.英語のヒント
順伝播の手順はこの関数の中で定義する必要があるが、その後はこの関数ではなくModuleのインスタンスを呼び出すべきである。前者は登録されたフックの実行を引き受けるが、後者はそれらを黙って無視するからである。
class d2l.torch.RNN(num_inputs, num_hiddens)- The RNN model implemented with high-level APIs.
英語のヒント
高水準のAPIで実装したRNNのモデル。forward(inputs, H=None)- Defines the computation performed at every call.
英語のヒント
呼び出しのたびに実行される計算を定義する。Should be overridden by all subclasses.英語のヒント
すべてのサブクラスでオーバーライドされるべきである。Note注意
Although the recipe for forward pass needs to be defined within this function, one should call theModuleinstance afterwards instead of this since the former takes care of running the registered hooks while the latter silently ignores them.英語のヒント
順伝播の手順はこの関数の中で定義する必要があるが、その後はこの関数ではなくModuleのインスタンスを呼び出すべきである。前者は登録されたフックの実行を引き受けるが、後者はそれらを黙って無視するからである。
class d2l.torch.RNNLM(rnn, vocab_size, lr=0.01)- The RNN-based language model implemented with high-level APIs.
英語のヒント
高水準のAPIで実装したRNNベースの言語モデル。init_params()
output_layer(hiddens)
class d2l.torch.RNNLMScratch(rnn, vocab_size, lr=0.01)- The RNN-based language model implemented from scratch.
英語のヒント
ゼロから実装したRNNベースの言語モデル。forward(X, state=None)
init_params()
one_hot(X)
output_layer(rnn_outputs)
predict(prefix, num_preds, vocab, device=None)
training_step(batch)
validation_step(batch)
class d2l.torch.RNNScratch(num_inputs, num_hiddens, sigma=0.01)- The RNN model implemented from scratch.
英語のヒント
ゼロから実装したRNNのモデル。forward(inputs, state=None)
class d2l.torch.Seq2Seq(encoder, decoder, tgt_pad, lr)- The RNN encoder–decoder for sequence to sequence learning.
英語のヒント
系列から系列への学習のためのRNNエンコーダ・デコーダ。configure_optimizers()
validation_step(batch)
class d2l.torch.Seq2SeqEncoder(vocab_size, embed_size, num_hiddens, num_layers, dropout=0)- The RNN encoder for sequence-to-sequence learning.
英語のヒント
系列から系列への学習のためのRNNエンコーダ。forward(X, *args)- Defines the computation performed at every call.
英語のヒント
呼び出しのたびに実行される計算を定義する。Should be overridden by all subclasses.英語のヒント
すべてのサブクラスでオーバーライドされるべきである。Note注意
Although the recipe for forward pass needs to be defined within this function, one should call theModuleinstance afterwards instead of this since the former takes care of running the registered hooks while the latter silently ignores them.英語のヒント
順伝播の手順はこの関数の中で定義する必要があるが、その後はこの関数ではなくModuleのインスタンスを呼び出すべきである。前者は登録されたフックの実行を引き受けるが、後者はそれらを黙って無視するからである。
class d2l.torch.SGD(params, lr)- Minibatch stochastic gradient descent.
英語のヒント
ミニバッチ確率的勾配降下法。step()
zero_grad()
class d2l.torch.SoftmaxRegression(num_outputs, lr)- The softmax regression model.
英語のヒント
ソフトマックス回帰のモデル。forward(X)- Defines the computation performed at every call.
英語のヒント
呼び出しのたびに実行される計算を定義する。Should be overridden by all subclasses.英語のヒント
すべてのサブクラスでオーバーライドされるべきである。Note注意
Although the recipe for forward pass needs to be defined within this function, one should call theModuleinstance afterwards instead of this since the former takes care of running the registered hooks while the latter silently ignores them.英語のヒント
順伝播の手順はこの関数の中で定義する必要があるが、その後はこの関数ではなくModuleのインスタンスを呼び出すべきである。前者は登録されたフックの実行を引き受けるが、後者はそれらを黙って無視するからである。
class d2l.torch.SyntheticRegressionData(w, b, noise=0.01, num_train=1000, num_val=1000, batch_size=32)- Synthetic data for linear regression.
英語のヒント
線形回帰のための合成データ。get_dataloader(train)
class d2l.torch.TimeMachine(batch_size, num_steps, num_train=10000, num_val=5000)- The Time Machine dataset.
英語のヒント
『タイム・マシン』のデータセット。build(raw_text, vocab=None)
get_dataloader(train)
class d2l.torch.Trainer(max_epochs, num_gpus=0, gradient_clip_val=0)- The base class for training models with data.
英語のヒント
データでモデルを訓練するための基底クラス。clip_gradients(grad_clip_val, model)
fit(model, data)
fit_epoch()
prepare_batch(batch)
prepare_data(data)
prepare_model(model)
class d2l.torch.TransformerEncoder(vocab_size, num_hiddens, ffn_num_hiddens, num_heads, num_blks, dropout, use_bias=False)- The Transformer encoder.
英語のヒント
Transformerのエンコーダ。forward(X, valid_lens)- Defines the computation performed at every call.
英語のヒント
呼び出しのたびに実行される計算を定義する。Should be overridden by all subclasses.英語のヒント
すべてのサブクラスでオーバーライドされるべきである。Note注意
Although the recipe for forward pass needs to be defined within this function, one should call theModuleinstance afterwards instead of this since the former takes care of running the registered hooks while the latter silently ignores them.英語のヒント
順伝播の手順はこの関数の中で定義する必要があるが、その後はこの関数ではなくModuleのインスタンスを呼び出すべきである。前者は登録されたフックの実行を引き受けるが、後者はそれらを黙って無視するからである。
class d2l.torch.TransformerEncoderBlock(num_hiddens, ffn_num_hiddens, num_heads, dropout, use_bias=False)- Bases:
Module英語のヒント
基底クラス:ModuleThe Transformer encoder block.英語のヒント
Transformerのエンコーダブロック。forward(X, valid_lens)- Defines the computation performed at every call.
英語のヒント
呼び出しのたびに実行される計算を定義する。Should be overridden by all subclasses.英語のヒント
すべてのサブクラスでオーバーライドされるべきである。Note注意
Although the recipe for forward pass needs to be defined within this function, one should call theModuleinstance afterwards instead of this since the former takes care of running the registered hooks while the latter silently ignores them.英語のヒント
順伝播の手順はこの関数の中で定義する必要があるが、その後はこの関数ではなくModuleのインスタンスを呼び出すべきである。前者は登録されたフックの実行を引き受けるが、後者はそれらを黙って無視するからである。
class d2l.torch.Vocab(tokens=[], min_freq=0, reserved_tokens=[])- Bases:
object英語のヒント
基底クラス:objectVocabulary for text.英語のヒント
テキストのための語彙。to_tokens(indices)
property unk