Repository: huggingface/transformers

Issue:
Update examples/ner/run_ner.py to use AutoModel
This PR is updating `run_ner.py` to use AutoModel implementation. Refer to #3290 and is simpler than before.

Maybe @srush can review this.


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

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

```diff
@@            Coverage Diff             @@
##           master    #3305      +/-   ##
==========================================
- Coverage   77.47%   77.46%   -0.01%     
==========================================
  Files          99       99              
  Lines       16799    16799              
==========================================
- Hits        13015    13014       -1     
- Misses       3784     3785       +1     
```


| [Impacted Files](https://codecov.io/gh/huggingface/transformers/pull/3305?src=pr&el=tree) | Coverage Δ | |
|---|---|---|
| [src/transformers/modeling\_tf\_utils.py](https://codecov.io/gh/huggingface/transformers/pull/3305/diff?src=pr&el=tree#diff-c3JjL3RyYW5zZm9ybWVycy9tb2RlbGluZ190Zl91dGlscy5weQ==) | `85.68% <0.00%> (-0.36%)` | :arrow_down: |
| [src/transformers/modeling\_utils.py](https://codecov.io/gh/huggingface/transformers/pull/3305/diff?src=pr&el=tree#diff-c3JjL3RyYW5zZm9ybWVycy9tb2RlbGluZ191dGlscy5weQ==) | `93.70% <0.00%> (+0.13%)` | :arrow_up: |

------

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


Resolving patch:
diff --git a/examples/ner/run_ner.py b/examples/ner/run_ner.py
--- a/examples/ner/run_ner.py
+++ b/examples/ner/run_ner.py
@@ -31,7 +31,6 @@
 from tqdm import tqdm, trange
 
 from transformers import (
-    ALL_PRETRAINED_MODEL_ARCHIVE_MAP,
     WEIGHTS_NAME,
     AdamW,
     AutoConfig,
@@ -39,7 +38,7 @@
     AutoTokenizer,
     get_linear_schedule_with_warmup,
 )
-from transformers.modeling_auto import MODEL_MAPPING
+from transformers.modeling_auto import MODEL_FOR_TOKEN_CLASSIFICATION_MAPPING
 from utils_ner import convert_examples_to_features, get_labels, read_examples_from_file
 
 
@@ -51,8 +50,9 @@
 
 logger = logging.getLogger(__name__)
 
-ALL_MODELS = tuple(ALL_PRETRAINED_MODEL_ARCHIVE_MAP)
-MODEL_CLASSES = tuple(m.model_type for m in MODEL_MAPPING)
+MODEL_CONFIG_CLASSES = list(MODEL_FOR_TOKEN_CLASSIFICATION_MAPPING.keys())
+MODEL_TYPES = tuple(conf.model_type for conf in MODEL_CONFIG_CLASSES)
+ALL_MODELS = sum((tuple(conf.pretrained_config_archive_map.keys()) for conf in MODEL_CONFIG_CLASSES), ())
 
 TOKENIZER_ARGS = ["do_lower_case", "strip_accents", "keep_accents", "use_fast"]
 
@@ -384,7 +384,7 @@ def main():
         default=None,
         type=str,
         required=True,
-        help="Model type selected in the list: " + ", ".join(MODEL_CLASSES),
+        help="Model type selected in the list: " + ", ".join(MODEL_TYPES),
     )
     parser.add_argument(
         "--model_name_or_path",


Test patch: