プリンキピア

第4章分類のための線形ニューラルネットワーク

4.5.1. Defining the Model4.5.1 モデルの定義

As in Section 3.5, we construct our fully connected layer using the built-in layer. The built-in __call__ method then invokes forward whenever we need to apply the network to some input.
英語のヒント
3.5節と同じく、組み込みの層を使って全結合層を組み立てる。そのうえで、ネットワークを何かの入力に適用する必要があるときはいつでも、組み込みの__call__メソッドがforwardを呼び出す。
We use a Flatten layer to convert the fourth-order tensor X to second order by keeping the dimensionality along the first axis unchanged.
英語のヒント
Flatten層を使い、最初の軸に沿った次元数は変えずに、4階のテンソルXを2階に変換する。
class SoftmaxRegression(d2l.Classifier):  #@save
    """The softmax regression model."""
    def __init__(self, num_outputs, lr):
        super().__init__()
        self.save_hyperparameters()
        self.net = nn.Sequential(nn.Flatten(),
                                 nn.LazyLinear(num_outputs))

    def forward(self, X):
        return self.net(X)