sorted options words
Browse files
app.py
CHANGED
|
@@ -19,8 +19,7 @@ def load_lsj_dict():
|
|
| 19 |
|
| 20 |
@st.cache_data
|
| 21 |
def load_all_models_words():
|
| 22 |
-
return load_compressed_word_list('
|
| 23 |
-
|
| 24 |
|
| 25 |
# Load compressed word list
|
| 26 |
all_models_words = load_all_models_words()
|
|
@@ -38,13 +37,13 @@ active_tab = option_menu(None, ["Nearest neighbours", "Cosine similarity", "3D g
|
|
| 38 |
# Nearest neighbours tab
|
| 39 |
if active_tab == "Nearest neighbours":
|
| 40 |
|
| 41 |
-
#
|
| 42 |
-
|
| 43 |
eligible_models = ["Archaic", "Classical", "Hellenistic", "Early Roman", "Late Roman"]
|
|
|
|
| 44 |
|
| 45 |
with st.form("nn_form"):
|
| 46 |
st.markdown("## Nearest Neighbours")
|
| 47 |
-
target_word = st.multiselect("Enter a word", all_models_words, max_selections=1)
|
| 48 |
if len(target_word) > 0:
|
| 49 |
target_word = target_word[0]
|
| 50 |
|
|
@@ -99,24 +98,36 @@ if active_tab == "Nearest neighbours":
|
|
| 99 |
|
| 100 |
# Cosine similarity tab
|
| 101 |
elif active_tab == "Cosine similarity":
|
| 102 |
-
|
| 103 |
-
|
| 104 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 105 |
with col1:
|
| 106 |
-
word_1 = st.
|
|
|
|
|
|
|
|
|
|
|
|
|
| 107 |
|
| 108 |
-
with col2:
|
| 109 |
-
time_slice_1 = st.selectbox("Time slice word 1", ["Archaic", "Classical", "Hellenistic", "Early Roman", "Late Roman"])
|
| 110 |
|
| 111 |
-
|
| 112 |
-
|
| 113 |
-
|
| 114 |
-
|
| 115 |
-
|
| 116 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 117 |
|
| 118 |
-
|
| 119 |
-
|
| 120 |
|
| 121 |
# If the button is clicked, execute calculation
|
| 122 |
if cosine_similarity_button:
|
|
|
|
| 19 |
|
| 20 |
@st.cache_data
|
| 21 |
def load_all_models_words():
|
| 22 |
+
return sorted(load_compressed_word_list('corpora/compass_filtered.pkl.gz'), key=custom_sort)
|
|
|
|
| 23 |
|
| 24 |
# Load compressed word list
|
| 25 |
all_models_words = load_all_models_words()
|
|
|
|
| 37 |
# Nearest neighbours tab
|
| 38 |
if active_tab == "Nearest neighbours":
|
| 39 |
|
| 40 |
+
# All models in a list
|
|
|
|
| 41 |
eligible_models = ["Archaic", "Classical", "Hellenistic", "Early Roman", "Late Roman"]
|
| 42 |
+
all_models_words = load_all_models_words()
|
| 43 |
|
| 44 |
with st.form("nn_form"):
|
| 45 |
st.markdown("## Nearest Neighbours")
|
| 46 |
+
target_word = st.multiselect("Enter a word", options=all_models_words, max_selections=1)
|
| 47 |
if len(target_word) > 0:
|
| 48 |
target_word = target_word[0]
|
| 49 |
|
|
|
|
| 98 |
|
| 99 |
# Cosine similarity tab
|
| 100 |
elif active_tab == "Cosine similarity":
|
| 101 |
+
eligible_models_1 = []
|
| 102 |
+
eligible_models_2 = []
|
| 103 |
+
all_models_words = load_all_models_words()
|
| 104 |
+
|
| 105 |
+
with st.form("cosine_similarity_form"):
|
| 106 |
+
st.markdown("## Cosine similarity")
|
| 107 |
+
col1, col2 = st.columns(2)
|
| 108 |
+
col3, col4 = st.columns(2)
|
| 109 |
with col1:
|
| 110 |
+
word_1 = st.multiselect("Enter a word", placeholder="πατήρ", max_selections=1, options=all_models_words)
|
| 111 |
+
if len(word_1) > 0:
|
| 112 |
+
word_1 = word_1[0]
|
| 113 |
+
eligible_models_1 = check_word_in_models(word_1)
|
| 114 |
+
|
| 115 |
|
|
|
|
|
|
|
| 116 |
|
| 117 |
+
time_slice_1 = st.selectbox("Time slice word 1", eligible_models_1)
|
| 118 |
+
|
| 119 |
+
with st.container():
|
| 120 |
+
with col3:
|
| 121 |
+
word_2 = st.multiselect("Enter a word", placeholder="μήτηρ", max_selections=1, options=all_models_words)
|
| 122 |
+
if len(word_2) > 0:
|
| 123 |
+
word_2 = word_2[0]
|
| 124 |
+
eligible_models_2 = check_word_in_models(word_2)
|
| 125 |
+
|
| 126 |
+
with col4:
|
| 127 |
+
time_slice_2 = st.selectbox("Time slice word 2", eligible_models_2)
|
| 128 |
|
| 129 |
+
# Create button for calculating cosine similarity
|
| 130 |
+
cosine_similarity_button = st.form_submit_button("Calculate cosine similarity")
|
| 131 |
|
| 132 |
# If the button is clicked, execute calculation
|
| 133 |
if cosine_similarity_button:
|