Answers.Body: <p>The hidden and carry states of an LSTM contain the current 'embedding' of the past data that has been passed through the cell. The hidden state is also taken as output at each timestep. If, as you are writing, make the hidden state of size 1, then indeed it will not remember much of the past.</p>
  <p>However, what is more common, is to have a larger number of hidden neurons in the LSTM and then connect a fully connected dense layer to the output, which takes in this hidden state (embedding) and transforms it to a single output node. That way you can remember a lot of data, but still have a 1 neuron output.</p>
  
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2023-02-24T19:35:01.470Z
Answers.LastActivityDate: 2023-02-24T19:35:01.470Z
Answers.UserDisplayName: Robin van Hoorn
Body: <p>I'm new to LSTMs, and I'm trying to do a basic timeseries prediction using stock prices. However, I'm a bit confused as to how the LSTM is supposed to remember outputs from previous timesteps when it has a many to one shape.</p>
  <p>For example, let's say we're at timestep <code>n</code>, and the following timeseries is part of my input:</p>
  <pre><code>[[100, 10], [300, 30], [200, 20]]
  </code></pre>
  <p>And it maps to some output, let's say <code>1</code></p>
  <p>Great. But let's say at timestep <code>n - 1</code>, when the input was just <code>[[100, 10], [300, 30]]</code>, the output was <code>0</code>. <strong>How will the LSTM know this?</strong></p>
  <p>Should I include the same data at different timesteps (using something like zero padding) with the corresponding output? Or am I totally misunderstanding something about how LSTMs work?</p>
  
Tags: <neural-networks><recurrent-neural-networks><long-short-term-memory><time-series><sequence-modeling>
Title: Many To One LSTM - Can I Use the Same Sequence as Input from Previous Timesteps?
UserDisplayName: Krusty the Clown
ThreadText: # Many To One LSTM - Can I Use the Same Sequence as Input from Previous Timesteps?
  
  (Asked by: username_0 on 2023-02-24)
  
  I'm new to LSTMs, and I'm trying to do a basic timeseries prediction using stock prices. However, I'm a bit confused as to how the LSTM is supposed to remember outputs from previous timesteps when it has a many to one shape.
  
  For example, let's say we're at timestep `n`, and the following timeseries is part of my input:
  
  ```
  [[100, 10], [300, 30], [200, 20]]
  
  ```
  
  And it maps to some output, let's say `1`
  
  Great. But let's say at timestep `n - 1`, when the input was just `[[100, 10], [300, 30]]`, the output was `0`. **How will the LSTM know this?**
  
  Should I include the same data at different timesteps (using something like zero padding) with the corresponding output? Or am I totally misunderstanding something about how LSTMs work?
  
  **Tags:** neural-networks, recurrent-neural-networks, long-short-term-memory, time-series, sequence-modeling
  
  
  ---
  
  ## 1 answers
  
  ### Answer by username_1 on 2023-02-24. Score: 0
  
  The hidden and carry states of an LSTM contain the current 'embedding' of the past data that has been passed through the cell. The hidden state is also taken as output at each timestep. If, as you are writing, make the hidden state of size 1, then indeed it will not remember much of the past.
  
  However, what is more common, is to have a larger number of hidden neurons in the LSTM and then connect a fully connected dense layer to the output, which takes in this hidden state (embedding) and transforms it to a single output node. That way you can remember a lot of data, but still have a 1 neuron output.
  
  
  ---
  
  