[WIP] Support label_smoothed_cross_entropy
Author: ieBoytsov
Pull request: yes
Labels: name: wontfix

By default there is no implementation of cross entropy with soft labels in Pytorch as discussed in #5168

I found a feature request in pytorch for it but it is still not done. 

https://github.com/pytorch/pytorch/issues/7455

There is also discussion where i found an implemented version of this loss. I checked that it performs the same as nn.CrossEntropyLoss given smoothing=0.0 and accurately smoothes labels given nonzero smoothing. I ported it with small refactoring.

Key improvements that are planned in this PR:

1) Add label smoothing cross entropy loss
2) support and parametrise loss choice in `finetune.py`


Comments:
# [Codecov](https://codecov.io/gh/huggingface/transformers/pull/5247?src=pr&el=h1) Report
> Merging [#5247](https://codecov.io/gh/huggingface/transformers/pull/5247?src=pr&el=desc) into [master](https://codecov.io/gh/huggingface/transformers/commit/aa6a29bc25b663e1311c5c4fb96b004cf8a6d2b6&el=desc) will **increase** coverage by `0.38%`.
> The diff coverage is `n/a`.

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

```diff
@@            Coverage Diff             @@
##           master    #5247      +/-   ##
==========================================
+ Coverage   77.92%   78.30%   +0.38%     
==========================================
  Files         137      137              
  Lines       23475    23475              
==========================================
+ Hits        18292    18383      +91     
+ Misses       5183     5092      -91     
```


| [Impacted Files](https://codecov.io/gh/huggingface/transformers/pull/5247?src=pr&el=tree) | Coverage Δ | |
|---|---|---|
| [src/transformers/tokenization\_utils.py](https://codecov.io/gh/huggingface/transformers/pull/5247/diff?src=pr&el=tree#diff-c3JjL3RyYW5zZm9ybWVycy90b2tlbml6YXRpb25fdXRpbHMucHk=) | `95.18% <0.00%> (+0.37%)` | :arrow_up: |
| [src/transformers/tokenization\_bert.py](https://codecov.io/gh/huggingface/transformers/pull/5247/diff?src=pr&el=tree#diff-c3JjL3RyYW5zZm9ybWVycy90b2tlbml6YXRpb25fYmVydC5weQ==) | `91.28% <0.00%> (+0.82%)` | :arrow_up: |
| [src/transformers/data/processors/squad.py](https://codecov.io/gh/huggingface/transformers/pull/5247/diff?src=pr&el=tree#diff-c3JjL3RyYW5zZm9ybWVycy9kYXRhL3Byb2Nlc3NvcnMvc3F1YWQucHk=) | `56.68% <0.00%> (+28.02%)` | :arrow_up: |

------

[Continue to review full report at Codecov](https://codecov.io/gh/huggingface/transformers/pull/5247?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/5247?src=pr&el=footer). Last update [aa6a29b...4d63b64](https://codecov.io/gh/huggingface/transformers/pull/5247?src=pr&el=lastupdated). Read the [comment docs](https://docs.codecov.io/docs/pull-request-comments).


The one thing i dont understand is where to initialise this loss in `finetune.py`.

As i see now there is now no loss instances in `finetune.py`, the loss function comes from given model and initialised during modelling_*.py

This PR seems outdated. The issue has been resolved with PR #5919

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.