-
Notifications
You must be signed in to change notification settings - Fork 289
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Vector Embeddings --> UMAP projections of nodes for organizing within 2 or 3-D space. #522
Comments
so...you want to reduce the dimensionality of your embeddings and visualize them in 2D/3D? something like this would do:
Step 1: Set Up Your Next.js AppIf you haven't already, create a Next.js app: npx create-next-app@latest my-3d-graph-app
cd my-3d-graph-app
npm install Step 2: Install DependenciesInstall the necessary dependencies: npm install ml-pca 3d-force-graph react-three-fiber three Step 3: Create the ComponentCreate a file called import { useState, useEffect, useRef } from 'react';
import Head from 'next/head';
import PCA from 'ml-pca';
import ForceGraph3D from '3d-force-graph';
const performPCA = (data) => {
const pca = new PCA(data);
const reducedData = pca.predict(data, { nComponents: 3 }).to2DArray();
return reducedData.map(([x, y, z]) => ({ x, y, z }));
};
export default function Home() {
const [data, setData] = useState({ nodes: [], links: [] });
const containerRef = useRef();
useEffect(() => {
const fetchEmbeddings = async () => {
const response = await fetch('/embeddings.json');
const embeddings = await response.json();
const reducedEmbeddings = performPCA(embeddings);
const nodes = reducedEmbeddings.map((emb, id) => ({
id: id.toString(),
x: emb.x,
y: emb.y,
z: emb.z,
}));
const links = []; // Define your links if you have any
setData({ nodes, links });
};
fetchEmbeddings();
}, []);
useEffect(() => {
if (data.nodes.length > 0) {
const graph = ForceGraph3D()(containerRef.current)
.graphData(data)
.nodeAutoColorBy('id');
return () => {
graph._destructor();
};
}
}, [data]);
return (
<div>
<Head>
<title>3D Graph</title>
<link rel="icon" href="/favicon.ico" />
</Head>
<div ref={containerRef} style={{ width: '100%', height: '100vh' }} />
</div>
);
} Step 4: Add
|
I came across this repository looking for a force-directed network engine I could render in a next js app... I have a large network I'm looking to render, and would like to define a custom function (or utilize some existing tool) that uses force directed behavior in combination with spatial projection of UMAP from vector embeddings of node ids...
Is there an established method, or integration with this react repo, for achieving this? Thanks!
The text was updated successfully, but these errors were encountered: