1. the percent of excellent evaluation climb to 28% 2. The excellent part accounts for 28 percent of the questionnaire 3. 28% customer service evaluation is excellent
optimizer = torch.optim.SGD(net.parameters(), lr=0.2) #net.parameters():包含了神经网络的所有参数 lr:学习率(步长) loss_func = torch.nn.MSELoss() # this is for regression mean squared loss
那么在训练的时候
首先定义网络的输出位置prediction,真正计算损失loss
每次利用优化器清除掉网络中之前计算的梯度
然后开始运行反向传播算法
最后向正确方向迈出一步,用计算出的梯度再计算出新一轮的网络参数
1 2 3 4 5
prediction = net(x) # input x and predict based on x loss = loss_func(prediction, y) # must be (1. nn output, 2. target) optimizer.zero_grad() # clear gradients for next train loss.backward() # backpropagation, compute gradients optimizer.step() # apply gradients