1
$\begingroup$

PyTorch noobie here. I'm following an online tutorial and there's a simple model definition as follows:

class BagOfWordsClassifier(nn.Module):
    def __init__(self, vocab_size, hidden1, hidden2):
        super(BagOfWordsClassifier, self).__init__()
        self.fc1 = nn.Linear(vocab_size, hidden1)
        self.fc2 = nn.Linear(hidden1, hidden2)
        self.fc3 = nn.Linear(hidden2, 1)
        
    def forward(self, inputs):
        x = F.relu(self.fc1(inputs.squeeze(1).float()))
        x = F.relu(self.fc2(x))
        return self.fc3(x)

What I don't understand here is why do we need inputs.squeeze(1) at the forawrd function? When I take it out it gives me the following error:

"addmm_cuda" not implemented for 'Long'

If you need additional info don't hesitate to ask.

$\endgroup$
1
  • $\begingroup$ squeeze(1) removes the 1st dimension out of your input tensor (inputs). Can you provide the shape of your inputs tensor? $\endgroup$ Commented Dec 22, 2021 at 2:00

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Browse other questions tagged or ask your own question.