Cannot load model in tranformers
Author: gdet
Pull request: no
Labels: name: wontfix

name: Version mismatch

Hello, I tried to upload your model and I get this error: 

    tokenizer = AutoTokenizer.from_pretrained("nlpaueb/bert-base-greek-uncased-v1")
    model = AutoModelWithLMHead.from_pretrained("nlpaueb/bert-base-greek-uncased-v1")


    ERROR:pytorch_transformers.modeling_utils:Model name 'nlpaueb/bert-base-greek-uncased-v1' 
    was not found in model name list (bert-base-uncased, bert-large-uncased, bert-base-cased, 
    bert-large-cased, bert-base-multilingual-uncased, bert-base-multilingual-cased, bert-base-chinese, 
    bert-base-german-cased, bert-large-uncased-whole-word-masking, bert-large-cased-whole-word-masking,
    bert-large-uncased-whole-word-masking-finetuned-squad, bert-large-cased-whole-word-masking-finetuned-squad, bert-base-cased-finetuned-mrpc). 
    We assumed 'nlpaueb/bert-base-greek-uncased-v1' 
    was a path or url but couldn't find any file associated to this path or url.

If I download the model and upload it from a folder in the system I get this error: 


    tokenizer = AutoTokenizer.from_pretrained("/home/transformers/huggingface/greekaueb")
    model = AutoModelWithLMHead.from_pretrained("/home/transformers/huggingface/greekaueb")

    ValueErrorValueError: : Unrecognized model identifier in /home/hatzimin/transformers
    /huggingface/greek_transfer_learning/greekaueb. 
    Should contains one of 'bert', 'openai-gpt', 'gpt2', 'transfo-xl', 'xlnet', 'xlm', 'roberta'
    


Comments:
It seems you have a very old version of this repository (when it was still named `pytorch_transformers`). Please update to the latest version or you won't have all the features (like access to the model hub).

I fixed the version and the error was fixed. But now I get 

    AttributeError: 'BertTokenizer' object has no attribute 'encoder'
Do I have another problem with version? I also used 

    pip3 install --upgrade pytorch-pretrained-bert
Thank you

Please post the code and full trace that gave you this error.

    tokenizer = AutoTokenizer.from_pretrained("nlpaueb/bert-base-greek-uncased-v1")
    model = AutoModelWithLMHead.from_pretrained("nlpaueb/bert-base-greek-uncased-v1")
    model.to(args.device)
    # Add special tokens if they are not already added
    add_special_tokens_(model, tokenizer)

    def add_special_tokens_(model, tokenizer):
    """ Add special tokens to the tokenizer and the model if they have not already been added. """
       orig_num_tokens = len(tokenizer.encoder)
       num_added_tokens = tokenizer.add_special_tokens(ATTR_TO_SPECIAL_TOKEN) # doesn't add if they are already there
       if num_added_tokens > 0:
          model.resize_token_embeddings(new_num_tokens=orig_num_tokens + num_added_tokens)



     INFO:transformers.modeling_utils:loading weights file https://s3.amazonaws.com   /models.huggingface.co/bert/nlpaueb/bert-base-greek-uncased-v1/pytorch_model.bin from cache at /home/hatzimin/.cache/torch/transformers/3a685f5fa6f50a35a4efc31e9cdc74cfe8e2956002ee5c2df350e5e6c54deaf2.2aad66b9b70b2aa069cb5a695a371c8289c0fc672a34efff6188126824ef3b60
     INFO:transformers.modeling_utils:Weights from pretrained model not used in BertForMaskedLM: ['cls.seq_relationship.weight', 'cls.seq_relationship.bias']
    Traceback (most recent call last):
     File "./traingreek.py", line 268, in <module>
       train()
     File "./traingreek.py", line 161, in train
       add_special_tokens_(model, tokenizer)
     File "./traingreek.py", line 51, in add_special_tokens_
       orig_num_tokens = len(tokenizer.encoder)
     AttributeError: 'BertTokenizer' object has no attribute 'encoder'


That's because the tokenizer does not have an `encoder` attribute. If you're looking to get the size of the tokenizer, you can do it with `len(tokenizer)`.

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.