Thanks, this makes loss function running. But it returns Inf. I think this may be caused by my usage, not sure if I am passing correct parameters.
loss = loss_function(tag_score, target, tag_score_sizes, target_sizes)

shapes of parameters are as follows:
tag_score: (4, 2, 64)        seq_len, batch_size, character_probability
target: (8, )                      target labels stretched as 1D tensor, actual data: [5,12,58,62,10,52,50,15]
tag_score_sizes:  (2,)      actual data is [4, 4]
target_sizes: (2, )            actual data is [4, 4]

I have checked tag_score by summing up the last dimension. The results are 1 denoting they are probabilities.