Properly loading a fine tuned model from directory
Hi everybody,After reading the docs I still don’t really understand how should I load my saved model properly.I fine tuned a CamembertForSequenceClassification.from_pretrained model with some data, the results was good so I saved it using save_pretrained(model_path). Now I would like to use this model to do inference… I use these lines of code:config = AutoConfig.from_pretrained(model_path)tokenizer = AutoTokenizer.from_pretrained(model_path)model = AutoModelForSequenceClassification.from_config(config)I now have several interogation:If I tokenize a new sequence with tokenizer.encode_plus(new_seq), it doesn’t tokenize the sentence the way it did when I previously saved the model. I must precise all the params (max_length…) to retrieve what I want.  Is that normal?If I load my saved model without using AutoModelForSequenceClassification but with AutoModel the model do not load a classification layer however I saved my model using this last layer. Is that also normal?So I’m wondering how can I be sure that I load the exact same model with all the weights and params that I saved previously.Thanks for everything!
2020-08-25T09:32:48Z
Yes, you should pass the same params to tokenizer that you passed during training.AutoModelwon’t add the heads (classfication layer, LM head etc). Use proper AutoModel classes to get same weights and params i.eAutoModelForSequenceClassificationfor classification model,AutoModelForCausalLMfor causal LM’s like GPT-2 etcYou can load the saved model using justAutoModelForSequenceClassification.from_pretrained, it’ll load theconfigitself. You should passconfigexplicitly when you want to change something in it.
2020-08-25T09:41:16Z
Ok that’s clear, thank you very much for your answer.