Add functioning early stopping (patience) and weighted random sampling
This is to fix the issues in #4186 (hopefully) to get it merged in. Also adds weighted random sampling for imbalanced classes.
# [Codecov](https://codecov.io/gh/huggingface/transformers/pull/5958?src=pr&el=h1) Report
> Merging [#5958](https://codecov.io/gh/huggingface/transformers/pull/5958?src=pr&el=desc) into [master](https://codecov.io/gh/huggingface/transformers/commit/09a2f40684f77e62d0fd8485fe9d2d610390453f&el=desc) will **decrease** coverage by `0.09%`.
> The diff coverage is `13.04%`.

[![Impacted file tree graph](https://codecov.io/gh/huggingface/transformers/pull/5958/graphs/tree.svg?width=650&height=150&src=pr&token=9qOlN6Hb1c)](https://codecov.io/gh/huggingface/transformers/pull/5958?src=pr&el=tree)

```diff
@@            Coverage Diff             @@
##           master    #5958      +/-   ##
==========================================
- Coverage   78.49%   78.39%   -0.10%     
==========================================
  Files         146      146              
  Lines       26210    26252      +42     
==========================================
+ Hits        20573    20580       +7     
- Misses       5637     5672      +35     
```


| [Impacted Files](https://codecov.io/gh/huggingface/transformers/pull/5958?src=pr&el=tree) | Coverage Δ | |
|---|---|---|
| [src/transformers/trainer.py](https://codecov.io/gh/huggingface/transformers/pull/5958/diff?src=pr&el=tree#diff-c3JjL3RyYW5zZm9ybWVycy90cmFpbmVyLnB5) | `35.50% <9.09%> (-2.34%)` | :arrow_down: |
| [src/transformers/training\_args.py](https://codecov.io/gh/huggingface/transformers/pull/5958/diff?src=pr&el=tree#diff-c3JjL3RyYW5zZm9ybWVycy90cmFpbmluZ19hcmdzLnB5) | `78.00% <100.00%> (+0.44%)` | :arrow_up: |
| [src/transformers/generation\_tf\_utils.py](https://codecov.io/gh/huggingface/transformers/pull/5958/diff?src=pr&el=tree#diff-c3JjL3RyYW5zZm9ybWVycy9nZW5lcmF0aW9uX3RmX3V0aWxzLnB5) | `86.46% <0.00%> (+0.25%)` | :arrow_up: |

------

[Continue to review full report at Codecov](https://codecov.io/gh/huggingface/transformers/pull/5958?src=pr&el=continue).
> **Legend** - [Click here to learn more](https://docs.codecov.io/docs/codecov-delta)
> `Δ = absolute <relative> (impact)`, `ø = not affected`, `? = missing data`
> Powered by [Codecov](https://codecov.io/gh/huggingface/transformers/pull/5958?src=pr&el=footer). Last update [09a2f40...cbc7c63](https://codecov.io/gh/huggingface/transformers/pull/5958?src=pr&el=lastupdated). Read the [comment docs](https://docs.codecov.io/docs/pull-request-comments).
<|||||>This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.
<|||||>when this will be added to library?<|||||>This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.
