From cc1ea03004bdabd8c981c6efbe84d8a54f9d59c0 Mon Sep 17 00:00:00 2001 From: Matthew Honnibal Date: Mon, 10 Dec 2018 16:09:10 +0100 Subject: [PATCH] Add test for issue #2871 -- vectors for reserved words --- spacy/tests/regression/test_issue2871.py | 27 ++++++++++++++++++++++++ 1 file changed, 27 insertions(+) create mode 100644 spacy/tests/regression/test_issue2871.py diff --git a/spacy/tests/regression/test_issue2871.py b/spacy/tests/regression/test_issue2871.py new file mode 100644 index 000000000..2b7d88c01 --- /dev/null +++ b/spacy/tests/regression/test_issue2871.py @@ -0,0 +1,27 @@ +# coding: utf8 +from __future__ import unicode_literals + +import numpy +from spacy.vectors import Vectors +from spacy.vocab import Vocab +from spacy.tokens import Doc +from spacy._ml import link_vectors_to_models + + +def test_issue2871(): + """Test that vectors recover the correct key for spaCy reserved words.""" + words = ['dog', 'cat', 'SUFFIX'] + vocab = Vocab() + vocab.vectors.resize(shape=(3, 10)) + vector_data = numpy.zeros((3, 10), dtype='f') + for word in words: + _ = vocab[word] + vocab.set_vector(word, vector_data[0]) + vocab.vectors.name = 'dummy_vectors' + link_vectors_to_models(vocab) + assert vocab['dog'].rank == 0 + assert vocab['cat'].rank == 1 + assert vocab['SUFFIX'].rank == 2 + assert vocab.vectors.find(key='dog') == 0 + assert vocab.vectors.find(key='cat') == 1 + assert vocab.vectors.find(key='SUFFIX') == 2