peter2000 commited on
Commit
9b1b004
1 Parent(s): fdafc16

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +47 -0
app.py CHANGED
@@ -1,7 +1,54 @@
1
  import plotly.express as px
2
  import streamlit as st
 
3
  import pandas as pd
4
  import os
5
 
 
 
6
 
 
7
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
  import plotly.express as px
2
  import streamlit as st
3
+ import umap.umap_ as umap
4
  import pandas as pd
5
  import os
6
 
7
+ model_name = 'sentence-transformers/all-MiniLM-L6-v2'
8
+ model = SentenceTransformer(model_name)
9
 
10
+ df_osdg = pd.read_csv('https://zenodo.org/record/5550238/files/osdg-community-dataset-v21-09-30.csv',sep='\t')
11
 
12
+ _lab_dict = {0: 'no_cat',
13
+ 1:'SDG 1 - No poverty',
14
+ 2:'SDG 2 - Zero hunger',
15
+ 3:'SDG 3 - Good health and well-being',
16
+ 4:'SDG 4 - Quality education',
17
+ 5:'SDG 5 - Gender equality',
18
+ 6:'SDG 6 - Clean water and sanitation',
19
+ 7:'SDG 7 - Affordable and clean energy',
20
+ 8:'SDG 8 - Decent work and economic growth',
21
+ 9:'SDG 9 - Industry, Innovation and Infrastructure',
22
+ 10:'SDG 10 - Reduced inequality',
23
+ 11:'SDG 11 - Sustainable cities and communities',
24
+ 12:'SDG 12 - Responsible consumption and production',
25
+ 13:'SDG 13 - Climate action',
26
+ 14:'SDG 14 - Life below water',
27
+ 15:'SDG 15 - Life on land',
28
+ 16:'SDG 16 - Peace, justice and strong institutions',
29
+ 17:'SDG 17 - Partnership for the goals',}
30
+
31
+ labels = [_lab_dict[lab] for lab in df_osdg['sdg'] ]
32
+ keys = list(df_osdg['keys'])
33
+ docs = list(df_osdg['text'])
34
+
35
+ docs_embeddings = model.encode(docs)
36
+
37
+ n_neighbors = 15
38
+ n_components = 3
39
+ random_state =42
40
+ umap_model = (umap.UMAP(n_neighbors=n_neighbors,
41
+ n_components=n_components,
42
+ metric='cosine',
43
+ random_state=random_state)
44
+ .fit(docs_embeddings))
45
+
46
+ docs_umap = umap_model.transform(docs_embeddings)
47
+
48
+ fig = px.scatter_3d(
49
+ docs_umap, x=0, y=1, z=2,
50
+ color=labels,
51
+ opacity = .5)#, hover_data=[keys])
52
+ fig.update_scenes(xaxis_visible=False, yaxis_visible=False,zaxis_visible=False )
53
+ fig.update_traces(marker_size=4)
54
+ st.plotly_chart(fig)