Add Epsilon- and Eta-Sampling
Author: shermansiu
Pull request: yes

# What does this PR do?

<!--
Congratulations! You've made it this far! You're not quite done yet though.

Once merged, your PR is going to appear in the release notes with the title you set, so make sure it's a great title that fully reflects the extent of your awesome contribution.

Then, please replace this with a description of the change and which issue is fixed (if applicable). Please also include relevant motivation and context. List any dependencies (if any) that are required for this change.

Once you're done, someone will review your PR shortly (see the section "Who can review?" below to tag some potential reviewers). They may suggest changes to make the code even better. If no one reviewed your PR after a week has passed, don't hesitate to post a new comment @-mentioning the same persons---sometimes notifications get lost.
-->

<!-- Remove if not applicable -->

Implements epsilon- and eta-sampling, as seen in [[Truncation Sampling as Language Model Desmoothing](https://arxiv.org/abs/2210.15191)](https://arxiv.org/abs/2210.15191). The code is adapted from the author's official repository [here](https://github.com/john-hewitt/truncation-sampling).

Resolves #21092.


## Before submitting
- [x] 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.
- [x] 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?

Anyone in the community is free to review the PR once the tests have passed. Feel free to tag
members/contributors who may be interested in your PR.

<!-- Your PR will be replied to more quickly if you can figure out the right person to tag with @

 If you know how to use git blame, that is the easiest way, otherwise, here is a rough guide of **who to tag**.
 Please tag fewer than 3 people.

Models:

- text models: @ArthurZucker and @younesbelkada
- vision models: @amyeroberts and @NielsRogge
- speech models: @sanchit-gandhi

Library:

- flax: @sanchit-gandhi
- generate: @gante
- pipelines: @Narsil
- tensorflow: @gante and @Rocketknight1
- tokenizers: @ArthurZucker
- trainer: @sgugger

Integrations:

- deepspeed: @stas00
- ray/raytune: @richardliaw, @amogkam

Documentation: @sgugger, @stevhliu and @MKhalusova

HF projects:

- accelerate: [different repo](https://github.com/huggingface/accelerate)
- datasets: [different repo](https://github.com/huggingface/datasets)
- diffusers: [different repo](https://github.com/huggingface/diffusers)
- rust tokenizers: [different repo](https://github.com/huggingface/tokenizers)

Maintained examples (not research project or legacy):

- Flax: @sanchit-gandhi
- PyTorch: @sgugger
- TensorFlow: @Rocketknight1

 -->
@gante


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

@gante I incorporated your changes! I rebased with `main` because there were some merge conflicts, which caused some of the review snippets above to get "outdated," but it's done!

@sgugger this PR adds a new sampling-based generation strategy that can be effectively implemented through logits processors

Yeah, no problem!😊

@shermansiu now step 4 remains :) Would you like to work on it? (we can retweet and share your posts)

I'm interested, but it feels like it's best added to https://github.com/huggingface/blog/blob/main/notebooks/02_how_to_generate.ipynb than in its own notebook, as other truncation sampling approaches (top-p and top-k) are already there.

We don't update the notebooks for our blog posts, so they stay consistent with their content :) But we will certainly update our [new docs](https://huggingface.co/docs/transformers/main/en/generation_strategies)

The new docs only contain simple examples (for now), so the benefits of the new generation strategy should be showcased in a notebook. In the near future, we will have an advanced text generation doc with clear examples for each flag (but it won't be ready in the next 2-3 months)

I have a lot on my to-do list right now... Although I'd love to contribute to the notebook, I think it's unrealistic for me to be able to put something out soon.

Yesterday's ACL 2023 tutorial on "Generating Text from Large Language Models" covers eta-sampling and more! John Hewitt, the first author of the eta-sampling paper, was one of the presenters for that tutorial!

Site: https://rycolab.io/classes/acl-2023-tutorial/
Slides: https://drive.google.com/file/d/1UHbGcjzBURG1n2DufC7iDTmGNjIz5Dp_/view