tahamajs's picture
|
download
raw
5.97 kB
# 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:
```bash
# 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:
```bash
# 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:
- PyTorch Geometric: https://pytorch-geometric.readthedocs.io/
- Stanford CS224W: http://web.stanford.edu/class/cs224w/
- Distill.pub: https://distill.pub/
---
## πŸ› Troubleshooting
### Common Issues:
**ImportError: torch_geometric not found**
```bash
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_

Xet Storage Details

Size:
5.97 kB
Β·
Xet hash:
a1e94bd0de06c1d7973cd82f09a0280eb5ec1f4861fa1c5e1e2de4cd31bcc2e6

Xet efficiently stores files, intelligently splitting them into unique chunks and accelerating uploads and downloads. More info.