diff --git a/spacy/errors.py b/spacy/errors.py index b124fc88c..e0ddc86c5 100644 --- a/spacy/errors.py +++ b/spacy/errors.py @@ -552,6 +552,9 @@ class Errors(object): E191 = ("Invalid head: the head token must be from the same doc as the " "token itself.") E192 = ("Unable to resize vectors in place with cupy.") + E193 = ("Unable to resize vectors in place if the resized vector dimension " + "({new_dim}) is not the same as the current vector dimension " + "({curr_dim}).") @add_codes diff --git a/spacy/vectors.pyx b/spacy/vectors.pyx index 5b8512970..f3c20fb7f 100644 --- a/spacy/vectors.pyx +++ b/spacy/vectors.pyx @@ -200,6 +200,8 @@ cdef class Vectors: """ xp = get_array_module(self.data) if inplace: + if shape[1] != self.data.shape[1]: + raise ValueError(Errors.E193.format(new_dim=shape[1], curr_dim=self.data.shape[1])) if xp == numpy: self.data.resize(shape, refcheck=False) else: