Thanks a lot.
For start, this seems to work.
class CTC(object):
    def __init__(self, pred_len, target_len, reduction='sum', blank=0, eos=26):
        self.pred_len = pred_len
        self.target_len = target_len
        self.criterion = torch.nn.CTCLoss(blank=blank, reduction=reduction)
        self.eos = eos

    def __call__(self, x, y):
        N = x.size()[1]
        x = x.log_softmax(2)
        input_lengths = torch.full(size=(N,), fill_value=self.pred_len, dtype=torch.long)
        target_lengths = torch.full(size=(N,), fill_value=self.target_len, dtype=torch.long)
        for i in range(N):
            target_lengths[i] = (y[i] == self.eos).nonzero()[0]
        return self.criterion(x, y, input_lengths, target_lengths)

As a best paractice, should the length correspond to the index of EOS or of the PAD after EOS?
Secondly what is a good percentage of input_sequence_length vs target_sequence_length?
Thank you!