FlaubertForTokenClassification 
Author: stas00
Pull request: yes

implement FlaubertForTokenClassification as a subclass of XLMForTokenClassification.

Based on an item from https://github.com/huggingface/transformers/projects/17

Comments:
# [Codecov](https://codecov.io/gh/huggingface/transformers/pull/5644?src=pr&el=h1) Report
> Merging [#5644](https://codecov.io/gh/huggingface/transformers/pull/5644?src=pr&el=desc) into [master](https://codecov.io/gh/huggingface/transformers/commit/0befb513278f6e42b722be340dbc667e0ba2718e&el=desc) will **decrease** coverage by `1.02%`.
> The diff coverage is `100.00%`.

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

```diff
@@            Coverage Diff             @@
##           master    #5644      +/-   ##
==========================================
- Coverage   78.26%   77.24%   -1.03%     
==========================================
  Files         146      146              
  Lines       25998    26005       +7     
==========================================
- Hits        20348    20088     -260     
- Misses       5650     5917     +267     
```


| [Impacted Files](https://codecov.io/gh/huggingface/transformers/pull/5644?src=pr&el=tree) | Coverage Δ | |
|---|---|---|
| [src/transformers/\_\_init\_\_.py](https://codecov.io/gh/huggingface/transformers/pull/5644/diff?src=pr&el=tree#diff-c3JjL3RyYW5zZm9ybWVycy9fX2luaXRfXy5weQ==) | `99.24% <ø> (ø)` | |
| [src/transformers/modeling\_auto.py](https://codecov.io/gh/huggingface/transformers/pull/5644/diff?src=pr&el=tree#diff-c3JjL3RyYW5zZm9ybWVycy9tb2RlbGluZ19hdXRvLnB5) | `74.41% <ø> (ø)` | |
| [src/transformers/modeling\_flaubert.py](https://codecov.io/gh/huggingface/transformers/pull/5644/diff?src=pr&el=tree#diff-c3JjL3RyYW5zZm9ybWVycy9tb2RlbGluZ19mbGF1YmVydC5weQ==) | `85.18% <100.00%> (+0.81%)` | :arrow_up: |
| [src/transformers/modeling\_tf\_mobilebert.py](https://codecov.io/gh/huggingface/transformers/pull/5644/diff?src=pr&el=tree#diff-c3JjL3RyYW5zZm9ybWVycy9tb2RlbGluZ190Zl9tb2JpbGViZXJ0LnB5) | `23.38% <0.00%> (-73.39%)` | :arrow_down: |
| [src/transformers/modeling\_tf\_distilbert.py](https://codecov.io/gh/huggingface/transformers/pull/5644/diff?src=pr&el=tree#diff-c3JjL3RyYW5zZm9ybWVycy9tb2RlbGluZ190Zl9kaXN0aWxiZXJ0LnB5) | `64.90% <0.00%> (-33.90%)` | :arrow_down: |
| [src/transformers/file\_utils.py](https://codecov.io/gh/huggingface/transformers/pull/5644/diff?src=pr&el=tree#diff-c3JjL3RyYW5zZm9ybWVycy9maWxlX3V0aWxzLnB5) | `81.49% <0.00%> (+0.29%)` | :arrow_up: |
| [src/transformers/modeling\_tf\_roberta.py](https://codecov.io/gh/huggingface/transformers/pull/5644/diff?src=pr&el=tree#diff-c3JjL3RyYW5zZm9ybWVycy9tb2RlbGluZ190Zl9yb2JlcnRhLnB5) | `93.36% <0.00%> (+49.37%)` | :arrow_up: |
| [src/transformers/modeling\_tf\_electra.py](https://codecov.io/gh/huggingface/transformers/pull/5644/diff?src=pr&el=tree#diff-c3JjL3RyYW5zZm9ybWVycy9tb2RlbGluZ190Zl9lbGVjdHJhLnB5) | `95.53% <0.00%> (+69.51%)` | :arrow_up: |

------

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


Thanks! Can you also add the model to the common tests (by adding it to the [all_model_classes](https://github.com/huggingface/transformers/blob/b2747af5434e5a5d8ab1d7e2789699d20d7a4ab8/tests/test_modeling_flaubert.py#L316)) and in the [documentation file](https://github.com/huggingface/transformers/blob/master/docs/source/model_doc/flaubert.rst)?

This looks great to me otherwise.

> Can you also add the model to the common tests (by adding it to the [all_model_classes](https://github.com/huggingface/transformers/blob/b2747af5434e5a5d8ab1d7e2789699d20d7a4ab8/tests/test_modeling_flaubert.py#L316))

I tried that originally, but they don't support `*TokenClassification` - its outputs are different, so most tests break. Note that `XLMForTokenClassification` isn't being tested in the common tests. This PR was really monkeyseemonkeydo. Perhaps merging this and then work on `XLMForTokenClassification` common tests first? and then the subclass will be easy.

> and in the documentation file?

done.

I think there is a bug in `XLMForTokenClassification` - if I do this fix:
```
--- a/src/transformers/modeling_xlm.py
+++ b/src/transformers/modeling_xlm.py
@@ -1079,7 +1079,7 @@ class XLMForTokenClassification(XLMPreTrainedModel):
         sequence_output = self.dropout(sequence_output)
         logits = self.classifier(sequence_output)

-        outputs = (logits,) + outputs[2:]  # add hidden states and attention if they are here
+        outputs = (logits,) + outputs[1:]  # add hidden states and attention if they are here
         if labels is not None:
             loss_fct = CrossEntropyLoss()
             # Only keep active parts of the loss
```
I can now add `XLMForTokenClassification` to `all_model_classes` - and 99% of it now passes.

It looks like that line of code was copied from `BertForTokenClassification`, but for XLM it appears to need to be `outputs[1:]`


Oh, my fork was outdated - I see you have just fixed this bug. OK, adding FlaubertForTokenClassification to all_model_classes should work now.