# Token classification on long sentences

**URL:** <https://discuss.huggingface.co/t/token-classification-on-long-sentences/14354>\
**Category:** 🤗Transformers\
**Created:** [February 2, 2022, 9:55pm UTC](https://discuss.huggingface.co/t/token-classification-on-long-sentences/14354 "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](https://discuss.huggingface.co/u/rogeriobromfman)\
**Post date:** [February 2, 2022, 9:55pm UTC](https://discuss.huggingface.co/t/token-classification-on-long-sentences/14354/1 "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.
