def linear_train(train_data, train_target, n_epochs=200):
for _ in range(n_epochs):
# Get the result of the forward pass.
output = linear_forward(train_data)
# Calculate the loss between the training data and target data.
loss = F.mean_squared_error(train_target, output)
# Zero all gradients before updating them.
linear_function.zerograds()
# Calculate and update all gradients.
loss.backward()
# Use the optmizer to move all parameters of the network
# to values which will reduce the loss.
optimizer.update()
评论列表
文章目录