battery_builder / app.py
morteza's picture
simple ui to plot and select samples
c75dc46
raw
history blame
1 kB
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('Enter model version: ', 'metapath2vec_v1.202112011')
model = Word2Vec.load(f'models/{model_name}.pkl')
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.header('Recommendations:')
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)