I’m new to using PyTorch for RNNs and loving it so far. Nonetheless, my model is only training on individual sequences (i.e., batch size = 1).
As I move towards training in batch, I’ve been going through many different implementations for padding and batching the tensors, such as:
- https://medium.com/@sonicboom8/sentiment-analysis-with-variable-length-sequences-in-pytorch-6241635ae130
- https://github.com/hunkim/PyTorchZeroToAll/blob/master/13_2_rnn_classification.py
I also noticed PyTorch has pad_sequence
which seems useful, though it does not return a PackedSequence
object.
Is there a PyTorch recommended way to do padding and batching?