I am working with the torchtext.datasets datasets. I need to do classification using a recurrence network.
NGRAMS = 1
BATCH_SIZE = 20
train_dataset, test_dataset = text_classification.DATASETS['AG_NEWS'](
    root='./.data', ngrams=NGRAMS, vocab=None)

and the dataLoader
data = DataLoader(train_data, batch_size=BATCH_SIZE, shuffle=True,collate_fn=batching)

create batch function
def batching(batch):
    #print(batch.shape)
    label = torch.tensor([entry[0] for entry in batch])
    text = [entry[1] for entry in batch]
    textLength = torch.tensor([entry.shape for entry in text])
    max_text_length = torch.max(textLength)
    newtext = [torch.cat((torch.zeros([max_text_length-textLength[i]], dtype=torch.long), text[i]),0) for i in range(len(text))]
    new_textLength = torch.tensor([entry.shape for entry in newtext])
    text2=torch.stack(newtext)  #the padded tensor
    
    return text2, label

What I have in the function above is to ensure all the sentences in the batch are of equal lengths by padding them by 0(to the left).

Am I doing the right thing?
Do I need to add 0 to the vocabulary? How I add 0 to the vocabulary?  Since the vocabulary is created automatically?
Do I add start and end of sentence token? How do I add to the vocabulary?
Lastly, do I need an offset?