Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
yangliu2 opened this issue Nov 4, 2020 · 4 comments
Open

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

yangliu2 opened this issue Nov 4, 2020 · 4 comments
Assignees
Labels
enhancement New feature or request

Comments

@yangliu2
Copy link

yangliu2 commented Nov 4, 2020

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!

@benleetownsend
Copy link
Contributor

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.

@benleetownsend
Copy link
Contributor

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)

@benleetownsend benleetownsend self-assigned this Nov 7, 2020
@yangliu2
Copy link
Author

yangliu2 commented Nov 9, 2020

Thank you so much!

@yangliu2 yangliu2 closed this as completed Nov 9, 2020
@yangliu2
Copy link
Author

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.

@yangliu2 yangliu2 reopened this Nov 13, 2020
@benleetownsend benleetownsend added the enhancement New feature or request label Nov 19, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

2 participants