Answers.Body: <p>One of the essential pre-processing we do on the corpus involves treating the variable-length sentences to a fixed length. There are various ways in which we can do this:</p>
  <h1>Truncate</h1>
  <hr />
  <p>This involves reducing the length of all the sentences to the length of the shortest sentence in the corpus. This is generally not done as it reduces the amount of information that we can learn from the corpus. This image shows pre sequence truncation, where we remove from the back to make the sentences of the same length.</p>
  <p><a href="https://i.sstatic.net/PBgbz.png" rel="nofollow noreferrer"><img src="https://i.sstatic.net/PBgbz.png" alt="Truncate Example" /></a></p>
  <h1>Padding</h1>
  <hr />
  <p>This is the most preferred method when it comes to handling the problem of variable length sentences. In this approach, we increase the size of each vector to the longest sentence in the corpus. There are two ways to this:</p>
  <ul>
  <li><strong>Post-Padding</strong>: Adding zeroes in the ending</li>
  <li><strong>Pre-Padding</strong>: Adding zeroes in the beginning</li>
  </ul>
  <h1>References</h1>
  <hr />
  <p><a href="https://arxiv.org/pdf/1903.07288.pdf" rel="nofollow noreferrer">Effect of Padding on LSTMs and CNNs</a> by Dwarampudi Mahidhar Reddy and N V Subba Reddy, et al.</p>
  
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2020-09-30T17:07:16.767Z
Answers.LastActivityDate: 2020-09-30T17:07:16.767Z
Answers.UserDisplayName: Saurav Maheshkar
Body: <p>I have been doing a course which teaches you about Deep Neural Networks, during one of the exercises I was made to make an RNN for sentiment classification which I did, but I did not understand how an RNN is able to deal with sentences of different lengths while conducting sentiment classification.</p>
  
Tags: <neural-networks><recurrent-neural-networks><text-classification><sentiment-analysis><multi-label-classification>
Title: How do RNN's for sentiment classification deal with different sentence lengths?
UserDisplayName: jr123456jr987654321
ThreadText: # How do RNN's for sentiment classification deal with different sentence lengths?
  
  (Asked by: username_0 on 2020-08-11)
  
  I have been doing a course which teaches you about Deep Neural Networks, during one of the exercises I was made to make an RNN for sentiment classification which I did, but I did not understand how an RNN is able to deal with sentences of different lengths while conducting sentiment classification.
  
  **Tags:** neural-networks, recurrent-neural-networks, text-classification, sentiment-analysis, multi-label-classification
  
  ---
  
  ## 1 answers
  
  ### Answer by username_1 on 2020-09-30. Score: 1 | Accepted answer
  
  One of the essential pre-processing we do on the corpus involves treating the variable-length sentences to a fixed length. There are various ways in which we can do this:
  
  # Truncate
  
  ---
  
  This involves reducing the length of all the sentences to the length of the shortest sentence in the corpus. This is generally not done as it reduces the amount of information that we can learn from the corpus. This image shows pre sequence truncation, where we remove from the back to make the sentences of the same length.
  
  [![Truncate Example](https://i.sstatic.net/PBgbz.png)](https://i.sstatic.net/PBgbz.png)
  
  # Padding
  
  ---
  
  This is the most preferred method when it comes to handling the problem of variable length sentences. In this approach, we increase the size of each vector to the longest sentence in the corpus. There are two ways to this:
  
  * **Post-Padding**: Adding zeroes in the ending
  * **Pre-Padding**: Adding zeroes in the beginning
  
  # References
  
  ---
  
  [Effect of Padding on LSTMs and CNNs](https://arxiv.org/pdf/1903.07288.pdf) by Dwarampudi Mahidhar Reddy and N V Subba Reddy, et al.
  
  
  ---
  
  