ValueError Traceback (most recent call last)
<ipython-input-28-10509ec63b58> in <module>
11 start_time = time.time()
12
---> 13 train_loss, train_acc = train(model, train_iterator, optimizer, criterion)
14 valid_loss, valid_acc = evaluate(model, valid_iterator, criterion)
15
<ipython-input-25-ecea5e6d8ce8> in train(model, iterator, optimizer, criterion)
12 predictions = model(batch.t).squeeze(1)
13
---> 14 loss = criterion(predictions, batch.l)
15
16 acc = binary_accuracy(predictions, batch.l)
~\anaconda3\lib\site-packages\torch\nn\modules\module.py in __call__(self, *input, **kwargs)
530 result = self._slow_forward(*input, **kwargs)
531 else:
--> 532 result = self.forward(*input, **kwargs)
533 for hook in self._forward_hooks.values():
534 hook_result = hook(self, input, result)
~\anaconda3\lib\site-packages\torch\nn\modules\loss.py in forward(self, input, target)
599 self.weight,
600 pos_weight=self.pos_weight,
--> 601 reduction=self.reduction)
602
603
~\anaconda3\lib\site-packages\torch\nn\functional.py in binary_cross_entropy_with_logits(input, target, weight, size_average, reduce, reduction, pos_weight)
2122
2123 if not (target.size() == input.size()):
-> 2124 raise ValueError("Target size ({}) must be the same as input size ({})".format(target.size(), input.size()))
2125
2126 return torch.binary_cross_entropy_with_logits(input, target, weight, pos_weight, reduction_enum)
ValueError: Target size (torch.Size([26])) must be the same as input size (torch.Size([66]))
我正在训练CNN。在我自己的印尼数据集上进行情感分析。 This is my code。我使用了criteria = nn.BCEWithLogitsLoss ()
和optimizer = optim.RMSprop
。我不知道我需要在哪里进行更改以纠正错误。