TLWalk is a community-aware graph embedding method integrated into the Karate Club library. TLWalk enhances node representations by explicitly considering intra-community and inter-community relationships using a two-layer hierarchical random walk strategy.
- Community-Aware Embedding: Explicitly integrates hierarchical community structures.
- Intra-Community and Inter-Community Dynamics: Models both dense local relationships and sparse global structures.
- Seamless Integration: TLWalk is compatible with the Karate Club graph embedding library and can be used directly for various graph tasks.
- Scalability: Efficient on large-scale networks with a clear modular design.
-
Install the Karate Club library using
pip
:pip install karateclub
-
Clone the TLWalk repository to access the relevant scripts:
git clone https://github.com/yourusername/TLWalk.git cd TLWalk
Edge files must follow the standard .edges
format:
- Each line represents an edge:
<node_1> <node_2>
(space-separated). - Example:
0 1 1 2 2 3 0 3
Supported datasets are stored in the input/
directory.
Preprocess your graph data to ensure compatibility:
python preprocess.py
Run TLWalk to generate graph embeddings:
python _TwoLayerCommunityWalk.py
Evaluate TLWalk embeddings for link prediction:
python link_prediction.py
Evaluate node classification performance:
python node_classification_c.py
Once TLWalk is integrated into the Karate Club library, it can be used as follows:
from karateclub import TwoLayerCommunityWalk
import networkx as nx
# Load a graph
G = nx.karate_club_graph()
# Initialize the model
model = TwoLayerCommunityWalk(dimensions=128, walk_length=10, num_walks=80)
# Fit the model
model.fit(G)
# Generate embeddings
embeddings = model.get_embedding()
print(embeddings)
TLWalk/
│-- input/ # Input graph datasets (.edges files)
│ │-- bio-WormNet-v3.edges
│ │-- ego-Facebook.edges
│ │-- ...
│
│-- _TwoLayerCommunityWalk.py # Main TLWalk embedding implementation
│-- preprocess.py # Preprocessing script for input graphs
│-- link_prediction.py # Script for link prediction
│-- node_classification_c.py # Script for node classification
│
│-- output/ # Generated embeddings and results
│-- results/ # Task results (accuracy, AUC, etc.)
If you use TLWalk in your research, please cite our work:
@misc{yu2024layerwalkcommunityawaregraph,
title={Two Layer Walk: A Community-Aware Graph Embedding},
author={He Yu and Jing Liu},
year={2024},
eprint={2412.12933},
archivePrefix={arXiv},
primaryClass={cs.SI},
url={https://arxiv.org/abs/2412.12933},
}
This project is released under the MIT License.
For questions or contributions, please open an issue or contact He Yu at [email protected].