Skip to content

A lightweight implementation of TLWalk: A Community-Aware Graph Embedding algorithm for capturing both local and global network structures effectively.

Notifications You must be signed in to change notification settings

leonyuhe/TLWalk

Repository files navigation

Two Layer Community Walk (TLWalk)

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.


Features

  • 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.

Installation

  1. Install the Karate Club library using pip:

    pip install karateclub
  2. Clone the TLWalk repository to access the relevant scripts:

    git clone https://github.com/yourusername/TLWalk.git
    cd TLWalk

Input Data

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.


Usage

1. Preprocessing

Preprocess your graph data to ensure compatibility:

python preprocess.py 

2. Run TLWalk for Embedding

Run TLWalk to generate graph embeddings:

python _TwoLayerCommunityWalk.py

3. Link Prediction Task

Evaluate TLWalk embeddings for link prediction:

python link_prediction.py 

4. Node Classification Task

Evaluate node classification performance:

python node_classification_c.py 

Example Integration with Karate Club

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)

Repository Structure

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.)

Citation

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}, 
}

License

This project is released under the MIT License.


Contact

For questions or contributions, please open an issue or contact He Yu at [email protected].

About

A lightweight implementation of TLWalk: A Community-Aware Graph Embedding algorithm for capturing both local and global network structures effectively.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages