Implementation of the graph2vec algorithm
Project description
graph2emb
Elior Cohen의 node2vec, graph2vec를 참고해 Node2Vec + Graph2Vec 기능을 한 프로젝트로 합친 구현체입니다.
특징
- Node2Vec: 랜덤 워크 기반 노드 임베딩
- Edge embedding: (Hadamard/평균/L1/L2) 방식의 엣지 임베딩
- Graph2Vec: WL(Weisfeiler–Lehman) hashing + Doc2Vec 기반 그래프 임베딩
- uv 기반 개발/실행
파이썬 모듈 이름은
graph2emb입니다.
빠른 시작 (sample 실행)
# 의존성/프로젝트 설치
uv sync
# Node2Vec (edge list 로드)
uv run python sample/node2vec_from_edgelist.py
# Node2Vec + edge embedding
uv run python sample/node2vec_edge_embeddings.py
# Graph2Vec
uv run python sample/graph2vec_basic.py
샘플 설명은 sample/README.md를 참고하세요.
사용 예시 (코드)
Node2Vec (노드 임베딩)
import networkx as nx
from graph2emb import Node2Vec
g = nx.fast_gnp_random_graph(n=100, p=0.3, seed=42)
node2vec = Node2Vec(g, dimensions=64, walk_length=30, num_walks=20, workers=1, seed=42)
model = node2vec.fit(window=10, min_count=1, epochs=5)
print(model.wv.most_similar("2", topn=5)) # 노드 id는 문자열로 조회
Edge embedding (엣지 임베딩)
from graph2emb.edges import HadamardEmbedder
edges_embs = HadamardEmbedder(model.wv)
print(edges_embs[("1", "2")])
Graph2Vec (그래프 임베딩)
import networkx as nx
from graph2emb import Graph2Vec
graphs = [
nx.fast_gnp_random_graph(n=12, p=0.3, seed=1),
nx.fast_gnp_random_graph(n=14, p=0.2, seed=2),
]
g2v = Graph2Vec(dimensions=32, workers=1, min_count=1, epochs=3, seed=42)
g2v.fit(graphs)
emb = g2v.get_embedding() # shape: (len(graphs), dimensions)
개발/테스트
# 테스트 실행
uv run pytest
# 병렬 테스트
uv run pytest -n auto
# 커버리지 포함 테스트 실행
uv run pytest --cov=graph2emb --cov-report=html
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
graph2emb-0.9.0.tar.gz
(27.8 kB
view details)
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
graph2emb-0.9.0-py3-none-any.whl
(22.9 kB
view details)
File details
Details for the file graph2emb-0.9.0.tar.gz.
File metadata
- Download URL: graph2emb-0.9.0.tar.gz
- Upload date:
- Size: 27.8 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: uv/0.9.30 {"installer":{"name":"uv","version":"0.9.30","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"macOS","version":null,"id":null,"libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":null}
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
2e8fba1190ebf629e0d57999450298d6a7ec6b6593c89f6c4f57b437629f544d
|
|
| MD5 |
d4dcda82d2ef4c5bc15dce024b3cb1c5
|
|
| BLAKE2b-256 |
ac1c1efad6b238713a6ae12f652a6d0f7600e63ba092d2be02ac79dcabd50b1c
|
File details
Details for the file graph2emb-0.9.0-py3-none-any.whl.
File metadata
- Download URL: graph2emb-0.9.0-py3-none-any.whl
- Upload date:
- Size: 22.9 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: uv/0.9.30 {"installer":{"name":"uv","version":"0.9.30","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"macOS","version":null,"id":null,"libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":null}
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
9af59bb86178820888687f7bb0b24197ba0beb48ba34eaec3343222200b4d440
|
|
| MD5 |
afb7d0355a519200cc2b172284a1f00a
|
|
| BLAKE2b-256 |
f48fcdca88fa91d5237fdd11e069896bfb4478e6233bd5163dbaa6074fdfb3e2
|