Spacy Confidence Score in SpanCategorizer

1.4k Views Asked by At

I have trained a Spacy nlp model with a 'spancat' model. For testing the model, I have added the code below for prediction of spans and label

nlp = spacy.load('output_/model-best')
rest = 'The book was of red colour'
doc1 = nlp(rest)
print(doc1.spans) #To get predicted span
span = doc1.spans['sc'][0] 
print(span.label_) # to get label

How can I also get the confidence score for prediction of the spans?

1

There are 1 best solutions below

0
On BEST ANSWER

You can get the score directly from the span group, using the scores attribute. For example:

doc = nlp("your text here")
spans = doc.spans["sc"]
for span, confidence in zip(spans, spans.attrs["scores"]):
    print(span.label_, confidence)