title: How to use return_sequences option and TimeDistributed layer in Keras?
body: <p>I have a dialog corpus like below. And I want to implement a LSTM model which predicts a system action. The system action is described as a bit vector. And a user input is calculated as a word-embedding which is also a bit vector.</p>
  
  <pre><code>t1: user: "Do you know an apple?", system: "no"(action=2)
  t2: user: "xxxxxx", system: "yyyy" (action=0)
  t3: user: "aaaaaa", system: "bbbb" (action=5)
  </code></pre>
  
  <p>So what I want to realize is "many to many (2)" model. When my model receives a user input, it must output a system action.
  <a href="https://i.stack.imgur.com/13opm.jpg" rel="noreferrer"><img src="https://i.stack.imgur.com/13opm.jpg" alt="enter image description here"></a>
  But I cannot understand <code>return_sequences</code> option and <code>TimeDistributed</code> layer after LSTM. To realize "many-to-many (2)", <code>return_sequences==True</code> and adding a <code>TimeDistributed</code> after LSTMs are required? I appreciate if you would give more description of them.</p>
  
  <blockquote>
    <p><strong>return_sequences</strong>: Boolean. Whether to return the last output in the output sequence, or the full sequence.</p>
    
    <p><strong>TimeDistributed</strong>: This wrapper allows to apply a layer to every temporal slice of an input.</p>
  </blockquote>
  
  <h3>Updated 2017/03/13 17:40</h3>
  
  <p>I think I could understand the <code>return_sequence</code> option. But I am not still sure about <code>TimeDistributed</code>. If I add a <code>TimeDistributed</code> after LSTMs, is the model the same as "my many-to-many(2)" below? So I think Dense layers are applied for each output.
  <a href="https://i.stack.imgur.com/DiPyQ.jpg" rel="noreferrer"><img src="https://i.stack.imgur.com/DiPyQ.jpg" alt="enter image description here"></a></p>