title: How do I create padded batches in Tensorflow for tf.train.SequenceExample data using the DataSet API?
body: <p>For training an <strong>LSTM model</strong> in <strong>Tensorflow</strong>, I have structured my data into a <strong>tf.train.SequenceExample</strong> format and stored it into a <strong>TFRecord file</strong>. I would now like to use the new DataSet API to <strong>generate padded batches for training</strong>. In <a href="https://www.tensorflow.org/programmers_guide/datasets" rel="noreferrer">the documentation</a> there is an example for using padded_batch, but for my data I can't figure out what the value of <em>padded_shapes</em> should be.</p>
  
  <p>For reading the TFrecord file into the batches I have written the following Python code:</p>
  
  <pre><code>import math
  import tensorflow as tf
  import numpy as np
  import struct
  import sys
  import array
  
  if(len(sys.argv) != 2):
    print "Usage: createbatches.py [RFRecord file]"
    sys.exit(0)
  
  
  vectorSize = 40
  inFile = sys.argv[1]
  
  def parse_function_dataset(example_proto):
    sequence_features = {
        'inputs': tf.FixedLenSequenceFeature(shape=[vectorSize],
                                             dtype=tf.float32),
        'labels': tf.FixedLenSequenceFeature(shape=[],
                                             dtype=tf.int64)}
  
    _, sequence = tf.parse_single_sequence_example(example_proto, sequence_features=sequence_features)
  
    length = tf.shape(sequence['inputs'])[0]
    return sequence['inputs'], sequence['labels']
  
  sess = tf.InteractiveSession()
  
  filenames = tf.placeholder(tf.string, shape=[None])
  dataset = tf.contrib.data.TFRecordDataset(filenames)
  dataset = dataset.map(parse_function_dataset)
  # dataset = dataset.batch(1)
  dataset = dataset.padded_batch(4, padded_shapes=[None])
  iterator = dataset.make_initializable_iterator()
  
  batch = iterator.get_next()
  
  # Initialize `iterator` with training data.
  training_filenames = [inFile]
  sess.run(iterator.initializer, feed_dict={filenames: training_filenames})
  
  print(sess.run(batch))
  </code></pre>
  
  <p>The code works well if I use <code>dataset = dataset.batch(1)</code> (no padding needed in that case), but when I use the <code>padded_batch</code> variant, I get the following error:</p>
  
  <blockquote>
    <p>TypeError: If shallow structure is a sequence, input must also be a
    sequence. Input has type: .</p>
  </blockquote>
  
  <p>Can you help me figuring out what I should pass for the <em>padded_shapes</em> parameter?</p>
  
  <p>(I know there is lots of example code using threading and queues for this, but I'd rather use the new DataSet API for this project)</p>