Why do attention models need to choose a maximum sentence length?

pinocchio: <p>I was going through the <a href="https://pytorch.org/tutorials/intermediate/seq2seq_translation_tutorial.html#sphx-glr-intermediate-seq2seq-translation-tutorial-py" rel="noopener nofollow ugc">seq2seq-translation tutorial on pytorch</a> and found the following sentence:</p>
<blockquote>
<p>Because there are sentences of all sizes in the training data, to actually create and train this layer we have to choose a maximum sentence length (input length, for encoder outputs) that it can apply to. Sentences of the maximum length will use all the attention weights, while shorter sentences will only use the first few.</p>
</blockquote>
<p>which didn’t really make sense to me. My understanding of attention is that attention is computed as follows (according to the Pointer Network paper) at time step $t$:</p>
<p>$$ u^{&lt;t,j&gt;} = v^\top tanh( W_1 e_j + W_2 d_{t} ) = NN_u(e_j, d_t )$$<br>
$$ \alpha^{&lt;t,j&gt;} = softmax( u^{&lt;t,j&gt;} ) = \frac{u^{&lt;t,j&gt;}}{Z^{}}$$<br>
$$ d’<em>{&lt;i+1&gt;} = \sum^{T_x}</em>{j=1} \alpha^{&lt;t,j&gt;} e_j $$</p>
<p>which basically means that a specific attention weight is not dependent on the length of the encoder (i.e. the encoder can change size and the above equation won’t be affected because $T_x$ can be variable size).</p>
<p>If that is true then why does the paper say this maximum sentence length thing?</p>
<p>They also say:</p>
<blockquote>
<p>There are other forms of attention that work around the length limitation by using a relative position approach. Read about “local attention” in <a href="https://arxiv.org/abs/1508.04025" rel="noopener nofollow ugc">Effective Approaches to Attention-based Neural Machine Translation</a>.</p>
</blockquote>
<p>which also confused me. Any clarification?</p>
<hr>
<aside class="onebox stackexchange" data-onebox-src="https://stats.stackexchange.com/questions/411736/why-do-attention-models-need-to-choose-a-maximum-sentence-length">
  <header class="source">

      <a href="https://stats.stackexchange.com/questions/411736/why-do-attention-models-need-to-choose-a-maximum-sentence-length" target="_blank" rel="noopener nofollow ugc">stats.stackexchange.com</a>
  </header>

  <article class="onebox-body">
      <a href="https://stats.stackexchange.com/users/28986/charlie-parker" target="_blank" rel="noopener nofollow ugc">
    <img alt="Charlie Parker" src="https://i.stack.imgur.com/2B6rV.png?s=256&amp;g=1" class="thumbnail onebox-avatar" width="256" height="256">
  </a>

<h4>
  <a href="https://stats.stackexchange.com/questions/411736/why-do-attention-models-need-to-choose-a-maximum-sentence-length" target="_blank" rel="noopener nofollow ugc">Why do attention models need to choose a maximum sentence length?</a>
</h4>

<div class="tags">
  <strong>neural-networks, natural-language, recurrent-neural-network, attention</strong>
</div>

<div class="date">
  asked by
  
  <a href="https://stats.stackexchange.com/users/28986/charlie-parker" target="_blank" rel="noopener nofollow ugc">
    Charlie Parker
  </a>
  on <a href="https://stats.stackexchange.com/questions/411736/why-do-attention-models-need-to-choose-a-maximum-sentence-length" target="_blank" rel="noopener nofollow ugc">01:02AM - 06 Jun 19 UTC</a>
</div>

  </article>

  <div class="onebox-metadata">
    
    
  </div>

  <div style="clear: both"></div>
</aside>