optimizer.zero_grad()
# get the output from the model
output, h = mynet(specs, h)
print(output.size())
output = F.log_softmax(output, dim=2)
output = output.transpose(0,1)
# calculate the loss and perform backprop
loss = criterion(output, labels, input_lengths, label_lengths)
loss.backward()
# `clip_grad_norm` helps prevent the exploding gradient problem in RNNs / LSTMs.
nn.utils.clip_grad_norm_(mynet.parameters(), clip)
optimizer.step()
---------------------------------------------------------------------------
RuntimeError Traceback (most recent call last)
<ipython-input-132-fd3f6611addd> in <module>
42 output = output.transpose(0,1)
43 # calculate the loss and perform backprop
---> 44 loss = criterion(output, labels, input_lengths, label_lengths)
45 loss.backward()
46 # `clip_grad_norm` helps prevent the exploding gradient problem in RNNs / LSTMs.
/opt/conda/lib/python3.7/site-packages/torch/nn/modules/module.py in __call__(self, *input, **kwargs)
548 result = self._slow_forward(*input, **kwargs)
549 else:
--> 550 result = self.forward(*input, **kwargs)
551 for hook in self._forward_hooks.values():
552 hook_result = hook(self, input, result)
/opt/conda/lib/python3.7/site-packages/torch/nn/modules/loss.py in forward(self, log_probs, targets, input_lengths, target_lengths)
1309 def forward(self, log_probs, targets, input_lengths, target_lengths):
1310 return F.ctc_loss(log_probs, targets, input_lengths, target_lengths, self.blank, self.reduction,
-> 1311 self.zero_infinity)
1312
1313 # TODO: L1HingeEmbeddingCriterion
/opt/conda/lib/python3.7/site-packages/torch/nn/functional.py in ctc_loss(log_probs, targets, input_lengths, target_lengths, blank, reduction, zero_infinity)
2050 """
2051 return torch.ctc_loss(log_probs, targets, input_lengths, target_lengths, blank, _Reduction.get_enum(reduction),
-> 2052 zero_infinity)
2053
2054
RuntimeError: blank must be in label range
criterion = nn.CTCLoss(blank=28, zero_infinity=False)