Buckets:
| # CA10: Advanced Knowledge Graphs | |
| ## ๐ฏ Project Overview | |
| A comprehensive implementation of **Advanced Knowledge Graph** systems with state-of-the-art embedding models, Graph Neural Networks, neural reasoning capabilities, and domain-specific applications. This project demonstrates cutting-edge knowledge graph technologies with practical implementations across healthcare, retail, and financial domains. | |
| ### ๐ What are Knowledge Graphs? | |
| Knowledge Graphs are structured representations of knowledge that capture entities, their attributes, and relationships between them. They enable: | |
| - **Semantic Understanding**: Rich representation of domain knowledge | |
| - **Reasoning**: Infer new facts from existing knowledge | |
| - **Integration**: Connect disparate data sources | |
| - **Explainability**: Transparent knowledge representation | |
| **Example**: | |
| - **Entities**: Person: "Albert Einstein", Concept: "Relativity" | |
| - **Relation**: "discovered" | |
| - **Triple**: (Albert Einstein, discovered, Relativity) | |
| --- | |
| ## โจ Key Features | |
| ### Core Implementations | |
| - โ **5+ Advanced Embedding Models** - TransE, DistMult, ComplEx, SimplE, RotatE, ConvE | |
| - โ **4 GNN Architectures** - GCN, GAT, GraphSAGE, R-GCN | |
| - โ **4 Neural Reasoning Methods** - Multi-hop, path ranking, neural-symbolic, reasoning chains | |
| - โ **3 Domain Applications** - Healthcare, Retail, Financial knowledge graphs | |
| - โ **LLM Integration** - Gemini API, LangChain, RAG systems | |
| - โ **Interactive Visualizations** - Graph structure, embeddings, metrics | |
| --- | |
| ## ๐ Project Structure | |
| ``` | |
| CA10_knowledge_graphs/ | |
| โโโ README.md # This file | |
| โโโ requirements.txt # Dependencies | |
| โโโ PROJECT_SUMMARY.md # Project summary | |
| โ | |
| โโโ notebooks/ # ๐ Jupyter Notebooks | |
| โ โโโ 01_Advanced_KG_Embeddings.ipynb | |
| โ โโโ 02_Graph_Neural_Networks.ipynb | |
| โ โโโ CA10.ipynb | |
| โ | |
| โโโ src/ # ๐ง Source Code | |
| โ โโโ core/ # Core KG components | |
| โ โ โโโ knowledge_graph.py | |
| โ โ โโโ scientific_kg.py | |
| โ โโโ models/ # Embedding and GNN models | |
| โ โ โโโ embeddings.py | |
| โ โ โโโ graph_neural_networks.py | |
| โ โโโ reasoning/ # Neural reasoning | |
| โ โโโ neural_reasoning.py | |
| โ โโโ langgraph_reasoning.py | |
| โ โโโ rag_system.py | |
| โ | |
| โโโ demos/ # ๐ฎ Domain Applications | |
| โ โโโ healthcare_kg_project.py | |
| โ โโโ retail_kg_project.py | |
| โ โโโ financial_kg_project.py | |
| โ โโโ comprehensive_kg_project.py | |
| โ | |
| โโโ scripts/ # ๐ Execution Scripts | |
| โ โโโ run.sh | |
| โ | |
| โโโ integrations/ # ๐ LLM Integrations | |
| โโโ tests/ # ๐งช Test Suite | |
| โโโ docs/ # ๐ Documentation | |
| โโโ data/ # ๐ Data and Results | |
| โโโ models/ # ๐พ Saved Models | |
| โโโ config/ # โ๏ธ Configuration | |
| ``` | |
| --- | |
| ## ๐ Quick Start | |
| ### 1. Installation | |
| ```bash | |
| cd CA10_knowledge_graphs | |
| pip install -r requirements.txt | |
| ``` | |
| ### 2. Run Main Project | |
| ```bash | |
| cd scripts | |
| ./run.sh | |
| ``` | |
| ### 3. Run Domain-Specific Projects | |
| ```bash | |
| # Healthcare Knowledge Graph | |
| python demos/healthcare_kg_project.py | |
| # Retail Knowledge Graph | |
| python demos/retail_kg_project.py | |
| # Financial Knowledge Graph | |
| python demos/financial_kg_project.py | |
| # Comprehensive System | |
| python demos/comprehensive_kg_project.py | |
| ``` | |
| ### 4. Explore Notebooks | |
| ```bash | |
| jupyter notebook notebooks/ | |
| ``` | |
| --- | |
| ## ๐ Core Components | |
| ### 1. Knowledge Graph Embeddings | |
| #### Traditional Embeddings | |
| - **TransE**: Translational embeddings (h + r โ t) | |
| - **DistMult**: Bilinear diagonal model | |
| - **ComplEx**: Complex-valued embeddings | |
| #### Advanced Embeddings | |
| - **SimplE**: Separate head/tail embeddings | |
| - **RotatE**: Rotation-based in complex space | |
| - **ConvE**: 2D convolutional embeddings | |
| - **Graph Attention**: Multi-head attention | |
| - **Transformer-based**: Self-attention mechanisms | |
| **Usage**: | |
| ```python | |
| from src.models.embeddings import SimplE, RotatE, ConvE | |
| # Initialize SimplE model | |
| model = SimplE(num_entities=1000, num_relations=50, embedding_dim=100) | |
| # Train the model | |
| trainer = KGEmbeddingTrainer(model, knowledge_graph) | |
| losses = trainer.train(epochs=200, lr=0.01) | |
| # Link prediction | |
| predictions = trainer.predict_links(head_entity, relation, k=10) | |
| ``` | |
| --- | |
| ### 2. Graph Neural Networks | |
| #### Supported Architectures | |
| - **GCN** (Graph Convolutional Networks): Aggregate neighbor features | |
| - **GAT** (Graph Attention Networks): Attention-weighted aggregation | |
| - **GraphSAGE**: Sample and aggregate from neighborhoods | |
| - **R-GCN** (Relational GCN): Multi-relational graph processing | |
| - **Temporal GNN**: Time-aware knowledge graph reasoning | |
| **Usage**: | |
| ```python | |
| from src.models.graph_neural_networks import GATKnowledgeGraph, RGCNKnowledgeGraph | |
| # Initialize GAT model | |
| gat_model = GATKnowledgeGraph( | |
| num_entities=1000, | |
| num_relations=50, | |
| embedding_dim=64, | |
| num_heads=4 | |
| ) | |
| # Initialize R-GCN model | |
| rgcn_model = RGCNKnowledgeGraph( | |
| num_entities=1000, | |
| num_relations=50, | |
| embedding_dim=64, | |
| num_bases=30 | |
| ) | |
| # Forward pass | |
| output = gat_model(edge_index, edge_type) | |
| ``` | |
| --- | |
| ### 3. Neural Reasoning | |
| #### Reasoning Methods | |
| - **Multi-Hop Reasoning**: Traverse multiple hops to infer new facts | |
| - **Path Ranking**: Learn to rank reasoning paths | |
| - **Neural-Symbolic Integration**: Combine neural learning with symbolic logic | |
| - **Reasoning Chains**: Step-by-step reasoning with intermediate steps | |
| - **Explainable Reasoning**: Generate interpretable explanations | |
| **Usage**: | |
| ```python | |
| from src.reasoning.neural_reasoning import MultiHopReasoning, NeuralSymbolicReasoning | |
| # Multi-hop reasoning | |
| multi_hop = MultiHopReasoning( | |
| num_entities=1000, | |
| num_relations=50, | |
| embedding_dim=64, | |
| max_hops=3 | |
| ) | |
| # Perform reasoning | |
| answer, reasoning_path = multi_hop.reason( | |
| query_entity="Einstein", | |
| query_relation="discovered", | |
| max_paths=5 | |
| ) | |
| ``` | |
| --- | |
| ### 4. Domain Applications | |
| #### Healthcare Knowledge Graph | |
| **Features**: | |
| - Disease-symptom relationships | |
| - Treatment recommendations | |
| - Comorbidity analysis | |
| - Disease prediction from symptoms | |
| **Usage**: | |
| ```python | |
| from demos.healthcare_kg_project import HealthcareKnowledgeGraph | |
| healthcare_kg = HealthcareKnowledgeGraph() | |
| treatments = healthcare_kg.find_treatments_for_disease("diabetes") | |
| predictions = healthcare_kg.predict_disease_from_symptoms(["fever", "cough"]) | |
| ``` | |
| #### Retail Knowledge Graph | |
| **Features**: | |
| - Product recommendations | |
| - Customer behavior analysis | |
| - Frequently bought together | |
| - Category and brand relationships | |
| **Usage**: | |
| ```python | |
| from demos.retail_kg_project import RetailKnowledgeGraph | |
| retail_kg = RetailKnowledgeGraph() | |
| recommendations = retail_kg.recommend_products("customer_001", top_k=5) | |
| similar_products = retail_kg.get_products_by_category("electronics") | |
| ``` | |
| #### Financial Knowledge Graph | |
| **Features**: | |
| - Portfolio analysis | |
| - Risk assessment | |
| - Market correlation analysis | |
| - Diversification opportunities | |
| **Usage**: | |
| ```python | |
| from demos.financial_kg_project import FinancialKnowledgeGraph | |
| financial_kg = FinancialKnowledgeGraph() | |
| portfolio = financial_kg.get_investor_portfolio("investor_001") | |
| risk_analysis = financial_kg.analyze_portfolio_risk("investor_001") | |
| ``` | |
| --- | |
| ## ๐ Performance Metrics | |
| ### Evaluation Metrics | |
| - **Hits@K**: Percentage of correct predictions in top-K | |
| - **Mean Rank**: Average rank of correct entities | |
| - **MRR** (Mean Reciprocal Rank): Harmonic mean of ranks | |
| - **Training Loss**: Convergence monitoring | |
| ### Example Results | |
| | Model | Hits@3 | Mean Rank | Parameters | | |
| | -------- | ------ | --------- | ---------- | | |
| | TransE | 0.65 | 12.3 | 50K | | |
| | DistMult | 0.72 | 10.1 | 50K | | |
| | ComplEx | 0.78 | 8.5 | 100K | | |
| | SimplE | 0.81 | 7.2 | 100K | | |
| | RotatE | 0.83 | 6.8 | 100K | | |
| --- | |
| ## ๐งช Testing | |
| ```bash | |
| cd tests | |
| python test_embeddings.py | |
| python test_reasoning.py | |
| # Or use pytest | |
| pytest -v | |
| ``` | |
| --- | |
| ## ๐ Educational Value | |
| ### Concepts Demonstrated | |
| 1. Knowledge graph construction and management | |
| 2. Graph embedding techniques | |
| 3. Graph Neural Networks | |
| 4. Neural reasoning and inference | |
| 5. Domain-specific applications | |
| 6. LLM integration for knowledge graphs | |
| ### Learning Outcomes | |
| - Understand knowledge graph fundamentals | |
| - Implement embedding models | |
| - Apply GNNs to knowledge graphs | |
| - Build reasoning systems | |
| - Create domain-specific applications | |
| --- | |
| ## ๐ฌ Research Applications | |
| 1. **Healthcare**: Medical diagnosis and treatment recommendation | |
| 2. **E-commerce**: Product recommendation and customer analysis | |
| 3. **Finance**: Portfolio management and risk assessment | |
| 4. **Scientific Discovery**: Literature mining and hypothesis generation | |
| 5. **Question Answering**: Knowledge-based QA systems | |
| 6. **Semantic Search**: Intelligent information retrieval | |
| --- | |
| ## ๐ฆ Dependencies | |
| ### Core Libraries | |
| ``` | |
| torch>=2.0.0 | |
| torch-geometric>=2.4.0 | |
| networkx>=3.1 | |
| transformers>=4.30.0 | |
| ``` | |
| ### LLM and RAG | |
| ``` | |
| langchain>=0.1.0 | |
| langchain-google-genai>=1.0.0 | |
| google-generativeai>=0.3.0 | |
| chromadb>=0.4.0 | |
| faiss-cpu>=1.7.4 | |
| ``` | |
| ### Visualization | |
| ``` | |
| matplotlib>=3.7.0 | |
| seaborn>=0.12.0 | |
| plotly>=5.15.0 | |
| ``` | |
| **See `requirements.txt` for complete list.** | |
| --- | |
| ## ๐ References | |
| ### Key Papers | |
| 1. **TransE**: Bordes et al., "Translating Embeddings for Modeling Multi-relational Data" (2013) | |
| 2. **DistMult**: Yang et al., "Embedding Entities and Relations" (2015) | |
| 3. **ComplEx**: Trouillon et al., "Complex Embeddings for Simple Link Prediction" (2016) | |
| 4. **SimplE**: Kazemi & Poole, "SimplE Embedding for Link Prediction" (2018) | |
| 5. **RotatE**: Sun et al., "RotatE: Knowledge Graph Embedding by Relational Rotation" (2019) | |
| 6. **ConvE**: Dettmers et al., "Convolutional 2D Knowledge Graph Embeddings" (2018) | |
| 7. **R-GCN**: Schlichtkrull et al., "Modeling Relational Data with Graph Convolutional Networks" (2018) | |
| --- | |
| ## ๐ค Contributing | |
| This project is part of the **Systems in AI** course (CA10). Contributions welcome! | |
| --- | |
| ## ๐ License | |
| Part of the System2_in_AI CA collection for educational and research purposes. | |
| --- | |
| ## ๐ Project Status | |
| - **Status**: โ **COMPLETE AND FULLY FUNCTIONAL** | |
| - **Version**: 2.0.0 | |
| - **Quality**: โญโญโญโญโญ Professional Grade | |
| - **Last Updated**: January 2025 | |
| - **Language**: English | |
| --- | |
| **Thank you for using the CA10 Advanced Knowledge Graphs project!** | |
| This comprehensive implementation provides everything needed to learn, research, and implement knowledge graph systems with state-of-the-art techniques. | |
| _Happy Learning and Building! ๐๐_ | |
Xet Storage Details
- Size:
- 11 kB
- Xet hash:
- a374518aa2f0f344de1d3c39af46ab4da335f69fd4ddedd3ad6431f34ed23ca4
ยท
Xet efficiently stores files, intelligently splitting them into unique chunks and accelerating uploads and downloads. More info.