<p>For any model that does not take a time series approach like an RNN does, the padding shouldn't make a difference.</p>
<p>I prefer padding right simply because there also might be text you need to cut-off. Then padding is more intuitive as you either cut-off a text if it's too long or pad a text when it's too short.</p>
<p>Either way, when a model is trained a certain way, it shouldn't make a difference so long the testing is also padded the way it was presented in training.</p>

CC BY-SA 4.0
2020-07-03T07:47:33.407Z
the problem with padding right is the last value for time of RNN unit is mostly always zero, i tackle it by return sequence from the recurrent layer, so it's not affected by the last zero pad. supposed to be correct?
Dan D.
CC BY-SA 4.0
2020-07-03T07:35:07.677Z
2020-07-03T07:35:07.677Z
N. Kiefer
<p>Text classification of equal length texts works without padding, but in reality, practically, texts never have the same length.</p>
<p>For example, spam filtering on blog article:</p>
<pre><code>thanks for sharing    [3 tokens] --&gt; 0 (Not spam)
this article is great [4 tokens] --&gt; 0 (Not spam)
here's &lt;URL&gt;          [2 tokens] --&gt; 1 (Spam)
</code></pre>
<p>Should I pad the texts on the right:</p>
<pre><code>thanks for     sharing --
this   article is      great
here's URL     --      --
</code></pre>
<p>Or, pad on the left:</p>
<pre><code>--   thanks  for    sharing
this article is     great
--   --      here's URL
</code></pre>
<p>What are the pros and cons of either pad left or right?</p>

<natural-language-processing><long-short-term-memory><sequence-modeling><text-classification><padding>
Text classification of non-equal length texts, should I pad left or right?
Dan D.
# Text classification of non-equal length texts, should I pad left or right?

(Asked by: username_0 on 2020-07-03)

Text classification of equal length texts works without padding, but in reality, practically, texts never have the same length.
For example, spam filtering on blog article:
thanks for sharing    [3 tokens] --> 0 (Not spam)
this article is great [4 tokens] --> 0 (Not spam)
here's           [2 tokens] --> 1 (Spam)

Should I pad the texts on the right:
thanks for     sharing --
this   article is      great
here's URL     --      --

Or, pad on the left:
--   thanks  for    sharing
this article is     great
--   --      here's URL

What are the pros and cons of either pad left or right?

**Tags:** natural-language-processing, long-short-term-memory, sequence-modeling, text-classification, padding


---

## 1 answers

### Answer by username_1 on 2020-07-03. Score: 1 | Accepted answer

For any model that does not take a time series approach like an RNN does, the padding shouldn't make a difference.

I prefer padding right simply because there also might be text you need to cut-off. Then padding is more intuitive as you either cut-off a text if it's too long or pad a text when it's too short.

Either way, when a model is trained a certain way, it shouldn't make a difference so long the testing is also padded the way it was presented in training.

> **Comments:**
> **username_0**: the problem with padding right is the last value for time of RNN unit is mostly always zero, i tackle it by return sequence from the recurrent layer, so it's not affected by the last zero pad. supposed to be correct?  

---

