Closed not-william closed 4 years ago
Hello,
This may have something to do with the fact that ktrain was updated a while ago (after you trained your model) to instantiate the tokenizer "on-the-fly" instead of saving it as part of the the Preprocessor instance (i.e., Transformer
object). This was done because some tokenizers in transformers
library are not easily pickable (and it also results in a smaller Predictor footprint).
EDIT: I tried to reproduce the error by training a model and saving a predictor using a very old version of ktrain and then reloading and predicting using a newer version. But, everything worked correctly, so not sure what's happening on your end. You can try the steps below to try and fix things, though.
Can you try the following?
# load just the model
from transformers import *
model = TFAutoModelForSequenceClassification.from_pretrained('multiclass_predictor')
print(model.summary())
Does the model load correctly? If so, then the problem should be easy to fix, as you can re-create your predictor using this loaded model and then re-save your predictor using the latest version of ktrain (all without having to re-train your model). Upon doing so, you will be able to use the predictor
normally to make predictions using the newest version of ktrain.
Please let me know the output of the above code. Also, make sure you're using the latest version of ktrain.
Many thanks, it was indeed a version issue. The original code
predictor = ktrain.load_predictor('multiclass_predictor')
predictor.predict(["This is a test sentence"])
works after upgrading to the latest version, so the machine I trained the model on must have had a higher version installed. Thanks again.
I've previously trained a BERT text classification model and saved the predictor using
predictor.save()
. However, when it comes to loading up the predictor, I get the following error.Any feedback greatly appreciated. Thanks.