From 4492a33a9d4480d589ef3134ab9161171e7e97c1 Mon Sep 17 00:00:00 2001 From: Matthew Honnibal Date: Fri, 23 Feb 2018 16:50:59 +0100 Subject: [PATCH] Fix sent_start multi-task objective when alignment fails --- spacy/pipeline.pyx | 17 ++++++++--------- 1 file changed, 8 insertions(+), 9 deletions(-) diff --git a/spacy/pipeline.pyx b/spacy/pipeline.pyx index 760edc9cc..8405e1310 100644 --- a/spacy/pipeline.pyx +++ b/spacy/pipeline.pyx @@ -761,20 +761,19 @@ class MultitaskObjective(Tagger): sent_tags = ['I-SENT'] * len(words) def _find_root(child): - while heads[child] != child: - if heads[child] is None: - if child == 0: - return child - else: - child -= 1 - else: - child = heads[child] + seen = set([child]) + while child is not None and heads[child] != child: + seen.add(child) + child = heads[child] return child sentences = {} for i in range(len(words)): root = _find_root(i) - sentences.setdefault(root, []).append(i) + if root is None: + sent_tags[i] = None + else: + sentences.setdefault(root, []).append(i) for root, span in sorted(sentences.items()): if len(span) == 1: sent_tags[span[0]] = 'U-SENT'