How hwwang55/kgcn works
Project Type and Purpose
• This is an open‐source machine‐learning tool implementing Knowledge Graph Convolutional Networks (KGCN) for recommender systems.
• It is not a traditional client–server or full‑stack app, but a data‑processing + model‑training pipeline that:
– Loads raw rating and knowledge‐graph data (MovieLens, Last.FM)
– Preprocesses inputs into graph structures
– Builds and trains a GCN‐based recommendation model
– Outputs evaluation metrics and recommendation results
High‑Level File‑Structure Analysis
• data/ – raw datasets and KG files (movie/, music/)
– item_index2entity_id.txt, kg.txt, user_artists.dat
• src/ – pure‐Python implementation of the pipeline
– preprocess.py – data cleaning & graph construction
– data_loader.py – dataset batching & sampling
– aggregators.py – GCN neighborhood aggregation logic
– model.py – KGCN model class (layers, forward pass)
– train.py – training loop, loss computation, evaluation
– main.py – parameter settings & end‑to‑end orchestration
Key Architecture Insights from README
• The included “framework.png” shows a three‑stage flow:
1) Neighbor sampling from the KG
2) Multi‑layer graph convolution (aggregating entity + relation embeddings)
3) Score prediction for user–item pairs
• Dependencies are pure Python (NumPy/TensorFlow/PyTorch unspecified), no web servers or microservices
– MovieLens ratings.csv, Last.FM user_artists.dat
– Knowledge graph files (kg.txt)
2) Preprocessing Module (rectangle)
– preprocess.py
– Outputs: user–item train/test splits, adjacency lists, entity/relation mappings
3) Data Loader Module (rectangle)
– data_loader.py
– Performs negative sampling, mini‑batch construction
4) KGCN Model Module (rectangle)
– model.py & aggregators.py
– Graph convolutional layers, neighbor aggregator functions
5) Trainer Module (rectangle)
– train.py
– Loss calculation, optimization (e.g., Adam), early stopping, metrics
6) Orchestrator / CLI (rectangle with rounded corners)
– main.py
– Parses command‑line flags (–d movie/music), connects modules in sequence
– Recommendation lists, AUC/Recall metrics
• Raw Data → Preprocessing → (Preprocessed Files) → Data Loader → Trainer
• Data Loader ↔ KGCN Model (batches in, embeddings out)
• Trainer → Evaluation Outputs
• Orchestrator calls Preprocessing → Data Loader → Trainer in sequence
c. Architectural Patterns & Principles
• Pipeline Pattern: clear stages (Preprocess → Load → Train → Eval)
• Modular Separation: one file per responsibility (single‑responsibility principle)
• Graph‑computation submodule (aggregators) isolated from I/O code
• Parameterization via main.py for domain‑specific configs (movie vs. music)
d. Technologies & Frameworks to Call Out
• Python 3.x
• (Implicit) GCN backend – e.g., TensorFlow or PyTorch for tensor ops
• Data storage: local filesystem (flat text files)