Spaces:
Sleeping
Sleeping
tm
Browse files
nlp_core/topic_modeler.py
CHANGED
|
@@ -257,9 +257,15 @@ class TopicModeler:
|
|
| 257 |
# Map from valid_texts index back to original texts index
|
| 258 |
result_map: Dict[int, TopicResult] = {}
|
| 259 |
for pos, (orig_idx, topic_id) in enumerate(zip(indices, topics)):
|
| 260 |
-
|
| 261 |
-
|
| 262 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 263 |
|
| 264 |
topic_row = topic_info[topic_info["Topic"] == topic_id]
|
| 265 |
if not topic_row.empty and "Name" in topic_row.columns:
|
|
|
|
| 257 |
# Map from valid_texts index back to original texts index
|
| 258 |
result_map: Dict[int, TopicResult] = {}
|
| 259 |
for pos, (orig_idx, topic_id) in enumerate(zip(indices, topics)):
|
| 260 |
+
try:
|
| 261 |
+
prob = float(probs[pos]) if probs is not None else 0.0
|
| 262 |
+
except (TypeError, IndexError, ValueError):
|
| 263 |
+
prob = 0.0
|
| 264 |
+
try:
|
| 265 |
+
topic_words = model.get_topic(topic_id)
|
| 266 |
+
keywords = [w for w, _ in (topic_words or [])[:5]]
|
| 267 |
+
except Exception:
|
| 268 |
+
keywords = []
|
| 269 |
|
| 270 |
topic_row = topic_info[topic_info["Topic"] == topic_id]
|
| 271 |
if not topic_row.empty and "Name" in topic_row.columns:
|