Fix head alignment in GoldParse

This commit is contained in:
Matthew Honnibal 2018-04-03 01:54:45 +02:00
parent 88de8fe323
commit 9c5c940441

View File

@ -451,17 +451,11 @@ cdef class GoldParse:
annot_tuples = (range(len(words)), words, tags, heads, deps, entities)
self.orig_annot = list(zip(*annot_tuples))
if words is not None:
self.words = self._alignment.to_yours(words)
if tags is not None:
self.tags = self._alignment.to_yours(tags)
if deps is not None:
self.labels = self._alignment.to_yours(deps)
if tags is not None:
self.tags = self._alignment.to_yours(tags)
if entities is not None:
self.ner = self._alignment.to_yours(entities)
if heads is not None:
for gold_i, gold_head in enumerate(heads):
if gold_head is None:
continue
@ -474,8 +468,12 @@ cdef class GoldParse:
elif isinstance(cand_i, list):
for sub_i in cand_i[:-1]:
self.heads[sub_i] = sub_i+1
if isinstance(cand_head, list):
self.heads[cand_i[-1]] = cand_head[-1]
else:
self.heads[cand_i[-1]] = cand_head
elif isinstance(cand_i, tuple):
elif isinstance(cand_i, tuple) and isinstance(cand_head, int):
# We only handle one-to-many or many-to-one, not many-to-many
cand_i, sub_i = cand_i
if not isinstance(self.heads[cand_i], list):
self.heads[cand_i] = []
@ -500,7 +498,7 @@ cdef class GoldParse:
self.labels[i] = self.labels[i][0]
else:
self.labels[i] = 'subtok'
self.heads[i] = i+1
#self.heads[i] = i+1
cycle = nonproj.contains_cycle(self._alignment.flatten(self.heads))
if cycle is not None: