Could you please help how to solve this problem. Basically, I'm trying to get into Pytorch tensor function data that is vector not scalar. X1 and X2 are basically columns in CSV file that contains many strings. How to kind of iterate through every single data from x1 and x2 and not just trying to parse the whole vector. I'm a newbie at Python and Pytorch as well.
import torch
import random
import pandas
data = pandas.read_csv('train/train.tsv', sep='\t')
learningrate = torch.tensor(0.01)
W = torch.rand([2, 2], dtype=torch.float, requires_grad=True)
b = torch.rand(2, dtype=torch.float, requires_grad=True)
U = torch.rand(2, dtype=torch.float, requires_grad=True)
c = torch.rand(1, dtype=torch.float, requires_grad=True)
def get_item():
x1 = torch.tensor(data['Powierzchnia w m2'],
dtype=torch.float, requires_grad=True)
x2 = torch.tensor(data['Liczba pokoi'],
dtype=torch.float, requires_grad=True)
x = torch.tensor([x1, x2], dtype=torch.float)
yexpected = torch.tensor(data['cena'].values, dtype=torch.float)
return x, yexpected
for _ in range(100000):
x, yexpected = get_item()
h = torch.sigmoid(W @ x+b)
print(x)
print(yexpected)
print(h)
y = torch.sigmoid(U@h+c)
loss = (y-yexpected)**2
print(loss)
loss.backward()
with torch.no_grad():
W -= learningrate * W.grad
b -= learningrate * b.grad
c -= learningrate * c.grad
U -= learningrate * U.grad
b.grad.zero_()
W.grad.zero_()
c.grad.zero_()
U.grad.zero_()