# Pretrained model with stride doesn't predict long text

**URL:** <https://discuss.huggingface.co/t/pretrained-model-with-stride-doesnt-predict-long-text/64017>\
**Category:** Beginners\
**Created:** [November 29, 2023, 4:43pm UTC](https://discuss.huggingface.co/t/pretrained-model-with-stride-doesnt-predict-long-text/64017 "2023-11-29T16:43:19Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![nbosc](https://avatars.discourse-cdn.com/v4/letter/n/35a633/32.png) [@nbosc](https://discuss.huggingface.co/u/nbosc)\
**Post date:** [November 29, 2023, 4:43pm UTC](https://discuss.huggingface.co/t/pretrained-model-with-stride-doesnt-predict-long-text/64017/1 "2023-11-29T16:43:20Z")

</div>

My objective is to annotate long documents with bioformer-8L. I have been said to use stride and truncation so I don’t have to split my documents in chunks of 512 tokens.

In the training phase, I called the tokenizer like this:

> tokenizer = AutoTokenizer.from\_pretrained(model\_checkpoint, stride = 128, return\_overflowing\_tokens=True, model\_max\_length=512, truncation=True, is\_split\_into\_words=True)

For the prediction I do:

> model = AutoModelForTokenClassification.from\_pretrained(model\_path)  
> tokenizer = AutoTokenizer.from\_pretrained(model\_path, stride = 128, return\_overflowing\_tokens=True, model\_max\_length=512, truncation=True, is\_split\_into\_words=True)  
> ner = pipeline(“token-classification”, model=model, tokenizer=tokenizer, aggregation\_strategy=“first”)

But it does not work, the model stops providing annotations in the middle of the text. For the test I duplicated several time the same sentence that I know contains annotations I am looking for.

Help please.

---

<div class="post-metadata">

**Author:** ![nbosc](https://avatars.discourse-cdn.com/v4/letter/n/35a633/32.png) [@nbosc](https://discuss.huggingface.co/u/nbosc)\
**Post date:** [December 1, 2023, 10:59am UTC](https://discuss.huggingface.co/t/pretrained-model-with-stride-doesnt-predict-long-text/64017/2 "2023-12-01T10:59:45Z")

</div>

Solution is to move stride from `from_trained` to `pipeline`.

> tokenizer = AutoTokenizer.from\_pretrained(model\_path, return\_overflowing\_tokens=True, model\_max\_length=512, truncation=True, is\_split\_into\_words=True)
> 
> ner = pipeline(“token-classification”, model=model, tokenizer=tokenizer, aggregation\_strategy=“first”, stride = 128)
