|
18 | 18 | parser = argparse.ArgumentParser() |
19 | 19 | parser.add_argument("--debug", action="store_true", help="Run topic modelling only, skip LLM labelling and plots") |
20 | 20 | parser.add_argument("--output-dir", type=str, default="outputs_MPE", help="Directory for plots and HTML (default: outputs_MPE)") |
21 | | -parser.add_argument("--llm-model", type=str, default="meta-llama/Meta-Llama-3-8B-Instruct", help="HuggingFace model ID for LLM labelling") |
| 21 | +parser.add_argument("--llm-model", type=str, default="meta-llama/Llama-3.1-8B-Instruct", help="HuggingFace model ID for LLM labelling") |
| 22 | +parser.add_argument("--nr-repr-docs", type=int, default=10, help="Number of representative docs per topic for LLM labelling") |
22 | 23 | args = parser.parse_args() |
23 | 24 |
|
24 | 25 | import matplotlib |
@@ -144,6 +145,19 @@ def _load_secret(key: str) -> str: |
144 | 145 | n_outliers = sum(1 for t in topics if t == -1) |
145 | 146 | log.info(f"Topics: {n_topics} | Outliers: {n_outliers} ({100*n_outliers/len(topics):.1f}%)") |
146 | 147 |
|
| 148 | +# Re-extract representative docs with configured count |
| 149 | +import pandas as _pd |
| 150 | +_documents_df = _pd.DataFrame({"Document": docs, "Topic": topics}) |
| 151 | +_repr_docs, _, _, _ = topic_model._extract_representative_docs( |
| 152 | + topic_model.c_tf_idf_, |
| 153 | + _documents_df, |
| 154 | + topic_model.topic_representations_, |
| 155 | + nr_samples=500, |
| 156 | + nr_repr_docs=args.nr_repr_docs, |
| 157 | +) |
| 158 | +topic_model.representative_docs_ = _repr_docs |
| 159 | +log.info(f"Representative docs per topic: {args.nr_repr_docs}") |
| 160 | + |
147 | 161 | if args.debug: |
148 | 162 | log.info("Debug mode — skipping LLM labelling and plots") |
149 | 163 | import sys; sys.exit(0) |
@@ -229,7 +243,8 @@ def _load_secret(key: str) -> str: |
229 | 243 |
|
230 | 244 | # 3. Topic info CSV — topics + LLM labels + sizes |
231 | 245 | info_no_outliers["LLM_Label"] = info_no_outliers["Topic"].map(lambda t: labels.get(t, "")) |
232 | | -info_no_outliers.to_csv(PLOTS_DIR / "topic_info.csv", index=False) |
| 246 | +cols = ["Topic", "LLM_Label"] + [c for c in info_no_outliers.columns if c not in ("Topic", "LLM_Label")] |
| 247 | +info_no_outliers[cols].to_csv(PLOTS_DIR / "topic_info.csv", index=False) |
233 | 248 | log.info(f"Topic info → {PLOTS_DIR / 'topic_info.csv'}") |
234 | 249 |
|
235 | 250 | # 4. Interactive HTML — zoomable documents + topics scatter |
|
0 commit comments