mirror of https://github.com/explosion/spaCy.git
Fix sent_start multi-task objective when alignment fails
This commit is contained in:
parent
5fa44e93f1
commit
4492a33a9d
|
@ -761,20 +761,19 @@ class MultitaskObjective(Tagger):
|
||||||
sent_tags = ['I-SENT'] * len(words)
|
sent_tags = ['I-SENT'] * len(words)
|
||||||
|
|
||||||
def _find_root(child):
|
def _find_root(child):
|
||||||
while heads[child] != child:
|
seen = set([child])
|
||||||
if heads[child] is None:
|
while child is not None and heads[child] != child:
|
||||||
if child == 0:
|
seen.add(child)
|
||||||
return child
|
child = heads[child]
|
||||||
else:
|
|
||||||
child -= 1
|
|
||||||
else:
|
|
||||||
child = heads[child]
|
|
||||||
return child
|
return child
|
||||||
|
|
||||||
sentences = {}
|
sentences = {}
|
||||||
for i in range(len(words)):
|
for i in range(len(words)):
|
||||||
root = _find_root(i)
|
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()):
|
for root, span in sorted(sentences.items()):
|
||||||
if len(span) == 1:
|
if len(span) == 1:
|
||||||
sent_tags[span[0]] = 'U-SENT'
|
sent_tags[span[0]] = 'U-SENT'
|
||||||
|
|
Loading…
Reference in New Issue