Extract probabilities for custom ner model #8451
Answered
by
polm
kalyanm2305
asked this question in
Help: Coding & Implementations
-
I trained a custom entity recognizer to extract products from a webpage and it does well. import sys
from collections import defaultdict
beam_width = 16
beam_density = 0.0001
nlp = spacy.load("./output/model-best")
with nlp.disable_pipes('ner'):
docs = list(nlp.pipe(texts))
print(docs)
beams = nlp.entity.beam_parse(docs, beam_width=beam_width, beam_density=beam_density)
for doc, beam in zip(docs, beams):
entity_scores = defaultdict(float)
for score, ents in nlp.entity.moves.get_beam_parses(beam):
for start, end, label in ents:
entity_scores[(start, end, label)] += score
print ('Entities and scores (detected with beam search)')
for key in entity_scores:
start, end, label = key
score = entity_scores[key]
if ( score > 0.01):
print ('Label: {}, Text: {}, Score: {}'.format(label, doc[start:end], score)) |
Beta Was this translation helpful? Give feedback.
Answered by
polm
Jun 21, 2021
Replies: 1 comment 3 replies
-
This is not supported at the moment, see #5917. The upcoming SpanCategorizer linked in that issue should provide this functionality. |
Beta Was this translation helpful? Give feedback.
3 replies
Answer selected by
polm
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
This is not supported at the moment, see #5917. The upcoming SpanCategorizer linked in that issue should provide this functionality.