Ejemplo n.º 1
0
def test_internals_api(n_components):
    callback = CustomCallback()
    reducer = UMAP(n_components=n_components, callback=callback)
    reducer.fit(data)
    callback.check()

    # Make sure super().__init__ is called
    callback = CustomCallback(skip_init=True)
    model = UMAP(n_epochs=10, callback=callback)

    with pytest.raises(ValueError):
        model.fit_transform(data)
Ejemplo n.º 2
0
    def reduce_dimensionality(self, embeddings):
        """Reduce dimensionality of embeddings using UMAP and train a UMAP model

        Args:
            embeddings (cupy.ndarray): The extracted embeddings using the
            sentence transformer module.

        Returns:
            umap_embeddings: The reduced embeddings
        """
        m_cos = NearestNeighbors(n_neighbors=15, metric="cosine")
        m_cos.fit(embeddings)
        knn_graph_cos = m_cos.kneighbors_graph(embeddings, mode="distance")
        u1 = UMAP(n_neighbors=15, n_components=5, min_dist=0.0)
        umap_embeddings = u1.fit_transform(embeddings, knn_graph=knn_graph_cos)

        return umap_embeddings