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

Best way to use a finetuned/customised LM for downstream task e.g. sequence classification? #48

Closed
yijinlee opened this issue Jul 29, 2021 · 2 comments

Comments

@yijinlee
Copy link

Hi,

Starting from pretrained GPT2 hf_model, I finetuned a custom LM using unlabelled dataset, using the model_cls = AutoModelForCausalLM method, and have saved/exported the resulting Learner object (let's call that finetuned_LM_learn).

What is the best way for me to then load that finetuned LM, and use it for downstream task (e.g. sequence classification) on labelled dataset? Should I just go through the same steps here, and then switch out the base_model before starting to train? Something like below?

learn.model.hf_model.base_model = finetuned_LM_learn.model.hf_model.base_model
learn.fit_one_cycle(epoch, lr)

Or is that not the correct / best way? Thanks.

@yijinlee
Copy link
Author

Ok I think I should be using finetuned_LM_learn.hf_model.save_pretrained(path) and then for downstream classification task do AutoModelForSequenceClassification.from_pretrained(path) instead. Please do correct me if I am wrong.. Thank you.

@ohmeow
Copy link
Owner

ohmeow commented Aug 29, 2021

Yup. That is correct.

Just use the transformer model's save_pretrained to the path you want to save your HF artifacts in (you should do the same with the tokenizer) and the use as you are above.

@ohmeow ohmeow closed this as completed Aug 29, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants