diff --git a/spacy/gold.pyx b/spacy/gold.pyx index 13e448342..5aa7da456 100644 --- a/spacy/gold.pyx +++ b/spacy/gold.pyx @@ -1050,6 +1050,12 @@ cdef class GoldParse: # avoid allocating memory if the doc does not contain any tokens if self.length == 0: + self.words = [] + self.tags = [] + self.heads = [] + self.labels = [] + self.ner = [] + self.morphs = [] # set a minimal orig so that the scorer can score an empty doc self.orig = TokenAnnotation(ids=[]) else: diff --git a/spacy/tests/regression/test_issue5137.py b/spacy/tests/regression/test_issue5137.py index 4b4e597d3..e9fd268c8 100644 --- a/spacy/tests/regression/test_issue5137.py +++ b/spacy/tests/regression/test_issue5137.py @@ -21,7 +21,8 @@ def test_issue5137(): def from_disk(self, path, **cfg): pass - Language.factories["my_component"] = lambda nlp, **cfg: MyComponent(nlp, **cfg) + factory = lambda nlp, model, **cfg: MyComponent(nlp, **cfg) + Language.factories["my_component"] = factory nlp = English() nlp.add_pipe(nlp.create_pipe("my_component"))