diff --git a/spacy/errors.py b/spacy/errors.py index 043859d29..a69a74bb7 100644 --- a/spacy/errors.py +++ b/spacy/errors.py @@ -457,6 +457,9 @@ class Errors: "issue tracker: http://github.com/explosion/spaCy/issues") # TODO: fix numbering after merging develop into master + E896 = ("There was an error using the static vectors. Ensure that the vectors " + "of the vocab are properly initialized, or set 'include_static_vectors' " + "to False.") E897 = ("Field '{field}' should be a dot-notation string referring to the " "relevant section in the config, but found type {type} instead.") E898 = ("Can't serialize trainable pipe '{name}': the `model` attribute " diff --git a/spacy/ml/staticvectors.py b/spacy/ml/staticvectors.py index f0213a9b8..71d825905 100644 --- a/spacy/ml/staticvectors.py +++ b/spacy/ml/staticvectors.py @@ -42,9 +42,13 @@ def forward( rows = model.ops.flatten( [doc.vocab.vectors.find(keys=doc.to_array(key_attr)) for doc in docs] ) + try: + vectors_data = model.ops.gemm(model.ops.as_contig(V[rows]), W, trans2=True) + except ValueError: + raise RuntimeError(Errors.E896) output = Ragged( - model.ops.gemm(model.ops.as_contig(V[rows]), W, trans2=True), - model.ops.asarray([len(doc) for doc in docs], dtype="i"), + vectors_data, + model.ops.asarray([len(doc) for doc in docs], dtype="i") ) mask = None if is_train: diff --git a/spacy/training/initialize.py b/spacy/training/initialize.py index 3d79eb78f..6f9896492 100644 --- a/spacy/training/initialize.py +++ b/spacy/training/initialize.py @@ -103,7 +103,7 @@ def load_vectors_into_model( "with the packaged vectors. Make sure that the vectors package you're " "loading is compatible with the current version of spaCy." ) - err = ConfigValidationError.from_error(e, config=None, title=title, desc=desc) + err = ConfigValidationError.from_error(e, title=title, desc=desc) raise err from None nlp.vocab.vectors = vectors_nlp.vocab.vectors if add_strings: