I'm making a machine learning model to calculate game win rate on different character combination. I got error at last line using loss function. I think it's because the input is one-hot vector. The output of the model doesn't compatile with target data. Because target data is just boolean value, win or lose. Please give me advice to get through this problem. How to make one-hot input compatible with non one-hot?
'''for example, when the number of character is 4 and eahc team member is 2.
x_data is [ [[0,0,1,0], [0,1,0,0], [1,0,0,0,],[0,1,0,0]], [game2]...]
team A1, temaA2, temaB1 teamB2
'''
y_data = [[0], [0], [0], [1], [1], [1]] # team blue win: 1, lose : 0
x_train = torch.FloatTensor(x_data)
y_train = torch.FloatTensor(y_data)
class BinaryClassifier(nn.Module):
def __init__(self):
super(BinaryClassifier, self).__init__()
self.layer1 = nn.Sequential(
nn.Linear(in_features=num_characters, out_features=10, bias=True),
nn.ReLU(),
)
self.layer2 = nn.Sequential(
nn.Linear(in_features=10, out_features=1, bias=True),
nn.Sigmoid(),
)
def forward(self, x):
x = self.layer1(x)
x = self.layer2(x)
return torch.sigmoid(x)
model = BinaryClassifier()
optimizer = optim.SGD(model.parameters(), lr=1)
nb_epochs = 1000
for epoch in range(nb_epochs + 1):
hypothesis = model(x_train)
cost = nn.BCELoss(hypothesis, y_train)
# RuntimeError: bool value of Tensor with more than one value is ambiguous