in iep/models/seq2seq.py [0:0]
def before_rnn(self, x, replace=0):
# TODO: Use PackedSequence instead of manually plucking out the last
# non-NULL entry of each sequence; it is cleaner and more efficient.
N, T = x.size()
idx = torch.LongTensor(N).fill_(T - 1)
# Find the last non-null element in each sequence. Is there a clean
# way to do this?
x_cpu = x.cpu()
for i in range(N):
for t in range(T - 1):
if x_cpu.data[i, t] != self.NULL and x_cpu.data[i, t + 1] == self.NULL:
idx[i] = t
break
idx = idx.type_as(x.data)
x[x.data == self.NULL] = replace
return x, Variable(idx)