Here is how I created the model and how I am testing it. For the life of me, I can't figure out why it's returning an empty dictionary without any predictions.
I used prodigy to annotate some data using spans.
python -m prodigy spans.manual test_model_1 blank:en test_data.txt --label label1,label2,label3
Then I created the model.
python -m prodigy train ./test_model_1 --spancat test_model_1
Lastly, I tried multiple ways to get predictions with the model with test text. This is the code that returns an empty dictionary.
import spacy
from spacy.tokens import Doc
# Define a function to get all possible predictions for a document
def get_all_cats(doc):
return {cat: doc._.cats[cat].cats.items() for cat in doc._.cats}
# Load the model
nlp = spacy.load("test_model_1/model-best")
# Add the 'cats' and 'all_cats' extensions to the Doc class
Doc.set_extension("cats", default={}, force=True)
Doc.set_extension("all_cats", getter=get_all_cats)
# The text to analyze
text = "This is a sample sentence to get predictions on."
# Process the text with the model
doc = nlp(text)
# Get all possible predictions for the document
predictions = doc._.all_cats
# Print the predictions
print(predictions)
My Environment
- spaCy version 3.5.1
- Platform Windows-10
- Python version 3.10.4
- en_core_web_sm 3.5.0