Hi, Thank you very much for your answer. I used the collate_fn functions in this way:
def collate_batch(batch):
    data = [item[0] for item in batch]
    data = pad_sequence(data, batch_first=True)
    targets = [item[1].unsqueeze_(0) for item in batch]
    targets = pad_sequence(targets, batch_first=True)
    return data, targets

is this correct?