# Token classification on long sentences

**URL:** </static-proxy?url=https%3A%2F%2Fdiscuss.huggingface.co%2Ft%2Ftoken-classification-on-long-sentences%2F14354%3E%5C
**Category:** 🤗Transformers\
**Created:** [February 2, 2022, 9:55pm UTC](/static-proxy?url=https%3A%2F%2Fdiscuss.huggingface.co%2Ft%2Ftoken-classification-on-long-sentences%2F14354 "2022-02-02T21:55:33Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![rogeriobromfman](https://sea2.discourse-cdn.com/hellohellohello/user_avatar/discuss.huggingface.co/rogeriobromfman/32/3727_2.png) [@rogeriobromfman](/static-proxy?url=https%3A%2F%2Fdiscuss.huggingface.co%2Fu%2Frogeriobromfman)%5C
**Post date:** [February 2, 2022, 9:55pm UTC](/static-proxy?url=https%3A%2F%2Fdiscuss.huggingface.co%2Ft%2Ftoken-classification-on-long-sentences%2F14354%2F1 "2022-02-02T21:55:33Z")

</div>

I have fine-tuned a BERT model for named-entity recognition. My tasks usually involve long sentences (over 512 tokens is very common).

At the moment, I’m solving this by not calling the `TokenClassificationPipeline`, but instead using the `max_length` and `stride` parameters of the tokenizer to deal with splitting the sentences, and then aggregating the resulting token labels in post-processing. For this, I have to manually call the pyTorch model for each sub-sentence.

Is there a native (or at least more efficient) way to do this? I saw this was implemented in the `QuestionAnsweringPipeline`.

The reason I’m asking is that I’m trying to implement this as a serverless endpoint in Amazon SageMaker. And for that to run smoothly, the inference script should be as optimized as possible.
