Skip to content

Instantly share code, notes, and snippets.

@jtourille
jtourille / pad_packed_demo.py
Created February 2, 2018 10:09 — forked from Tushar-N/pad_packed_demo.py
How to use pad_packed_sequence in pytorch
import torch
import torch.nn as nn
from torch.autograd import Variable
from torch.nn.utils.rnn import pack_padded_sequence, pad_packed_sequence
import torch.nn.functional as F
import numpy as np
import itertools
def flatten(l):
return list(itertools.chain.from_iterable(l))