Hello all,
I am working with Pytorch 1.0.1 and I am using the CTC loss of PyTorch.
The code looks like the following one (I am working on GPU):
criterion = torch.nn.CTCLoss()
outs, (h,c) = lstm(input) # input is padded with zeros
outs = torch.nn.functional.log_softmax(outs, dim=2)
loss = criterion(outs.permute(1,0,2).contiguous(), y.to(device), lengths_input.to(device), lengths_target.to(device) )

I am permuting outs (FloatTensor) because I am working batch_first (N, T, C) while CTC requires (T, N, C).
y contains the concatenation of the labels for each batch and is a LongTensor.
lengths_input and lengths_target (LongTensors) have 1 dimension with N elements each representing the length of each input sequence in the batch and each target sequence in the labels.
I am working with variable length sequences so the values of lengths_input may be different (and they often are) from one another.
This setting causes the loss to become nan after few iterations.
However, if I fill lengths_input with all equal sizes (i.e. outs.size(1)) the loss decreases fine.
This is the only change I made from one version to the other.
I was previously using PyTorch 1.0.0, then I read about this fixed bug 15 and I updated to 1.0.1 but nothing changed.
As I wrote in the comment I am using padded inputs to obtain a single batch-tensor. Is this not compatible with variable sized lengths in the CTC loss? Am I missing something?
Thank you!