# Token indices sequence length is longer than the specified maximum sequence length

**URL:** <https://discuss.huggingface.co/t/token-indices-sequence-length-is-longer-than-the-specified-maximum-sequence-length/25133>\
**Category:** 🤗Tokenizers\
**Created:** [October 28, 2022, 1:11pm UTC](https://discuss.huggingface.co/t/token-indices-sequence-length-is-longer-than-the-specified-maximum-sequence-length/25133 "2022-10-28T13:11:16Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![antoine2323231](https://avatars.discourse-cdn.com/v4/letter/a/b9bd4f/32.png) [@antoine2323231](https://discuss.huggingface.co/u/antoine2323231)\
**Post date:** [October 28, 2022, 1:11pm UTC](https://discuss.huggingface.co/t/token-indices-sequence-length-is-longer-than-the-specified-maximum-sequence-length/25133/1 "2022-10-28T13:11:16Z")

</div>

Hi, when running the run\_t5\_mlm\_flax.py script I am getting this error:

Token indices sequence length is longer than the specified maximum sequence length for this model (523 \> 512). Running this sequence through the model will result in indexing errors.

I have specified model\_max\_length =512 within the tokenizer.  
And passed --max\_seq\_length=“512” \ to the run\_t5\_mlm\_flax.py script.

Unfortunately I still get the same warning.

---

<div class="post-metadata">

**Author:** ![lianghsun](https://sea2.discourse-cdn.com/hellohellohello/user_avatar/discuss.huggingface.co/lianghsun/32/57774_2.png) [@lianghsun](https://discuss.huggingface.co/u/lianghsun)\
**Post date:** [October 28, 2022, 11:11pm UTC](https://discuss.huggingface.co/t/token-indices-sequence-length-is-longer-than-the-specified-maximum-sequence-length/25133/2 "2022-10-28T23:11:23Z")

</div>

Hi @antoine2323231 , can you try the following code to see if it works?

```auto
tokenizer(batch_sentences, padding='max_length', truncation=True)

```

---

<div class="post-metadata">

**Author:** ![antoine2323231](https://avatars.discourse-cdn.com/v4/letter/a/b9bd4f/32.png) [@antoine2323231](https://discuss.huggingface.co/u/antoine2323231)\
**Post date:** [October 30, 2022, 7:43am UTC](https://discuss.huggingface.co/t/token-indices-sequence-length-is-longer-than-the-specified-maximum-sequence-length/25133/3 "2022-10-30T07:43:51Z")

</div>

> [@lianghsun](#):
>
> `tokenizer(batch_sentences, padding='max_length', truncation=True)`

Hey [lianghsun](https://discuss.huggingface.co/u/lianghsun), I tried that but getting the same result. It is strange..

---

<div class="post-metadata">

**Author:** ![bobbytonylowe-rgdl](https://avatars.discourse-cdn.com/v4/letter/b/34f0e0/32.png) [@bobbytonylowe-rgdl](https://discuss.huggingface.co/u/bobbytonylowe-rgdl)\
**Post date:** [December 19, 2022, 5:21pm UTC](https://discuss.huggingface.co/t/token-indices-sequence-length-is-longer-than-the-specified-maximum-sequence-length/25133/4 "2022-12-19T17:21:23Z")

</div>

I am also getting a similar error. Did you resolve this?

---

<div class="post-metadata">

**Author:** ![tq2000](https://avatars.discourse-cdn.com/v4/letter/t/22d042/32.png) [@tq2000](https://discuss.huggingface.co/u/tq2000)\
**Post date:** [February 15, 2023, 10:41pm UTC](https://discuss.huggingface.co/t/token-indices-sequence-length-is-longer-than-the-specified-maximum-sequence-length/25133/5 "2023-02-15T22:41:11Z")

</div>

My walk-around is to reduce the length of the prompt. For example, if you are doing question answering, the context + question should be short than 512 tokens.
