1epochs = 2001
2steps = X.size(0)
3for i in range(epochs):
4 for j in range(steps):
5 data_point = np.random.randint(X.size(0))
6 x_var = Variable(X[data_point], requires_grad=False)
7 y_var = Variable(Y[data_point], requires_grad=False)
8
9 optimizer.zero_grad()
10 y_hat = model(x_var)
11 loss = loss_func.forward(y_hat, y_var)
12 loss.backward()
13 optimizer.step()
14
15 if i % 500 == 0:
16 print "Epoch: {0}, Loss: {1}, ".format(i, loss.data.numpy()[0])
17