Representing time sequence input/output in tensorflow
<p>I've been working through the TensorFlow documentation (still learning), and I can't figure out how to represent input/output sequence data.  My inputs are a sequences of 20 8-entry vectors, making a 8x20xN matrix, where N is the number of instances.  I'd like to eventually pass these through an LSTM for sequence to sequence learning.  I know I need a 3D vector, but I'm unsure which dimensions are which. </p>

<p>RTFMs with pointers to the correct documentation greatly appreciated.  I feel like this is obvious and I'm just missing it. </p>

<p>As described in the excellent blog post by <a href="http://www.wildml.com/2016/08/rnns-in-tensorflow-a-practical-guide-and-undocumented-features/" rel="nofollow">WildML</a>, the proper way is to save your example in a TFRecord using the formate <code>tf.SequenceExample()</code>. Using TFRecords for this provides the following advantages: </p>

<ul>
<li>You can split your data in to many files and load them each on a different GPU.</li>
<li>You can use Tensorflow utilities for loading the data (for example using <code>Queues</code> to load you data on demand.</li>
<li>Your model code will be separate from your dataset processing (this is a good habit to have).</li>
<li>You can bring new data to your model just by putting it into this format.</li>
</ul>

<p>TFRecords uses <code>protobuf</code> or protocol buffers as a way to format your data. The documentation of which can be found <a href="https://developers.google.com/protocol-buffers/" rel="nofollow">here</a>. The basic idea is you have a format for your data (in this case in the format of tf.SequenceExample) save it to a TFRecord and load it using the same data definition. Code for this pattern can be found at <a href="https://github.com/dennybritz/tf-rnn/blob/master/sequence_example.ipynb" rel="nofollow">this</a> ipython notebook.</p>

<p>As my answer is mostly summarizing the WildML blog post on this topic, I suggest you check that out, again found <a href="http://www.wildml.com/2016/08/rnns-in-tensorflow-a-practical-guide-and-undocumented-features/" rel="nofollow">here</a>.</p>

python tensorflow