Spaces:
Configuration error
Configuration error
| 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) | |