How to make the data of each batch have different sizes

libtorch 1.6.0 win10 x64 .

I wrote an OCR model of the dataset.The word is encoded with different lengths as the label input.How to make the data of each batch have different sizes?
example:
data:123.png datasize:[batchsize,3,180,32] ,label: 123,labelsize:[batchsize,3]
data:3234.png datasize:[batchsize,3,180,32] ,label: 3234,lablesize:[batchsize,4]
[batchsize,3]!=[batchsize,4]
The dataset in Pytorch supports different sizes, but libtorch does not.