def test_get_vector_by_num(self): from wordvector import WordVector dictionary = { 'the': 0, 'quick': 1, 'brown': 2, 'fox': 3, 'jumped': 4, 'over': 5 } embed_matrix = np.array([[1.0, 0.1, 0.1, 0.1, 0.1, 0.1, 0.1], [1.0, 0.05, 0.1, 0.1, 0.1, 0.1, 0.1], [-1.0, 0.1, 0.1, 0.1, 0.1, 0.1, 0.1], [1.0, 0.1, 0.1, 1.1, 1.1, 1.1, 0.1], [1.0, 0.1, 0.1, 0.9, 0.9, 0.9, 0.1], [1.0, 0.1, 0.1, 1.0, 1.0, 0.8, 0.1]]) word_embedding = WordVector(embed_matrix, dictionary) self.assertTrue( np.sum( np.abs( np.array([1.0, 0.1, 0.1, 1.1, 1.1, 1.1, 0.1]) - word_embedding.get_vector_by_num(3))) < 0.1, 'incorrest closest indices') self.assertTrue( np.sum( np.abs( np.array([1.0, 0.1, 0.1, 1.0, 1.0, 0.8, 0.1]) - word_embedding.get_vector_by_num(5))) < 0.1, 'incorrest closest indices') self.assertTrue( np.sum( np.abs( np.array([1.0, 0.1, 0.1, 0.1, 0.1, 0.1, 0.1]) - word_embedding.get_vector_by_num(0))) < 0.1, 'incorrest closest indices')