load  tf2 roberta model meet error
Author: bestpredicts
Pull request: no

## ❓ Questions & Help
`
config = RobertaConfig() # print(config) to see settings  
config.output_hidden_states = False # Set to True to obtain hidden states   
model = TFRobertaModel.from_pretrained('/home/wk/Bert_Pretrained/robert_base/roberta-base-tf_model.h5', config=config)   `
errors
`ValueError                                Traceback (most recent call last)
<ipython-input-19-eac9e3228d6c> in <module>
      1 config = RobertaConfig() # print(config) to see settings
      2 config.output_hidden_states = False # Set to True to obtain hidden states
----> 3 model = TFRobertaModel.from_pretrained('/home/wk/Bert_Pretrained/robert_base/roberta-base-tf_model.h5', config=config)

~/anaconda3/lib/python3.7/site-packages/transformers/modeling_tf_utils.py in from_pretrained(cls, pretrained_model_name_or_path, *model_args, **kwargs)
    315         # see https://github.com/tensorflow/tensorflow/blob/00fad90125b18b80fe054de1055770cfb8fe4ba3/tensorflow/python/keras/engine/network.py#L1339-L1357
    316         try:
--> 317             model.load_weights(resolved_archive_file, by_name=True)
    318         except OSError:
    319             raise OSError("Unable to load weights from h5 file. "

~/anaconda3/lib/python3.7/site-packages/tensorflow_core/python/keras/engine/training.py in load_weights(self, filepath, by_name)
    179         raise ValueError('Load weights is not yet supported with TPUStrategy '
    180                          'with steps_per_run greater than 1.')
--> 181     return super(Model, self).load_weights(filepath, by_name)
    182 
    183   @trackable.no_automatic_dependency_tracking

~/anaconda3/lib/python3.7/site-packages/tensorflow_core/python/keras/engine/network.py in load_weights(self, filepath, by_name)
   1173         f = f['model_weights']
   1174       if by_name:
-> 1175         saving.load_weights_from_hdf5_group_by_name(f, self.layers)
   1176       else:
   1177         saving.load_weights_from_hdf5_group(f, self.layers)

~/anaconda3/lib/python3.7/site-packages/tensorflow_core/python/keras/saving/hdf5_format.py in load_weights_from_hdf5_group_by_name(f, layers)
    758                                symbolic_weights[i])) +
    759                            ', but the saved weight has shape ' +
--> 760                            str(weight_values[i].shape) + '.')
    761 
    762         else:

ValueError: Layer #0 (named "roberta"), weight <tf.Variable 'tf_roberta_model_5/roberta/embeddings/word_embeddings/weight:0' shape=(30522, 768) dtype=float32, numpy=
array([[-0.02175204,  0.01785859, -0.01712652, ...,  0.0088525 ,
        -0.00240036,  0.01757819],
       [ 0.01320856,  0.01548896,  0.0290868 , ..., -0.01266216,
         0.00756532, -0.01283411],
       [ 0.02433892,  0.00970818, -0.01082115, ...,  0.01121136,
         0.01314066,  0.0088822 ],
       ...,
       [-0.00798688, -0.03137787, -0.00074065, ...,  0.03188593,
         0.02637535,  0.02540809],[ 0.01545427, -0.02784344,  0.01380141, ..., -0.02135191,
        -0.01506698, -0.00579444],
       [-0.01216899,  0.00676558,  0.01336646, ..., -0.00323554,
         0.02038151,  0.02287306]], dtype=float32)> has shape (30522, 768), but the saved weight has shape (50265, 7)`
<!-- A clear and concise description of the question. -->


Comments:
I am facing the same issue, how did you resolve this? @bestpredicts 

Same issue with portuguese bert version


I had the same issue and found that this problem occurs because the default "RobertaConfig" is based on "bert-base-uncased" config, which is different from "roberta-base" config. The right way to initialize the model and configuration is (LysandreJik's solution):

```python
config = RobertaConfig.from_pretrained("roberta-base", output_hidden_states=True)
model = RobertaForSequenceClassification.from_pretrained("roberta-base", config=config)
```

Please refer to the similar issue:
[#1627](https://github.com/huggingface/transformers/issues/1627)

This is annoying, one doesnt have to do this while setting config for TFDistilBert

https://towardsdatascience.com/working-with-hugging-face-transformers-and-tf-2-0-89bf35e3555a