From 59b7cf9db8bd3e150141d13d869592eef2573601 Mon Sep 17 00:00:00 2001 From: Matthew Honnibal Date: Thu, 15 Feb 2018 21:03:16 +0100 Subject: [PATCH] Add get_beam_parse method in ArcEager, for Prodigy --- spacy/syntax/arc_eager.pyx | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/spacy/syntax/arc_eager.pyx b/spacy/syntax/arc_eager.pyx index 16d55db24..190155269 100644 --- a/spacy/syntax/arc_eager.pyx +++ b/spacy/syntax/arc_eager.pyx @@ -390,6 +390,22 @@ cdef class ArcEager(TransitionSystem): gold.c.labels[i] = self.strings.add(label) return gold + def get_beam_parses(self, Beam beam): + parses = [] + probs = beam.probs + for i in range(beam.size): + state = beam.at(i) + if state.is_final(): + self.finalize_state(state) + prob = probs[i] + parse = [] + for j in range(state.length): + head = state.H(j) + label = self.strings[state._sent[j].dep] + parse.append((head, j, label)) + parses.append((prob, parse)) + return parses + cdef Transition lookup_transition(self, object name) except *: if '-' in name: move_str, label_str = name.split('-', 1)