Skip to content

Instantly share code, notes, and snippets.

View kaituoxu's full-sized avatar

Kaituo XU 许开拓 kaituoxu

View GitHub Profile
@MaximumEntropy
MaximumEntropy / padded_rnn.py
Last active July 23, 2018 12:46
Padded RNN PyTorch
import torch
import torch.nn as nn
from torch.autograd import Variable
from torch.nn.utils.rnn import pad_packed_sequence, pack_padded_sequence
x = Variable(torch.randn(10, 20, 30)).cuda()
lens = range(10)
x = pack_padded_sequence(x, lens[::-1], batch_first=True)