Allow Example to align whitespace annotation (#10189)

Remove exception for whitespace tokens in `Example.get_aligned` so that
annotation on whitespace tokens is aligned in the same way as for
non-whitespace tokens.
This commit is contained in:
Adriane Boyd 2022-02-03 17:01:53 +01:00 committed by GitHub
parent 2abd380f2d
commit fef896ce49
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 19 additions and 12 deletions

View File

@ -421,3 +421,13 @@ def test_Example_missing_heads():
# Ensure that the missing head doesn't create an artificial new sentence start
expected = [True, False, False, False, False, False]
assert example.get_aligned_sent_starts() == expected
def test_Example_aligned_whitespace(en_vocab):
words = ["a", " ", "b"]
tags = ["A", "SPACE", "B"]
predicted = Doc(en_vocab, words=words)
reference = Doc(en_vocab, words=words, tags=tags)
example = Example(predicted, reference)
assert example.get_aligned("TAG", as_string=True) == tags

View File

@ -159,9 +159,6 @@ cdef class Example:
gold_values = self.reference.to_array([field])
output = [None] * len(self.predicted)
for token in self.predicted:
if token.is_space:
output[token.i] = None
else:
values = gold_values[align[token.i].dataXd]
values = values.ravel()
if len(values) == 0: