Stack Exchange
pytorch ctc_loss why return tensor(inf, grad_fn=<MeanBackward0>)

torch.version : 1.10.1
os: windows 10

import torch
import torch.nn as nn

ctc_loss = nn.CTCLoss()
probs = torch.tensor([
    [
        [1.0, 2, 3, 4, 5],
        [3.0, 4, 5, 6, 0],
    ],
])
probs_size = torch.tensor([1, 1])


targets = torch.tensor([
    [1.0, 2, 3, 4, 5],
    [3.0, 4, 5, 6, 0],
])
target_lengths = torch.tensor([5, 4])

probs = probs.log_softmax(1).requires_grad_()
loss = ctc_loss(probs, targets, probs_size, target_lengths)
print(f"{loss=}")


loss=tensor(inf, grad_fn=MeanBackward0)

Hello everyone,
I tried to write a small demo of ctc_loss,
My probs prediction data is exactly the same as the targets label data.
In theory, loss == 0
But why the return value of pytorch ctc_loss will be inf (infinite) ??
What is the correct way to use it?
