Ejemplo n.º 1
0
 def test_most_common(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.5, 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.6, 0.1, 1.1, 1.1, 1.1, 0.1],
                              [1.0, 0.7, 0.1, 1.1, 1.1, 1.1, 0.1]])
     word_embedding = WordVector(embed_matrix, dictionary)
     mc_list = word_embedding.most_common(3)
     self.assertEqual(['the', 'quick', 'brown'], mc_list,
                      'wrong most common words returned')
     mc_list = word_embedding.most_common(1)
     self.assertEqual(['the'], mc_list, 'wrong most common words returned')