From 27abc56e98fc77667d69006746e1d4f1ce97f830 Mon Sep 17 00:00:00 2001 From: Matthew Honnibal Date: Sat, 29 Jul 2017 21:59:02 +0200 Subject: [PATCH] Add method to get beam entities --- spacy/syntax/ner.pyx | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/spacy/syntax/ner.pyx b/spacy/syntax/ner.pyx index 023707aaa..d15de0181 100644 --- a/spacy/syntax/ner.pyx +++ b/spacy/syntax/ner.pyx @@ -141,6 +141,23 @@ cdef class BiluoPushDown(TransitionSystem): entities[(start, end, label)] += prob return entities + def get_beam_parses(self, Beam beam): + parses = [] + probs = beam.probs + for i in range(beam.size): + stcls = beam.at(i) + if stcls.is_final(): + self.finalize_state(stcls.c) + prob = probs[i] + parse = [] + for j in range(stcls.c._e_i): + start = stcls.c._ents[j].start + end = stcls.c._ents[j].end + label = stcls.c._ents[j].label + parse.append((start, end, self.strings[label])) + parses.append((prob, parse)) + return parses + cdef Transition lookup_transition(self, object name) except *: cdef attr_t label if name == '-' or name == None: