835 MB
10,492 files
Updated 4 months ago
README.md

CA10 Knowledge Graphs - Notebooks

📚 Available Notebooks

1. 01_Advanced_KG_Embeddings.ipynb

Advanced knowledge graph embedding techniques:

  • SimplE, RotatE, ConvE
  • Graph Attention Networks
  • Transformer-based embeddings

2. 02_Graph_Neural_Networks.ipynb ✨ NEW & COMPLETE

Comprehensive GNN tutorial for Knowledge Graphs:

  • GCN: Graph Convolutional Networks
  • GAT: Graph Attention Networks
  • GraphSAGE: Sample and Aggregate
  • R-GCN: Relational GCN for multi-relational graphs

Features:

  • ✅ 25+ cells with code and markdown
  • ✅ Complete implementations of 4 GNN architectures
  • ✅ Training pipeline for link prediction
  • ✅ Attention weight visualization
  • ✅ t-SNE embedding visualization
  • ✅ Model comparison and benchmarking
  • ✅ Comprehensive mathematical formulas
  • ✅ Production-ready code

3. CA10.ipynb

Main project notebook with all CA10 implementations


📖 Documentation

Main Documents:

  • GNN_NOTEBOOK_GUIDE.md: Complete 300+ line guide covering:

    • Detailed theory for each GNN architecture
    • Mathematical formulas and intuitions
    • Implementation details
    • Usage instructions
    • Troubleshooting
    • Research applications
    • References
  • NOTEBOOK_COMPLETION_REPORT.md: Technical report with:

    • Implementation statistics
    • Feature checklist
    • Code metrics
    • Testing status

🚀 Quick Start

Running 02_Graph_Neural_Networks.ipynb:

# 1. Install dependencies
pip install torch torch-geometric scikit-learn matplotlib seaborn

# 2. Launch Jupyter
cd /path/to/CA10_knowledge_graphs/notebooks
jupyter notebook 02_Graph_Neural_Networks.ipynb

# 3. Run all cells or execute step by step

Prerequisites:

# Core dependencies
torch>=2.0.0
torch-geometric>=2.4.0
scikit-learn>=1.3.0
matplotlib>=3.7.0
seaborn>=0.12.0
numpy>=1.24.0

📊 Notebook Structure

02_Graph_Neural_Networks.ipynb Sections:

  1. Introduction - Overview and objectives
  2. Setup - Imports and configuration
  3. Knowledge Graph - Create and visualize KG
  4. GCN - Theory + Implementation
  5. GAT - Attention mechanism + Visualization
  6. GraphSAGE - Sampling and aggregation
  7. R-GCN - Multi-relational reasoning
  8. Training - Link prediction pipeline
  9. Comparison - Model benchmarking
  10. Visualization - t-SNE embeddings
  11. Summary - Key takeaways

🎯 Learning Objectives

After completing these notebooks, you will understand:

  • ✅ Graph Neural Network fundamentals
  • ✅ Message passing framework
  • ✅ Attention mechanisms in graphs
  • ✅ Aggregation strategies
  • ✅ Multi-relational graph reasoning
  • ✅ Knowledge graph embedding techniques
  • ✅ Link prediction tasks
  • ✅ Model comparison and selection

🔬 What's Implemented

GNN Architectures:

Model Layers Parameters Best For
GCN 2 ~50K Simple graphs
GAT 2 (4 heads) ~75K Varying importance
GraphSAGE 2 ~55K Large-scale
R-GCN 2 ~60K Multi-relational

Features:

  • Forward propagation
  • Training loops
  • Loss computation
  • Accuracy metrics
  • Visualization tools
  • Model comparison

📈 Visualizations Included

  1. Knowledge Graph Structure: NetworkX visualizations
  2. Attention Weights: Histogram + bar charts
  3. Training Curves: Loss over epochs
  4. Embeddings: t-SNE 2D projections (2x2 grid)
  5. Model Comparison: Parameter and performance tables

🎓 Educational Value

Target Audience:

  • Students learning GNNs
  • Researchers working with Knowledge Graphs
  • Engineers building graph-based systems
  • Anyone interested in graph neural networks

Difficulty Level:

  • Prerequisite: Basic Python, PyTorch, Graph theory
  • Level: Intermediate to Advanced
  • Time: 2-3 hours to complete

💡 Key Concepts Covered

Theory:

  • Graph convolutions
  • Message passing
  • Attention mechanisms
  • Aggregation functions
  • Basis decomposition
  • Over-smoothing
  • Inductive learning

Practice:

  • PyTorch implementation
  • PyTorch Geometric usage
  • Training on Knowledge Graphs
  • Link prediction
  • Embedding visualization
  • Model selection

🔧 Customization

You can easily modify:

  • Embedding dimensions
  • Number of layers
  • Hidden dimensions
  • Dropout rates
  • Learning rates
  • Aggregation functions
  • Number of attention heads
  • Number of bases (R-GCN)

📚 References

Papers:

  1. Kipf & Welling - "Semi-Supervised Classification with GCNs" (ICLR 2017)
  2. Veličković et al. - "Graph Attention Networks" (ICLR 2018)
  3. Hamilton et al. - "Inductive Representation Learning" (NIPS 2017)
  4. Schlichtkrull et al. - "Modeling Relational Data" (ESWC 2018)

Resources:


🐛 Troubleshooting

Common Issues:

ImportError: torch_geometric not found

pip install torch-geometric torch-scatter torch-sparse

CUDA out of memory

  • Reduce batch size or embedding dimension
  • Use CPU: device = 'cpu'

Slow training

  • Use GPU if available
  • Reduce number of layers
  • Use GraphSAGE with sampling

See GNN_NOTEBOOK_GUIDE.md for more troubleshooting tips.


🎉 Status

  • ✅ Complete: All notebooks functional
  • ✅ Documented: Comprehensive guides
  • ✅ Tested: Code verified
  • ✅ Production-Ready: Professional quality

📞 Support

For questions:

  1. Review GNN_NOTEBOOK_GUIDE.md
  2. Check main CA10 README
  3. Consult PyTorch Geometric docs

Happy Learning! 🚀📚

Part of the System2_in_AI CA10 project
Last updated: October 10, 2025

Total size
835 MB
Files
10,492
Last updated
Jun 17
Pre-warmed CDN
US EU US EU

Contributors