Issue
I was following a youtube video and learning to make a chat bot, the teacher explained this step to make the training model, the code compiled perfectly for the teacher but im getting an error. What am i doing wrong?
for epoch in range(num_epochs):
for (words, labels) in train_loader:
words = words.to(device)
labels = labels.to(device, dtype=torch.int64)
outputs= model(words)
loss = criterion(outputs,labels)
optimizer.zero_grad()
loss.backward()
optimizer.step()
if(epoch +1) % 100 == 0:
print(f'epoch {epoch+1}/{epoch}, loss = {loss.item():.4f}')
print(f'epoch {epoch+1}/{epoch}, loss = {loss.item():.4f}')
NeuralNet:
class NeuralNet(nn.Module):
def __init__(self,input_size, hidden_size,num_classes):
super(NeuralNet,self).__init__()
self.l1 = nn.Linear(input_size,hidden_size)
self.l2 = nn.Linear(hidden_size,hidden_size)
self.l3 = nn.Linear(hidden_size,num_classes)
self.relu = nn.ReLU()
def forward(self,x):
out = self.l1(x)
out = self.relu(out)
out = self.l2(out)
out = self.relu(out)
out = self.l3
return out
Solution
The issue is with the NeuralNet
code specifically in the line:
out = self.l3
You are setting out to be the Linear layer instead of calling the linear layer on the data. Change it to
out = self.l3(out)
and it will work
Answered By - Tamir
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.