AI-writer_Data2Doc icon indicating copy to clipboard operation
AI-writer_Data2Doc copied to clipboard

TypeError: forward() takes 3 positional arguments but 5 were given

Open scut-salmon opened this issue 6 years ago • 4 comments

When I try to predict the word using the model(BiLSTM) I generate by myself, it occurs the following error:

File "train.py", line 662, in predictwords encoder_hidden, encoder_hiddens = encoder(rt, re, rm, init_hidden) File "/home/zhangzhenchang/anaconda3/lib/python3.6/site-packages/torch/nn/modules/module.py", line 491, in call result = self.forward(*input, **kwargs) TypeError: forward() takes 3 positional arguments but 5 were given

What's the function of "encoder" mean, how can I fix this problem. Thanks, Zhang

scut-salmon avatar Jul 13 '18 00:07 scut-salmon

Traceback (most recent call last): File "E:/audio data/AI-writer_Data2Doc-master/train/small_evaluate.py", line 52, in for idx, text in enumerate(text_generator): File "E:\audio data\AI-writer_Data2Doc-master\train\train.py", line 776, in evaluate beam_size) File "E:\audio data\AI-writer_Data2Doc-master\train\train.py", line 670, in predictwords out, encoder_hidden = encoder(rt, re, rm, encoder_hidden) File "D:\anaconda\envs\pytorch\lib\site-packages\torch\nn\modules\module.py", line 477, in call result = self.forward(*input, **kwargs) TypeError: forward() takes 3 positional arguments but 5 were given

novegetate avatar Mar 29 '19 13:03 novegetate

man, you gotta post your code, not just the error itself.

Yonggie avatar Jul 18 '19 01:07 Yonggie

Traceback (most recent call last): File "E:/audio data/AI-writer_Data2Doc-master/train/small_evaluate.py", line 52, in for idx, text in enumerate(text_generator): File "E:\audio data\AI-writer_Data2Doc-master\train\train.py", line 776, in evaluate beam_size) File "E:\audio data\AI-writer_Data2Doc-master\train\train.py", line 670, in predictwords out, encoder_hidden = encoder(rt, re, rm, encoder_hidden) File "D:\anaconda\envs\pytorch\lib\site-packages\torch\nn\modules\module.py", line 477, in call result = self.forward(*input, **kwargs) TypeError: forward() takes 3 positional arguments but 5 were given

Hi Novegetate, have you solved the problem? I met the same issue. I am thinking whether it is because of the difference of pytorch's version.

BlackFeetMouse avatar Mar 16 '20 08:03 BlackFeetMouse

I found the solution. You should combine rt,re, rm into one dictionary inputs like inputs = {'rt': rt, 're': re, 'rm': rm} Then you only need input three arguments instead of five.

BlackFeetMouse avatar Mar 17 '20 06:03 BlackFeetMouse