Update app.py
Browse files
app.py
CHANGED
|
@@ -41,6 +41,7 @@ POOLING_MAP = {
|
|
| 41 |
"Mean-Max (Combined)": "mean-max"
|
| 42 |
}
|
| 43 |
|
|
|
|
| 44 |
@st.cache_resource
|
| 45 |
def load_embedder(model_name, pool_strat):
|
| 46 |
word_emb = models.Transformer(model_name)
|
|
@@ -50,7 +51,9 @@ def load_embedder(model_name, pool_strat):
|
|
| 50 |
pooling_mode_max_tokens=("max" in pool_strat),
|
| 51 |
pooling_mode_cls_token=("cls" in pool_strat)
|
| 52 |
)
|
| 53 |
-
|
|
|
|
|
|
|
| 54 |
|
| 55 |
# ==========================================
|
| 56 |
# 2. THE GUIDED UI
|
|
@@ -108,9 +111,9 @@ with st.expander("2️⃣ Geometry Layer (Dimensionality Reduction)", expanded=T
|
|
| 108 |
with st.expander("3️⃣ Clustering Layer (Grouping)", expanded=True):
|
| 109 |
st.markdown("*💡 **BERTopic Default:** Uses `HDBSCAN` exclusively (which crashes on tiny datasets).*")
|
| 110 |
st.markdown("""
|
| 111 |
-
*
|
| 112 |
-
* **Primary
|
| 113 |
-
* **Fallback
|
| 114 |
""")
|
| 115 |
|
| 116 |
with st.expander("4️⃣ Vocabulary Layer (Vectorization)", expanded=True):
|
|
|
|
| 41 |
"Mean-Max (Combined)": "mean-max"
|
| 42 |
}
|
| 43 |
|
| 44 |
+
# --- CACHE THE NEURAL NETWORK ---
|
| 45 |
@st.cache_resource
|
| 46 |
def load_embedder(model_name, pool_strat):
|
| 47 |
word_emb = models.Transformer(model_name)
|
|
|
|
| 51 |
pooling_mode_max_tokens=("max" in pool_strat),
|
| 52 |
pooling_mode_cls_token=("cls" in pool_strat)
|
| 53 |
)
|
| 54 |
+
|
| 55 |
+
# HARDCODED MATH: Permanently forces L2 Normalization so distance math works flawlessly
|
| 56 |
+
return SentenceTransformer(modules=[word_emb, pool_model, models.Normalize()])
|
| 57 |
|
| 58 |
# ==========================================
|
| 59 |
# 2. THE GUIDED UI
|
|
|
|
| 111 |
with st.expander("3️⃣ Clustering Layer (Grouping)", expanded=True):
|
| 112 |
st.markdown("*💡 **BERTopic Default:** Uses `HDBSCAN` exclusively (which crashes on tiny datasets).*")
|
| 113 |
st.markdown("""
|
| 114 |
+
*The model mathematically draws boundaries around similar sentences. *
|
| 115 |
+
* **Primary clustering algorithm (HDBSCAN):** Runs on datasets $\ge$ 15 sentences. Automatically filters outliers and finds dense semantic clouds. *(Defaults: min_cluster_size=10)*
|
| 116 |
+
* **Fallback clustering algorithm (K-Means):** Runs on datasets $<$ 15 sentences. Forces all sentences into buckets to prevent math crashes on tiny text samples.
|
| 117 |
""")
|
| 118 |
|
| 119 |
with st.expander("4️⃣ Vocabulary Layer (Vectorization)", expanded=True):
|