From d69113f4cac2b8ead8506d145a1d607d6d4e48c5 Mon Sep 17 00:00:00 2001 From: shademe Date: Fri, 18 Nov 2022 14:47:15 +0100 Subject: [PATCH] `Morphology`: Don't pickle `tags` member variable The information required to recreate the `tags` map is present in the string store, so it's not necessary to serialize it as well. --- spacy/morphology.pyx | 11 +++++------ 1 file changed, 5 insertions(+), 6 deletions(-) diff --git a/spacy/morphology.pyx b/spacy/morphology.pyx index 2c3be7b46..a07758f10 100644 --- a/spacy/morphology.pyx +++ b/spacy/morphology.pyx @@ -27,9 +27,7 @@ cdef class Morphology: self.strings = strings def __reduce__(self): - tags = set([self.get(self.strings[s]) for s in self.strings]) - tags -= set([""]) - return (unpickle_morphology, (self.strings, sorted(tags)), None, None) + return (unpickle_morphology, (self.strings,), None, None) cdef shared_ptr[MorphAnalysisC] _lookup_tag(self, hash_t tag_hash): match = self.tags.find(tag_hash) @@ -244,8 +242,9 @@ cdef int get_n_by_field(attr_t* results, const shared_ptr[MorphAnalysisC] morph, n_results += 1 return n_results -def unpickle_morphology(strings, tags): +def unpickle_morphology(strings): cdef Morphology morphology = Morphology(strings) - for tag in tags: - morphology.add(tag) + # Repopulate the tag map. + for string in strings: + morphology.add(string) return morphology