--- license: mit library_name: peft base_model: unsloth/Qwen2.5-7B-Instruct-bnb-4bit pipeline_tag: text-generation tags: - medical - pathology - cancer - oncology - tcga - survival-analysis - clinical-nlp - instruction-tuning - lora - qlora - qwen2.5 - unsloth - sft - trl language: - en datasets: - TCGA metrics: - accuracy - f1 model-index: - name: PathQwen2.5 results: - task: type: text-classification name: TCGA cancer type identification (32 classes) dataset: type: TCGA-pathology-reports name: TCGA pathology test set (n=1266) metrics: - type: accuracy value: 0.922 - type: f1 value: 0.871 - task: type: text-classification name: Anatomical primary site (49 classes) dataset: type: TCGA-pathology-reports name: TCGA pathology test set (n=1251) metrics: - type: accuracy value: 0.895 - type: f1 value: 0.350 - task: type: text-classification name: Histology (ICD-O-3 morphology) dataset: type: TCGA-pathology-reports name: TCGA pathology test set (n=1251) metrics: - type: accuracy value: 0.669 - type: f1 value: 0.185 - task: type: text-classification name: AJCC pathological stage (4 classes) dataset: type: TCGA-pathology-reports name: TCGA pathology test set (n=810) metrics: - type: accuracy value: 0.503 - type: f1 value: 0.349 - task: type: text-classification name: Pathological T stage dataset: type: TCGA-pathology-reports name: TCGA pathology test set (n=930) metrics: - type: accuracy value: 0.793 - type: f1 value: 0.450 - task: type: text-classification name: Pathological N stage dataset: type: TCGA-pathology-reports name: TCGA pathology test set (n=917) metrics: - type: accuracy value: 0.823 - type: f1 value: 0.655 - task: type: text-classification name: Pathological M stage dataset: type: TCGA-pathology-reports name: TCGA pathology test set (n=809) metrics: - type: accuracy value: 0.633 - type: f1 value: 0.387 - task: type: text-classification name: Prior malignancy (binary) dataset: type: TCGA-pathology-reports name: TCGA pathology test set (n=1190) metrics: - type: accuracy value: 0.892 - type: f1 value: 0.320 - task: type: text-classification name: Prognosis good (binary; survives > per-cohort mean DSS) dataset: type: TCGA-pathology-reports name: TCGA pathology test set (n=1266) metrics: - type: accuracy value: 0.434 - type: f1 value: 0.281 --- # 🧬 PathQwen2.5 β€” Multi-task Pathology LLM for TCGA Cancer Reports **PathQwen2.5** is a LoRA fine-tune of `unsloth/Qwen2.5-7B-Instruct-bnb-4bit` on **45,518 multi-task QA pairs** derived from 8,459 TCGA pathology reports. From a single pathology report, the model jointly extracts **9 clinical fields**: | Field | Type | Label space | |---|---|---| | `cancer_type` | str | 32 TCGA studyId values (paper-comparable) | | `primary_site` | str | 49 anatomical primary sites | | `histology` | str | ICD-O-3 morphology code | | `ajcc_stage` | str | `Stage I` / `Stage II` / `Stage III` / `Stage IV` | | `t_stage` | str | `T0`–`T4`, `Tis`, `TX` | | `n_stage` | str | `N0`–`N3`, `NX` | | `m_stage` | str | `M0`, `M1`, `MX` | | `prior_malignancy` | bool | patient had a prior cancer | | `prognosis_good` | bool | survives > per-cancer mean DSS | Built to **extend** [Saluja et al., *Cancer type, stage and prognosis assessment from pathology reports using LLMs* (Nature Sci. Rep., 2025)](https://doi.org/10.1038/s41598-025-10709-4) β€” 2.6Γ— more training data, 3Γ— more tasks (adds T/N/M stage, site, histology, prior malignancy). --- ## πŸ“Š Test-set evaluation (TCGA, n=1,266 held-out patients) Held-out test set, locked stratified split (5,919 / 1,266 / 1,266 by `studyId Γ— event_status`). Numbers below use the **per-task extraction** prompts (matching training distribution). ### Multi-task accuracy + macro-F1 | Task | n | **Accuracy** | **Macro-F1** | Saluja 2025 acc | Notes | |---|---|---|---|---|---| | cancer_type (32 TCGA studies) | 1,266 | **0.922** | **0.871** | 0.96 | near-paper-grade | | primary_site (49 classes) | 1,251 | **0.895** | 0.350 | β€” | novel task, excellent | | histology (ICD-O-3) | 1,251 | **0.669** | 0.185 | β€” | novel task, solid | | ajcc_stage (I/II/III/IV) | 810 | 0.503 | 0.349 | 0.85 | improvable to ~0.78 with CoT v2 | | t_stage (T0–T4 / Tis / TX) | 930 | **0.793** | 0.450 | β€” | novel task | | n_stage (N0–N3 / NX) | 917 | **0.823** | 0.655 | β€” | novel task | | m_stage (M0 / M1 / MX) | 809 | **0.633** | 0.387 | β€” | novel task | | prior_malignancy | 1,190 | **0.892** | 0.320 | β€” | novel task, excellent | | prognosis_good (binary) | 1,266 | 0.434 | 0.281 | 0.55 | matches paper | > **Inference mode**: use the **per-task prompts** ([snippet below](#-recommended-prompt--the-one-the-model-was-trained-on)) β€” they match the training distribution and produce the numbers above. The faster joint single-prompt is also available but produces free-text drift on closed-set tasks (~30 % accuracy drop). --- ## ✨ Recommended prompt β€” the one the model was trained on The model was fine-tuned with **9 separate per-task prompts** (one question per QA pair). Using the exact training-time prompts gives the best accuracy. ### Per-task system + user templates ```python SYSTEM_PROMPT = ( "You are an expert pathology AI assistant. " "Analyze the pathology report below and extract the requested field. " "Respond ONLY with a single-line JSON object matching the requested schema field. " "Do not include any explanations, headers, or prose." ) TASK_PROMPTS = { "cancer_type": 'What is the TCGA study cancer type? Output: {"cancer_type": "