Hi.
I’m newbie at Machine learning and PyTorch.
I want to know how to work one-hot encoding, so wrote extremely simple example.
import torch
from torch import nn, optim
from torch.utils.data import TensorDataset, DataLoader

# Only 2 category
X_train = []
y_train = []
for i in range(1000):
    if i % 2 == 0 :
        X_train.append([1,0])
        y_train.append(-10.0)
    else :
        X_train.append([0,1])
        y_train.append(+10.0)
        
X_train = torch.Tensor(X_train)
y_train = torch.Tensor(y_train)

# 
ds_train = TensorDataset(X_train, y_train)
loader_train = DataLoader(ds_train, batch_size=16, shuffle=True, drop_last=True)

# network
net = nn.Sequential(nn.Linear(2,1))

# 
optimizer = optim.Adam(net.parameters())
loss_fn = nn.L1Loss()

# loop
losses = []
net.train()
lastTime = time.time()
for epoc in range(10):
    for data, target in loader_train:
        y_pred = net(data)
        loss = loss_fn(target,y_pred)
        optimizer.zero_grad()
        loss.backward()
        optimizer.step()
        losses.append(loss.data)

%matplotlib inline
from matplotlib import pyplot as plt
plt.plot(losses[:])

But this optimizer predict noting, always outputs near zero.
What’s wrong with this?
Thanks