From f67ca05487227609ae2f4f5705d1d1baf6bfab27 Mon Sep 17 00:00:00 2001 From: JiangKX Date: Thu, 2 Jan 2020 17:17:50 +0800 Subject: [PATCH] =?UTF-8?q?3.3=20=E8=8A=82=E6=9C=80=E5=90=8E=E7=9A=84?= =?UTF-8?q?=E6=8D=9F=E5=A4=B1=E5=87=BD=E6=95=B0=E9=9C=80=E8=A6=81sum?= =?UTF-8?q?=E5=90=8E=E6=89=8D=E5=8F=AF=E4=BB=A5=E8=B0=83=E7=94=A8backward?= =?UTF-8?q?=E5=87=BD=E6=95=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- docs/chapter03_DL-basics/3.3_linear-regression-pytorch.md | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/docs/chapter03_DL-basics/3.3_linear-regression-pytorch.md b/docs/chapter03_DL-basics/3.3_linear-regression-pytorch.md index 9a608d096..8a79c6baa 100644 --- a/docs/chapter03_DL-basics/3.3_linear-regression-pytorch.md +++ b/docs/chapter03_DL-basics/3.3_linear-regression-pytorch.md @@ -48,7 +48,7 @@ tensor([[-2.7723, -0.6627], [ 0.2576, -0.2928], [ 2.0475, -2.7440], [ 1.0685, 1.1920], - [ 1.0996, 0.5106]]) + [ 1.0996, 0.5106]]) tensor([ 0.9066, -0.6247, 9.3383, 3.6537, 3.1283, 17.0213, 5.6953, 17.6279, 2.2809, 4.6661]) ``` @@ -68,7 +68,7 @@ class LinearNet(nn.Module): def forward(self, x): y = self.linear(x) return y - + net = LinearNet(num_inputs) print(net) # 使用print可以打印出网络的结构 ``` @@ -195,7 +195,7 @@ num_epochs = 3 for epoch in range(1, num_epochs + 1): for X, y in data_iter: output = net(X) - l = loss(output, y.view(-1, 1)) + l = loss(output, y.view(-1, 1)).sum() optimizer.zero_grad() # 梯度清零,等价于net.zero_grad() l.backward() optimizer.step()