title: PyTorch tokenizers: how to truncate tokens from left?
body: <p>As we can see in the below code snippet, specifying max_length and truncation for a tokenizer cuts excess tokens <em>from the left</em>:</p>
  <p><div class="snippet" data-lang="js" data-hide="false" data-console="true" data-babel="false">
  <div class="snippet-code">
  <pre class="snippet-code-html lang-html prettyprint-override"><code>tokenizer("hello, my name", truncation=True, max_length=6).input_ids
  
  &gt; [0, 42891, 6, 127, 766, 2]
  
  tokenizer("hello, my name", truncation=True, max_length=4).input_ids
  
  &gt; [0, 42891, 6, 2]</code></pre>
  </div>
  </div>
  </p>
  <p>The different tokenization strategies like <em>only_second</em>, <em>only_first</em>, <em>longest_first</em>, all seem to cut from the right.  Is there a way to cut from the left? So that the tokens would be <code>[0, 127, 766, 2]</code> in the second example?</p>