Fix sent_start multi-task objective when alignment fails

This commit is contained in:
Matthew Honnibal 2018-02-23 16:50:59 +01:00
parent 5fa44e93f1
commit 4492a33a9d
1 changed files with 8 additions and 9 deletions

View File

@ -761,19 +761,18 @@ 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:
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)
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: