File size: 1,216 Bytes
b7798d0
c75dc46
 
 
b7798d0
c75dc46
 
dd739a9
b136751
c75dc46
 
 
b136751
 
dd739a9
c75dc46
 
dd739a9
c75dc46
 
 
dd739a9
c75dc46
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
import streamlit as st
import pandas as pd
from gensim.models import Word2Vec
import matplotlib.pyplot as plt

# DEBUG st.write(f'streamlit version: {st.__version__}')

model_name = st.text_input('Model: ',
                           'metapath2vec_v1.202112011')

model = Word2Vec.load(f'models/{model_name}.pkl')

c_recommend_constructs = st.checkbox('Also recommend constructs',
                                     help='If checked, the constructs will be recommended along with the tasks')

positive_samples = st.multiselect('Positive samples', options=model.wv.index_to_key, default=[])
negative_samples = st.multiselect('Negative samples', options=model.wv.index_to_key, default=[])

n_recomms = 5

if len(positive_samples) + len(negative_samples) > 0:
  st.subheader('Recommended tasks or constructs:')
  recomms = model.wv.most_similar(positive=positive_samples,
                                  negative=negative_samples,
                                  topn=n_recomms)
  recomms_df = pd.DataFrame(recomms, columns=['word', 'similarity'])
  ax = recomms_df.plot(x='word', y='similarity', kind='barh')
  ax.invert_yaxis()
  st.pyplot(plt)
else:
  st.warning('No samples selected')

# st.write(recomms_df)