run_ner.py RobertaForTokenClassification.from_pretrained "size mismatch for classifier.bias"
Author: paulthemagno
Pull request: no

## ❓ Questions & Help
I have a trouble on run_ner.py([https://github.com/huggingface/transformers/blob/master/examples/run_ner.py](url)) evaluation using **Roberta**. My error is in this snippet:

```python
    # Load pretrained model and tokenizer
    if args.local_rank not in [-1, 0]:
        torch.distributed.barrier()  # Make sure only the first process in distributed training will download model & vocab

    args.model_type = args.model_type.lower()
    config_class, model_class, tokenizer_class = MODEL_CLASSES[args.model_type]
    config = RobertaConfig.from_pretrained(args.config_name if args.config_name else args.model_name_or_path,
                                          num_labels=num_labels,
                                          cache_dir=args.cache_dir if args.cache_dir else None)
    tokenizer = RobertaTokenizer.from_pretrained(args.tokenizer_name if args.tokenizer_name else args.model_name_or_path,
                                                do_lower_case=args.do_lower_case,
                                                cache_dir=args.cache_dir if args.cache_dir else None)
    model = RobertaForTokenClassification.from_pretrained(args.model_name_or_path,
                                        from_tf=bool(".ckpt" in args.model_name_or_path),
                                        config=config,
                                        cache_dir=args.cache_dir if args.cache_dir else None)
```

If I run with both training and evaluation, it works fine.
If I want only to evaluate my model I get this error:
```
Traceback (most recent call last):
  File "run_pos.py", line 560, in <module>
    main()
  File "run_pos.py", line 477, in main
    cache_dir=args.cache_dir if args.cache_dir else None)
  File "/usr/local/lib/python3.6/dist-packages/transformers/modeling_utils.py", line 479, in from_pretrained
    model.__class__.__name__, "\n\t".join(error_msgs)))
RuntimeError: Error(s) in loading state_dict for RobertaForTokenClassification:
        size mismatch for classifier.weight: copying a param with shape torch.Size([19, 768]) from checkpoint, the shape in current model is torch.Size([18, 768]).
        size mismatch for classifier.bias: copying a param with shape torch.Size([19]) from checkpoint, the shape in current model is torch.Size([18]).
```

I used a different set of labels (18 labels rather than CoNLL format) passing them through the flag `--labels /path/to/labels.txt`. As you can see, when it loads the model, it sees 19 labels and not the expected 18. I think the 19th is added during the training to tag the subwords. In particular it should be:

```python
# Use cross entropy ignore index as padding label id so that only real label ids contribute to the loss later
    pad_token_label_id = CrossEntropyLoss().ignore_index
```

I don't know if I have to remove a label from its mapping (how to do it?) or if there are other solutions. I also don't know why this error doesn't occur if I train and evaluate sequentially in the same process.

Thank you!

Comments: