peter2000 commited on
Commit
40c0a4f
1 Parent(s): 3ec30c4

Update app.py

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