Is there an official way to implement bidirectional AWD LSTM? I used the following code but the error pops out.
config = awd_lstm_lm_config.copy()
config['bidir'] = True
learn = language_model_learner(data_lm, AWD_LSTM, drop_mult=0.3, model_dir=".", config=config, pretrained=False)
learn.lr_find()
learn.recorder.plot(skip_end=15)
The error said the size should be double, does that mean I have to modify my code during creation of databunch?
/opt/conda/lib/python3.6/site-packages/torch/nn/modules/module.py in __call__(self, *input, **kwargs)
487 result = self._slow_forward(*input, **kwargs)
488 else:
--> 489 result = self.forward(*input, **kwargs)
490 for hook in self._forward_hooks.values():
491 hook_result = hook(self, input, result)
/opt/conda/lib/python3.6/site-packages/torch/nn/modules/container.py in forward(self, input)
90 def forward(self, input):
91 for module in self._modules.values():
---> 92 input = module(input)
93 return input
94
/opt/conda/lib/python3.6/site-packages/torch/nn/modules/module.py in __call__(self, *input, **kwargs)
487 result = self._slow_forward(*input, **kwargs)
488 else:
--> 489 result = self.forward(*input, **kwargs)
490 for hook in self._forward_hooks.values():
491 hook_result = hook(self, input, result)
/opt/conda/lib/python3.6/site-packages/fastai/text/models/awd_lstm.py in forward(self, input, from_embeddings)
112 new_hidden,raw_outputs,outputs = [],[],[]
113 for l, (rnn,hid_dp) in enumerate(zip(self.rnns, self.hidden_dps)):
--> 114 raw_output, new_h = rnn(raw_output, self.hidden[l])
115 new_hidden.append(new_h)
116 raw_outputs.append(raw_output)
/opt/conda/lib/python3.6/site-packages/torch/nn/modules/module.py in __call__(self, *input, **kwargs)
487 result = self._slow_forward(*input, **kwargs)
488 else:
--> 489 result = self.forward(*input, **kwargs)
490 for hook in self._forward_hooks.values():
491 hook_result = hook(self, input, result)
/opt/conda/lib/python3.6/site-packages/fastai/text/models/awd_lstm.py in forward(self, *args)
47 #To avoid the warning that comes because the weights aren't flattened.
48 warnings.simplefilter("ignore")
---> 49 return self.module.forward(*args)
50
51 def reset(self):
/opt/conda/lib/python3.6/site-packages/torch/nn/modules/rnn.py in forward(self, input, hx)
173 hx = (hx, hx)
174
--> 175 self.check_forward_args(input, hx, batch_sizes)
176 _impl = _rnn_impls[self.mode]
177 if batch_sizes is None:
/opt/conda/lib/python3.6/site-packages/torch/nn/modules/rnn.py in check_forward_args(self, input, hidden, batch_sizes)
150 if self.mode == 'LSTM':
151 check_hidden_size(hidden[0], expected_hidden_size,
--> 152 'Expected hidden[0] size {}, got {}')
153 check_hidden_size(hidden[1], expected_hidden_size,
154 'Expected hidden[1] size {}, got {}')
/opt/conda/lib/python3.6/site-packages/torch/nn/modules/rnn.py in check_hidden_size(hx, expected_hidden_size, msg)
146 def check_hidden_size(hx, expected_hidden_size, msg='Expected hidden size {}, got {}'):
147 if tuple(hx.size()) != expected_hidden_size:
--> 148 raise RuntimeError(msg.format(expected_hidden_size, tuple(hx.size())))
149
150 if self.mode == 'LSTM':
RuntimeError: Expected hidden[0] size (2, 32, 575), got (1, 32, 575)