Training a BERT model using PyTorch transformers (following the tutorial here).
Following statement in the tutorial
loss = model(b_input_ids, token_type_ids=None, attention_mask=b_input_mask, labels=b_labels)
leads to
TypeError: forward() got an unexpected keyword argument 'labels'
Here is the full error,
TypeError Traceback (most recent call last)
<ipython-input-53-56aa2f57dcaf> in <module>
26 optimizer.zero_grad()
27 # Forward pass
---> 28 loss = model(b_input_ids, token_type_ids=None, attention_mask=b_input_mask, labels=b_labels)
29 train_loss_set.append(loss.item())
30 # Backward pass
~/anaconda3/envs/systreviewclassifi/lib/python3.6/site-packages/torch/nn/modules/module.py in __call__(self, *input, **kwargs)
539 result = self._slow_forward(*input, **kwargs)
540 else:
--> 541 result = self.forward(*input, **kwargs)
542 for hook in self._forward_hooks.values():
543 hook_result = hook(self, input, result)
TypeError: forward() got an unexpected keyword argument 'labels'
I cant seem to figure out what kind of argument the forward() function expects.
There is a similar problem here, but I still do not get what the solution is.
System information:
- OS: Ubuntu 16.04 LTS
- Python version: 3.6.x
- Torch version: 1.3.0
- Torch Vision version: 0.4.1
- PyTorch transformers version: 1.2.0
所有评论(0)