Sliding window pipeline with average of logits
Author: boyleconnor
Pull request: yes

# What does this PR do?

This adds a variation on the existing `ChunkingPipeline` approach for handling strings with more than `model_max_length` tokens. After using the tokenizer to split the text into chunks (identically to how `ChunkingPipeline` does so), `SlidingWindowTokenClassificationPipeline` then averages the values of the logits for each token (across all sliding "windows" that happen to cover that token), and finally feeds those logits into the usual entity-extraction logic. The existing implementation of `TokenClassificationPipeline` instead runs entity extraction on each window separately, then takes the highest-scoring entity in case of any overlap.

Implements #14631

## Before submitting
- [ ] This PR fixes a typo or improves the docs (you can dismiss the other checks if that's the case).
- [x] Did you read the [contributor guideline](https://github.com/huggingface/transformers/blob/main/CONTRIBUTING.md#start-contributing-pull-requests),
      Pull Request section?
- [x] Was this discussed/approved via a Github issue or the [forum](https://discuss.huggingface.co/)? Please add a link
      to it if that's the case. **[Link](https://github.com/huggingface/transformers/issues/14631) to discussion**
- [ ] Did you make sure to update the documentation with your changes? Here are the
      [documentation guidelines](https://github.com/huggingface/transformers/tree/main/docs), and
      [here are tips on formatting docstrings](https://github.com/huggingface/transformers/tree/main/docs#writing-source-documentation).
- [x] Did you write any new necessary tests?


## Who can review?

@Narsil 


Comments:
The docs for this PR live [here](https://moon-ci-docs.huggingface.co/docs/transformers/pr_23097). All of your documentation changes will be reflected on that endpoint.

Can you provide some kind of benchmarks in terms fo benefits ?

If this is better in some form we can consider adding it in the pipelines.

In general we try to avoid adding new pipelines which don't change the I/O.
Also you can have your own pipeline coding on the hub directly : https://huggingface.co/docs/transformers/v4.28.1/en/main_classes/pipelines#pipeline-custom-code

@Narsil, @wigwit and I can work on trying to benchmark this (versus the existing approach) on an NER dataset.

Also, do you think this functionality would actually be more at home inside the existing `TokenClassificationPipeline` (as an alternative to the existing extract-entities-then-resolve-overlaps approach)? It could be activated by the user passing `average_logits=True` as one of the `__init__()` parameters. I'm realizing that would probably make more sense than creating another pipeline class and "task" just for the sliding window behavior.

Thanks for your PR but this looks more like a pipeline that would benefit from living entirely on the Hub using the [custom pipeline](https://huggingface.co/docs/transformers/add_new_pipeline#share-your-pipeline-on-the-hub) API than being added into Transformers.

Should this be closed?

This issue has been automatically marked as stale because it has not had recent activity. If you think this still needs to be addressed please comment on this thread.

Please note that issues that do not follow the [contributing guidelines](https://github.com/huggingface/transformers/blob/main/CONTRIBUTING.md) are likely to be ignored.