RuntimeError: size mismatch, m1: [2304 x 200], m2: [100 x 1]

I have the following code:https://gist.github.com/vorlkets/f38c91aa52cb4e68976e1f638d251a85. When run I get RuntimeError: size mismatch, m1: [2304 x 200], m2: [100 x 1] at C:\w\1\s\windows\pytorch\aten\src\TH/generic/THTensorMath.cpp:136 error. Can someone tell me what’s going on? I am a newbie btw.

Can you share the full error log?

python hw2main.py
Using device: cpu

Traceback (most recent call last):
File “hw2main.py”, line 142, in
main()
File “hw2main.py”, line 72, in main
ratingOutput, categoryOutput = net(inputs, length)
File “C:\Users\Cliff\AppData\Local\Programs\Python\Python38\lib\site-packages\torch\nn\modules\module.py”, line 532, in call
result = self.forward(*input, **kwargs)
File “F:\Master of Information Technology at UNSW\COMP9444 Neural Networks and Deep Learning\Assignment\Assignment 2\hw2\student.py”, line 105, in forward
out_rating = torch.sigmoid(self.fc_rating(out_rating))
File “C:\Users\Cliff\AppData\Local\Programs\Python\Python38\lib\site-packages\torch\nn\modules\module.py”, line 532, in call
result = self.forward(*input, **kwargs)
File “C:\Users\Cliff\AppData\Local\Programs\Python\Python38\lib\site-packages\torch\nn\modules\linear.py”, line 87, in forward
return F.linear(input, self.weight, self.bias)
File “C:\Users\Cliff\AppData\Local\Programs\Python\Python38\lib\site-packages\torch\nn\functional.py”, line 1372, in linear
output = input.matmul(weight.t())
RuntimeError: size mismatch, m1: [60 x 200], m2: [100 x 1] at C:\w\1\s\windows\pytorch\aten\src\TH/generic/THTensorMath.cpp:136

I think this can be the problem:

        self.gru_rating = tnn.GRU(input_size = 50, hidden_size = 100, num_layers = 5, bidirectional = True)
        self.gru_buscat = tnn.GRU(input_size = 50, hidden_size = 100, num_layers = 5, bidirectional = True)
        self.fc_rating = tnn.Linear(100, 1)
        self.fc_buscat = tnn.Linear(100, 5)

Since, these are bidirectional gru layers, the output dimension would would be 200, which doesn’t match with the Linear layer input dimension. Try:

        self.fc_rating = tnn.Linear(200, 1)
        self.fc_buscat = tnn.Linear(200, 5)