test/python/testembeddings.py
def testWords(self):
        """
        Test embeddings backed by word vectors
        """

        # Initialize model path
        path = os.path.join(tempfile.gettempdir(), "model")
        os.makedirs(path, exist_ok=True)

        # Build tokens file
        with tempfile.NamedTemporaryFile(mode="w", delete=False) as output:
            tokens = output.name
            for x in self.data:
                output.write(x + "\n")

        # Word vectors path
        vectors = os.path.join(path, "test-300d")

        # Build word vectors, if they don't already exist
        WordVectors.build(tokens, 300, 1, vectors)

        # Create dataset
        data = [(x, row, None) for x, row in enumerate(self.data)]

        # Create embeddings model, backed by word vectors
        embeddings = Embeddings({"path": vectors + ".magnitude",
                                 "storevectors": True,
                                 "scoring": "bm25",
                                 "pca": 3,
                                 "quantize": True})

        # Call scoring and index methods
        embeddings.score(data)
        embeddings.index(data)

        # Test search
        self.assertIsNotNone(embeddings.search("win", 1))

        Test embeddings backed by word vectors
        
Test embeddings backed by word vectors
Test embeddings backed by word vectors
def testWords(self):
        path = os.path.join(tempfile.gettempdir(), "model")
        os.makedirs(path, exist_ok=True)
        with tempfile.NamedTemporaryFile(mode="w", delete=False) as output:
            tokens = output.name
            for x in self.data:
                output.write(x + "\n")
        vectors = os.path.join(path, "test-300d")
        WordVectors.build(tokens, 300, 1, vectors)
        data = [(x, row, None) for x, row in enumerate(self.data)]
        embeddings = Embeddings({"path": vectors + ".magnitude",
                                 "storevectors": True,
                                 "scoring": "bm25",
                                 "pca": 3,
                                 "quantize": True})
        embeddings.score(data)
        embeddings.index(data)
        self.assertIsNotNone(embeddings.search("win", 1))
def testWords ( self ) : path = os . path . join ( tempfile . gettempdir ( ) , "model" ) os . makedirs ( path , exist_ok = True ) with tempfile . NamedTemporaryFile ( mode = "w" , delete = False ) as output : tokens = output . name for x in self . data : output . write ( x + "\n" ) vectors = os . path . join ( path , "test-300d" ) WordVectors . build ( tokens , 300 , 1 , vectors ) data = [ ( x , row , None ) for x , row in enumerate ( self . data ) ] embeddings = Embeddings ( { "path" : vectors + ".magnitude" , "storevectors" : True , "scoring" : "bm25" , "pca" : 3 , "quantize" : True } ) embeddings . score ( data ) embeddings . index ( data ) self . assertIsNotNone ( embeddings . search ( "win" , 1 ) )
Test embeddings backed by word vectors
Test embeddings backed by word vectors
"""
        Test embeddings backed by word vectors
        """ # Initialize model path # Build tokens file # Word vectors path # Build word vectors, if they don't already exist # Create dataset # Create embeddings model, backed by word vectors # Call scoring and index methods # Test search
self