Zero Padding for NLP

I am working on a sequence labeling problem (named entity recognition). As each sentence has different length, I use “pack_padded_sequence” to feed my BiLSTM. However, I need to zero padding the word2vec matrix first (the third dimension, batch dimension, has different value, so I cannot turn this into Tensor).

For now, I make a all-zero matrix and assign the word2vec matrix’s value to it. And the time cost is a little bit high.

I wonder is there any function in Pytorch or some method can help me?