Я получаю эту ошибку, когда запускаю модель, которую использую. Это код, который, кажется, вызывает проблему?
def forward(self, b, xc, xw, lens):
self.hidden = self.init_state(b)
x = self.embed(xc, xw)
x = nn.utils.rnn.pack_padded_sequence(x, lens, batch_first = True)
h, _ = self.rnn(x, self.hidden)
h, _ = nn.utils.rnn.pad_packed_sequence(h, batch_first = True)
return h
Вот трассировка
Traceback (most recent call last):
File "train.py", line 59, in <module>
train()
File "train.py", line 44, in train
loss = model(xc, xw, y0) # forward pass and compute loss
File "/Library/Frameworks/Python.framework/Versions/3.8/lib/python3.8/site-packages/torch/nn/modules/module.py", line 550, in __call__
result = self.forward(*input, **kwargs)
File "/Users/sidu/Downloads/rnn-encoder-decoder-pytorch/model.py", line 18, in forward
self.dec.hs = self.enc(b, xc, xw, lens)
File "/Library/Frameworks/Python.framework/Versions/3.8/lib/python3.8/site-packages/torch/nn/modules/module.py", line 550, in __call__
result = self.forward(*input, **kwargs)
File "/Users/sidu/Downloads/rnn-encoder-decoder-pytorch/model.py", line 64, in forward
h, _ = self.rnn(x, self.hidden)
File "/Library/Frameworks/Python.framework/Versions/3.8/lib/python3.8/site-packages/torch/nn/modules/module.py", line 550, in __call__
result = self.forward(*input, **kwargs)
File "/Library/Frameworks/Python.framework/Versions/3.8/lib/python3.8/site-packages/torch/nn/modules/rnn.py", line 567, in forward
self.check_forward_args(input, hx, batch_sizes)
File "/Library/Frameworks/Python.framework/Versions/3.8/lib/python3.8/site-packages/torch/nn/modules/rnn.py", line 522, in check_forward_args
self.check_hidden_size(hidden[0], expected_hidden_size,
File "/Library/Frameworks/Python.framework/Versions/3.8/lib/python3.8/site-packages/torch/nn/modules/rnn.py", line 186, in check_hidden_size
if hx.size() != expected_hidden_size:
AttributeError: 'builtin_function_or_method' object has no attribute 'size'
Я не могу понять, откуда эта ошибка, вероятно из-за моей неопытности в этом деле. Кто-нибудь может увидеть проблему? Дайте мне знать, если мне нужно что-то еще