Skip to content
New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

ValueError: Target size (torch.Size([8, 5])) must be the same as input size (torch.Size([8, 6])) #43

Open
Bamboomini opened this issue Apr 1, 2020 · 2 comments

Comments

@Bamboomini
Copy link

Hi
I run zhe code in my servers following the steps. And I met the error as follows:

4/01/2020 01:25:10 - INFO - root - ***** Running training *****
04/01/2020 01:25:10 - INFO - root - Num examples = 122532
04/01/2020 01:25:10 - INFO - root - Num Epochs = 6
04/01/2020 01:25:10 - INFO - root - Total train batch size (w. parallel, distributed & accumulation) = 8
04/01/2020 01:25:10 - INFO - root - Gradient Accumulation steps = 1
04/01/2020 01:25:10 - INFO - root - Total optimization steps = 91902
04/01/2020 01:25:22 - INFO - root - Epoch 1/6
Traceback (most recent call last):
File "run_bert.py", line 228, in
main()
File "run_bert.py", line 221, in main
run_train(args)
File "run_bert.py", line 129, in run_train
trainer.train(train_data=train_dataloader, valid_data=valid_dataloader)
File "/wangyu/bert-multi-laber/pybert/train/trainer.py", line 153, in train
train_log = self.train_epoch(train_data)
File "/wangyu/bert-multi-laber/pybert/train/trainer.py", line 98, in train_epoch
loss = self.criterion(output=logits,target=label_ids)
File "/wangyu/bert-multi-laber/pybert/train/losses.py", line 22, in call
loss = self.loss_fn(input = output,target = target)
File "/usr/local/lib/python3.6/dist-packages/torch/nn/modules/module.py", line 541, in call
result = self.forward(*input, **kwargs)
File "/usr/local/lib/python3.6/dist-packages/torch/nn/modules/loss.py", line 601, in forward
reduction=self.reduction)
File "/usr/local/lib/python3.6/dist-packages/torch/nn/functional.py", line 2112, in binary_cross_entropy_with_logits
raise ValueError("Target size ({}) must be the same as input size ({})".format(target.size(), input.size()))
ValueError: Target size (torch.Size([8, 5])) must be the same as input size (torch.Size([8, 6]))

I think it was wrong that I do something. But I do not know why? Hope to get your help!

Thank you very much!

@pvester
Copy link

pvester commented Jun 7, 2020

Same error for me but with [11, 5]... it looks like it cant handle if you dont have exactly 6 labels?

@AbdulRafay
Copy link

Please check your train.csv. Number of labels should exactly be same as specified in xlnet_processor.py and bert_processor.py. Also remove all cached files and .pkl files in dataset directory. Re-run bert or xlnet and your issue should be resolved.

# for free to join this conversation on GitHub. Already have an account? # to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants