Skip to content

Commit 001f5f4

Browse files
committed
sync MPE pipeline with run_pipeline.py updates
1 parent 05f7bba commit 001f5f4

1 file changed

Lines changed: 17 additions & 2 deletions

File tree

run_pipeline_MPE.py

Lines changed: 17 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,8 @@
1818
parser = argparse.ArgumentParser()
1919
parser.add_argument("--debug", action="store_true", help="Run topic modelling only, skip LLM labelling and plots")
2020
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")
2223
args = parser.parse_args()
2324

2425
import matplotlib
@@ -144,6 +145,19 @@ def _load_secret(key: str) -> str:
144145
n_outliers = sum(1 for t in topics if t == -1)
145146
log.info(f"Topics: {n_topics} | Outliers: {n_outliers} ({100*n_outliers/len(topics):.1f}%)")
146147

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+
147161
if args.debug:
148162
log.info("Debug mode — skipping LLM labelling and plots")
149163
import sys; sys.exit(0)
@@ -229,7 +243,8 @@ def _load_secret(key: str) -> str:
229243

230244
# 3. Topic info CSV — topics + LLM labels + sizes
231245
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)
233248
log.info(f"Topic info → {PLOTS_DIR / 'topic_info.csv'}")
234249

235250
# 4. Interactive HTML — zoomable documents + topics scatter

0 commit comments

Comments
 (0)