Spaces:
Sleeping
Sleeping
Create app.py
Browse files
app.py
ADDED
@@ -0,0 +1,198 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import streamlit as st # π Importing Streamlit to create our awesome app!
|
2 |
+
import streamlit_mermaid # π§ββοΈ Mermaid diagrams in Streamlit!
|
3 |
+
import os # π For file operations, because who doesn't like saving stuff?
|
4 |
+
|
5 |
+
# πΌοΈ Setting the page configuration to make it look neat.
|
6 |
+
st.set_page_config(page_title="Knowledge Graph Completion", layout="wide")
|
7 |
+
|
8 |
+
# π― Setting the title of our app.
|
9 |
+
st.title("Knowledge Graph Completion")
|
10 |
+
|
11 |
+
# π Introducing PBF with some Markdown magic!
|
12 |
+
st.markdown("# I. Introduction to Portable Brain Format (PBF)")
|
13 |
+
|
14 |
+
st.markdown("""
|
15 |
+
**Definition and Purpose of PBF**
|
16 |
+
|
17 |
+
- Goal of human and machine readability for knowledge graph exchange
|
18 |
+
- Comparison to similar graph standards (RDF, GQL)
|
19 |
+
- Mention of tools and libraries supporting PBF and related formats (Neo4j, Apache Jena)
|
20 |
+
- Current state of language portability in knowledge management AI
|
21 |
+
""")
|
22 |
+
|
23 |
+
st.markdown("### Comparison of Graph Standards")
|
24 |
+
|
25 |
+
# π§βπ¨ Mermaid diagram editor for the first diagram
|
26 |
+
filename1 = st.text_input("Enter filename for Diagram 1:", "diagram1.mmd")
|
27 |
+
mermaid_code1 = st.text_area("Edit Mermaid Diagram 1:", '''graph LR
|
28 |
+
PBF[Portable Brain Format]
|
29 |
+
RDF[RDF]
|
30 |
+
GQL[Graph Query Language]
|
31 |
+
PBF -- Similarities --> RDF
|
32 |
+
PBF -- Similarities --> GQL
|
33 |
+
RDF -- Differences --> GQL
|
34 |
+
''')
|
35 |
+
|
36 |
+
# π Save and Load buttons for Diagram 1
|
37 |
+
col1, col2 = st.columns(2)
|
38 |
+
with col1:
|
39 |
+
if st.button("Save Diagram 1"):
|
40 |
+
with open(filename1, 'w') as f:
|
41 |
+
f.write(mermaid_code1)
|
42 |
+
st.success(f"Diagram 1 saved to {filename1}!")
|
43 |
+
with col2:
|
44 |
+
if st.button("Load Diagram 1"):
|
45 |
+
if os.path.exists(filename1):
|
46 |
+
with open(filename1, 'r') as f:
|
47 |
+
mermaid_code1 = f.read()
|
48 |
+
st.success(f"Diagram 1 loaded from {filename1}!")
|
49 |
+
else:
|
50 |
+
st.error(f"File {filename1} does not exist.")
|
51 |
+
|
52 |
+
# π§ββοΈ Displaying the Mermaid diagram for Diagram 1
|
53 |
+
st.markdown("#### Diagram 1:")
|
54 |
+
streamlit_mermaid.mermaid(mermaid_code1)
|
55 |
+
|
56 |
+
# Repeat the process for other Mermaid diagrams in the app
|
57 |
+
st.markdown("# II. Knowledge Graph Completion")
|
58 |
+
|
59 |
+
st.markdown("## Using Language Models")
|
60 |
+
|
61 |
+
st.markdown("""
|
62 |
+
- **KG-BERT**: Using BERT for knowledge graph completion (Yao et al., 2019)
|
63 |
+
- **KG-LLM**: Exploring Large Language Models for knowledge graph completion (Yao et al., 2024)
|
64 |
+
""")
|
65 |
+
|
66 |
+
st.markdown("## Improving Existing Models")
|
67 |
+
|
68 |
+
st.markdown("""
|
69 |
+
- **ProjB**: An improved bilinear biased ProjE model for knowledge graph completion (Moattari et al., 2022)
|
70 |
+
""")
|
71 |
+
|
72 |
+
st.markdown("## Other Approaches")
|
73 |
+
|
74 |
+
st.markdown("""
|
75 |
+
- **GRank**: Graph Pattern Entity Ranking Model (Ebisu & Ichise, 2019)
|
76 |
+
""")
|
77 |
+
|
78 |
+
# π§ Time to dive into Knowledge Graph Embeddings.
|
79 |
+
st.markdown("# III. Knowledge Graph Embeddings")
|
80 |
+
|
81 |
+
st.markdown("## Applications")
|
82 |
+
|
83 |
+
st.markdown("- **Entity Type Prediction** (Biswas et al., 2020)")
|
84 |
+
|
85 |
+
st.markdown("## Biomedical Domain")
|
86 |
+
|
87 |
+
st.markdown("- Link prediction, rule learning, polypharmacy tasks (Gema et al., 2023)")
|
88 |
+
|
89 |
+
st.markdown("## Specific Models and Frameworks")
|
90 |
+
|
91 |
+
st.markdown("""
|
92 |
+
- **Knowledgebra**: An algebraic learning framework for KG (Yang et al., 2022)
|
93 |
+
- Deep learning on knowledge graphs for recommender systems (Gao et al., 2020)
|
94 |
+
- Neuromorphic knowledge graph embeddings (Caceres Chian et al., 2021)
|
95 |
+
""")
|
96 |
+
|
97 |
+
st.markdown("## Benchmarks and Best Practices")
|
98 |
+
|
99 |
+
st.markdown("- Benchmark and best practices for biomedical KG embeddings (Chang et al., 2020)")
|
100 |
+
|
101 |
+
st.markdown("### Knowledge Graph Embedding Process")
|
102 |
+
|
103 |
+
# π§βπ¨ Mermaid diagram editor for the second diagram
|
104 |
+
filename2 = st.text_input("Enter filename for Diagram 2:", "diagram2.mmd")
|
105 |
+
mermaid_code2 = st.text_area("Edit Mermaid Diagram 2:", '''graph TD
|
106 |
+
A[Knowledge Graph] --> B[Embedding Model]
|
107 |
+
B --> C[Vector Representations]
|
108 |
+
C --> D[Downstream Tasks]
|
109 |
+
D --> E[Entity Type Prediction]
|
110 |
+
D --> F[Link Prediction]
|
111 |
+
D --> G[Recommender Systems]
|
112 |
+
''')
|
113 |
+
|
114 |
+
# π Save and Load buttons for Diagram 2
|
115 |
+
col3, col4 = st.columns(2)
|
116 |
+
with col3:
|
117 |
+
if st.button("Save Diagram 2"):
|
118 |
+
with open(filename2, 'w') as f:
|
119 |
+
f.write(mermaid_code2)
|
120 |
+
st.success(f"Diagram 2 saved to {filename2}!")
|
121 |
+
with col4:
|
122 |
+
if st.button("Load Diagram 2"):
|
123 |
+
if os.path.exists(filename2):
|
124 |
+
with open(filename2, 'r') as f:
|
125 |
+
mermaid_code2 = f.read()
|
126 |
+
st.success(f"Diagram 2 loaded from {filename2}!")
|
127 |
+
else:
|
128 |
+
st.error(f"File {filename2} does not exist.")
|
129 |
+
|
130 |
+
# π§ββοΈ Displaying the Mermaid diagram for Diagram 2
|
131 |
+
st.markdown("#### Diagram 2:")
|
132 |
+
streamlit_mermaid.mermaid(mermaid_code2)
|
133 |
+
|
134 |
+
# π Exploring Knowledge Graph Applications.
|
135 |
+
st.markdown("# IV. Knowledge Graph Applications")
|
136 |
+
|
137 |
+
st.markdown("## Commonsense Reasoning")
|
138 |
+
|
139 |
+
st.markdown("""
|
140 |
+
- Fusing context into KG for commonsense QA (Xu et al., 2021)
|
141 |
+
- **CSKG**: The CommonSense Knowledge Graph (Ilievski et al., 2021)
|
142 |
+
""")
|
143 |
+
|
144 |
+
st.markdown("## Conversation Generation")
|
145 |
+
|
146 |
+
st.markdown("- Knowledge-aware conversation generation with explainable reasoning over augmented graphs (Liu et al., 2019)")
|
147 |
+
|
148 |
+
st.markdown("## Question Answering")
|
149 |
+
|
150 |
+
st.markdown("- Question answering over spatio-temporal knowledge graphs (Dai et al., 2024)")
|
151 |
+
|
152 |
+
st.markdown("### Application in Commonsense Reasoning")
|
153 |
+
|
154 |
+
# π§βπ¨ Mermaid diagram editor for the third diagram
|
155 |
+
filename3 = st.text_input("Enter filename for Diagram 3:", "diagram3.mmd")
|
156 |
+
mermaid_code3 = st.text_area("Edit Mermaid Diagram 3:", '''graph LR
|
157 |
+
Context -->|Fused into| KnowledgeGraph
|
158 |
+
KnowledgeGraph -->|Used for| CommonsenseQA
|
159 |
+
''')
|
160 |
+
|
161 |
+
# π Save and Load buttons for Diagram 3
|
162 |
+
col5, col6 = st.columns(2)
|
163 |
+
with col5:
|
164 |
+
if st.button("Save Diagram 3"):
|
165 |
+
with open(filename3, 'w') as f:
|
166 |
+
f.write(mermaid_code3)
|
167 |
+
st.success(f"Diagram 3 saved to {filename3}!")
|
168 |
+
with col6:
|
169 |
+
if st.button("Load Diagram 3"):
|
170 |
+
if os.path.exists(filename3):
|
171 |
+
with open(filename3, 'r') as f:
|
172 |
+
mermaid_code3 = f.read()
|
173 |
+
st.success(f"Diagram 3 loaded from {filename3}!")
|
174 |
+
else:
|
175 |
+
st.error(f"File {filename3} does not exist.")
|
176 |
+
|
177 |
+
# π§ββοΈ Displaying the Mermaid diagram for Diagram 3
|
178 |
+
st.markdown("#### Diagram 3:")
|
179 |
+
streamlit_mermaid.mermaid(mermaid_code3)
|
180 |
+
|
181 |
+
# ποΈ Introducing Specific Knowledge Graphs.
|
182 |
+
st.markdown("# V. Specific Knowledge Graphs")
|
183 |
+
|
184 |
+
st.markdown("""
|
185 |
+
- **TechKG**: A large-scale Chinese technology-oriented knowledge graph (Ren et al., 2018)
|
186 |
+
- **Wikidata**: Discovering implicational knowledge in Wikidata (Hanika et al., 2019)
|
187 |
+
- **EventNarrative**: A large-scale event-centric dataset for knowledge graph-to-text generation (Colas et al., 2022)
|
188 |
+
""")
|
189 |
+
|
190 |
+
# π§© Discussing Knowledge Graph Representation.
|
191 |
+
st.markdown("# VI. Knowledge Graph Representation")
|
192 |
+
|
193 |
+
st.markdown("- **KSR**: A semantic representation of knowledge graph within a novel unsupervised paradigm (Xiao et al., 2020)")
|
194 |
+
|
195 |
+
# π Wrapping up with RDF Generation and Validation.
|
196 |
+
st.markdown("# VII. RDF Generation and Validation")
|
197 |
+
|
198 |
+
st.markdown("- **R2RML and RML**: Comparison for RDF generation, rules validation, and inconsistency resolution (Dimou, 2020)")
|