xor by pytorch

Solutions on MaxInterview for xor by pytorch by the best coders in the world

showing results for - "xor by pytorch"
María
22 Jun 2020
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
similar questions
queries leading to this page
xor by pytorch