Classification Prediction using encoder of text_classifier_learner

Once a trained / fine tuned encoder is saved, what is the right way to load the encoder for prediction?

say a learner is defined as
leaner=text_classifier_learner(data_clas, drop_mult=0.5)

saved encoder was ‘fine_tuned_enc_1’

now doe we load the encoder by



learner.load(‘fine_tuned_enc_1’) ???

1 Like

Once you have trained your classifier, you should save the model, so then learner.load.

Thanks @sgugger,

I am experimenting with lesson3: imdb notebook.
My language-model learner is trained and saved, the encoder is also saved (as ‘fine_tuned_enc’).
Now in the classification part of the notebook, where we create a text_classifier_learner, should I load ‘fine_tuned_enc’ using learner.load or leaner.load_encoder?
The notebook uses load_encoder initially but later after some freeze_to and trainings it uses and learner.load (not load_encoder). Hence the question.

Many thanks again

When you are initializing the weights of your classifier, you should use load_encoder to load the language model you fine-tuned. Later, once you have fitted your model, you should use load.

Thank you sir,
If one uses load_decoder, the prediction results are terrible.
For example:
learn.predict(“It was awful,terribly worse than I could have imagined”)>>(Category neg, tensor(0), tensor([0.5442, 0.4558])) :joy::thinking:

Hi @sam2 I woul like to know once I have exported the model in the export.pkl file, what code should I use to load in a new python file the model to make a classification of one review?

I tried:

from import *
from import *
from utils import *
learn = load_learner(path/‘export.pkl’, cpu=True)
learn.path = path
learn.predict(“you suck”)

FileNotFoundError: [Errno 2] No such file or directory: ‘you suck’