You can specify a certain index to represent the ‘zero padding’ with torch.nn.Embedding(padding_idx=,…). Then, for each sentence of size less than max_len, create a list in the size of (max_len-sentence size) , of which its elements are actually the paddind_idx index. Then add this list to the already existing list of word indices representing the sentence.