Пример #1
0
    def testNoExist(self):
        """
        Test loading model that doesn't exist
        """

        # Test non-existent path raises an exception
        with self.assertRaises(IOError):
            Vectors.create({"path": os.path.join(tempfile.gettempdir(), "noexist")}, None)
Пример #2
0
    def testBlocking(self):
        """
        Test blocking load of vector model
        """

        config = {"path": self.path}
        model = Vectors.create(config, None)

        self.assertFalse(model.initialized)

        config["ids"] = ["0", "1"]
        config["dimensions"] = 300
        model = Vectors.create(config, None)

        self.assertTrue(model.initialized)
Пример #3
0
    def testTransform(self):
        """
        Test word vector transform
        """

        model = Vectors.create({"path": self.path}, None)
        self.assertEqual(len(model.transform((None, ["txtai"], None))), 300)
Пример #4
0
    def testLookup(self):
        """
        Test word vector lookup
        """

        model = Vectors.create({"path": self.path}, None)
        self.assertEqual(model.lookup(["txtai", "embeddings", "sentence"]).shape, (3, 300))
Пример #5
0
    def setUpClass(cls):
        """
        Create single TransformersVectors instance
        """

        cls.model = Vectors.create(
            {
                "method": "transformers",
                "path": "sentence-transformers/bert-base-nli-mean-tokens"
            }, None)
Пример #6
0
    def testNotImplemented(self):
        """
        Tests exceptions for non-implemented methods
        """

        vectors = Vectors(None, None)

        self.assertRaises(NotImplementedError, vectors.load, None)
        self.assertRaises(NotImplementedError, vectors.index, None)
        self.assertRaises(NotImplementedError, vectors.transform, None)
Пример #7
0
    def testIndex(self):
        """
        Test word vector indexing
        """

        # Generate data
        documents = [(x, "This is a test", None) for x in range(1000)]

        model = Vectors.create({"path": self.path}, None)

        ids, dimension, stream = model.index(documents)

        self.assertEqual(len(ids), 1000)
        self.assertEqual(dimension, 300)
        self.assertIsNotNone(os.path.exists(stream))