I have trained a model and when I attempt to load it I get the following error:
AttributeError: type object 'TextClassifier' has no attribute 'load_from_file'
NOTE: The model file exists in the current directory and is called _best-model.pt_
Code Snippet:
from flair.models import TextClassifier
def make_prediction(model_location="./best-model.pt"):
# Load the classifier that was created
classifier = TextClassifier.load_from_file('resources/taggers/ag_news/final-model.pt')
sent = ["FREE entry into our 拢250 weekly comp just send the word WIN to 80086 NOW. 18 T&C www.txttowin.co.uk"]
# Convert into format classifier understands
sentence = Sentence(sent)
classifier.predict(sentence)
# Format the outputs labels to be easier to read
print(sentence.labels)
print()
label = str(sentence.labels[0]).split()[0]
print(f"{label}\t{sentence}")
make_prediction()
I spent a long time attempting to troubleshoot this on my own. I hope raising this issue here is appropriate. If not please let me know where I should have posted it and I will move it or delete and reupload accordingly.
Thank you!
Hi @darien-schettler ,
I believe you are using Flair v0.4.2 . In the new release the function was refactored. Please use TextClassifier.load('resources/taggers/ag_news/final-model.pt')
This can be seen from the release notes https://github.com/zalandoresearch/flair/releases
I hope that helps and answers your question
Thank you!
Yes sorry about that, just updated the tutorial to reflect this change!
聽:ok_hand:
Most helpful comment
Hi @darien-schettler ,
I believe you are using Flair v0.4.2 . In the new release the function was refactored. Please use TextClassifier.load('resources/taggers/ag_news/final-model.pt')
This can be seen from the release notes https://github.com/zalandoresearch/flair/releases
I hope that helps and answers your question