ValueError Traceback (most recent call last)
Cell In[14], line 17
14 loss_avg = 0
16 for epoch in range(1, n_epochs + 1):
---> 17 loss = train(*random_training_set())
18 loss_avg += loss
20 if epoch % print_every == 0:
Cell In[13], line 8, in train(inp, target)
6 for c in range(chunk_len):
7 output, hidden = decoder(inp[c], hidden)
----> 8 loss += criterion(output, target[c])
10 loss.backward()
11 decoder_optimizer.step()
File /Library/Frameworks/Python.framework/Versions/3.12/lib/python3.12/site-packages/torch/nn/modules/module.py:1736, in Module._wrapped_call_impl(self, *args, **kwargs)
1734 return self._compiled_call_impl(*args, **kwargs) # type: ignore[misc]
1735 else:
-> 1736 return self._call_impl(*args, **kwargs)
File /Library/Frameworks/Python.framework/Versions/3.12/lib/python3.12/site-packages/torch/nn/modules/module.py:1747, in Module._call_impl(self, *args, **kwargs)
1742 # If we don't have any hooks, we want to skip the rest of the logic in
1743 # this function, and just call forward.
1744 if not (self._backward_hooks or self._backward_pre_hooks or self._forward_hooks or self._forward_pre_hooks
1745 or _global_backward_pre_hooks or _global_backward_hooks
1746 or _global_forward_hooks or _global_forward_pre_hooks):
-> 1747 return forward_call(*args, **kwargs)
1749 result = None
1750 called_always_called_hooks = set()
File /Library/Frameworks/Python.framework/Versions/3.12/lib/python3.12/site-packages/torch/nn/modules/loss.py:1293, in CrossEntropyLoss.forward(self, input, target)
1292 def forward(self, input: Tensor, target: Tensor) -> Tensor:
-> 1293 return F.cross_entropy(
1294 input,
1295 target,
1296 weight=self.weight,
1297 ignore_index=self.ignore_index,
1298 reduction=self.reduction,
1299 label_smoothing=self.label_smoothing,
1300 )
File /Library/Frameworks/Python.framework/Versions/3.12/lib/python3.12/site-packages/torch/nn/functional.py:3479, in cross_entropy(input, target, weight, size_average, ignore_index, reduce, reduction, label_smoothing)
3477 if size_average is not None or reduce is not None:
3478 reduction = _Reduction.legacy_get_string(size_average, reduce)
-> 3479 return torch._C._nn.cross_entropy_loss(
3480 input,
3481 target,
3482 weight,
3483 _Reduction.get_enum(reduction),
3484 ignore_index,
3485 label_smoothing,
3486 )
ValueError: Expected input batch_size (1) to match target batch_size (0).