IndicoDataSolutions / finetune

Scikit-learn style model finetuning for NLP

Home Page:https://finetune.indico.io

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

[Need help] How can I load a created base model

yangliu2 opened this issue · comments

I was looking for finetuning a previously trained model because I no longer have access to the training data.

I see that Classifier have a create_base_model(filename, exists_ok=False) function. I was able to save the same model weights. But I'm not sure how to load the saved weights as a base model.

When I used something like new_model = Classifier(base_model="<model_file_name>", it tells me the base_model should be an object with "settings" rather than a string.

Or should I just load the model using new_model = Classifier.load("<model_file_name>") and do new_model.fit(train, test) directly?
Thanks!

Thanks for your interest in finetune.
The api for loading base model files saved in this way is.

new_model = Classifier(base_model=<base model object>, base_model_path=<model_file_name>)

where the base model object is whatever you set base_model to when you originally trained the model, for example Bert, RoBERTa etc. If you did not set this originally, you can ignore this argument as the default (RoBERTa) will be used.

If you wanted to use this new model frequently and wanted a cleaner api you could also do:

class NewBaseModel(RoBERTa): # replace RoBERTa with whatever model this is based on
    settings = {**RoBERTa.settings, "base_model_path": <model file name>}

new_model = Classifier(base_model=NewBaseModel)

Thank you so much!

When I use create_base_model(filename, exists_ok=False), it only allows me to save the file in the default /Finetune/finetune/model/ folder (docker version). It would be nice if I can save it to a custom path.