madrueno/smm4h-heard-2026-tnm-extraction

Python

0

1 commits

updated Apr 27, 2026

See the code

README

TNM Staging Classification from TCGA Pathology Reports

ACL 2026 SMM4H-HeaRD 2026

Task 6: Predicting TNM Staging from TCGA Pathology Reports SMM4H-HeaRD 2026 Workshop @ ACL 2026


This repository contains the URJC team's submission for the TNM multi-label classification challenge: predicting cancer staging components from free-text TCGA pathology reports.

Goal: Build a system that reads pathology reports and predicts the three TNM cancer staging components (Tumor, Node, Metastasis) using NLP models and techniques.

Setup

Requirements

  • Python 3.12+
  • uv as dependency manager

Installation

git clone <repo-url>
cd smm4h-heard-2026-tnm-extraction

uv sync

The TCGA dataset is included in data/raw/.

Project Structure

smm4h-heard-2026-tnm-extraction/
├── data/
│   ├── raw/                            # Original TCGA reports and TNM labels
│   │   ├── text/
│   │   │   └── TCGA_Reports.csv
│   │   └── labels/
│   │       ├── TCGA_T14_patients.csv
│   │       ├── TCGA_N03_patients.csv
│   │       └── TCGA_M01_patients.csv
│   ├── interim/                        # Processed training data
│   │   └── TCGA_T0_TNMX_filtered.csv
│   └── submission/                     # Challenge submission data and predictions
│       ├── 01-validation/
│       └── 02-evaluation/
│
├── models/
│   └── custom/                       # Fine-tuned models (output of training scripts)
│
├── scripts/
│   ├── processing/                   # Data preparation
│   └── experiments/
│       ├── validation/               # Phase 1 scripts
│       │   ├── train/
│       │   ├── predict/
│       │   └── codabench_scorer.py
│       └── evaluation/               # Phase 2 scripts
│           ├── train/
│           └── predict/
│
├── src/tnm/                          # Shared library
│   ├── config.py                     # Paths and stage constants
│   ├── llm/                          # LLM prompts and chat templates
│   └── training/                     # Trainer classes and utilities
│
├── pyproject.toml
├── uv.lock
└── .gitignore

Challenge Description

Task

Multi-label classification of cancer TNM staging from free-text pathology reports (TCGA).

The system predicts three independent labels:

ComponentDescriptionClasses
T (Tumor)Size and extent of the primary tumorT1, T2, T3, T4
N (Node)Spread to regional lymph nodesN0, N1, N2, N3
M (Metastasis)Distant metastasisM0, M1

Data Sources

Pathology Reports

TNM Labels (Ground Truth)

  • Repository: tatonetti-lab/tnm-stage-classifier
  • Local path: data/raw/labels/
    • TCGA_T14_patients.csv — T stage labels (T1–T4)
    • TCGA_N03_patients.csv — N stage labels (N0–N3)
    • TCGA_M01_patients.csv — M stage labels (M0–M1)

Evaluation Metric

Macro-averaged F1 per stage (T, N, M), then averaged across all three stages. Implemented locally in scripts/experiments/validation/codabench_scorer.py.

Processed Data

data/interim/TCGA_T0_TNMX_filtered.csv

Custom training dataset built from TCGA reports and labels. Generated by scripts/processing/merge_reports_labels_filtered.py.

  • Columns: patient_id, text, t, n, m
  • Excludes records with T0, TX, NX, or MX labels
  • Deduplicates on report text to prevent cross-split leakage
  • Used to fine-tune models in the evaluation phase

Experiments

Phase 1 — Validation

Training data: data/submission/01-validation/challenge/tcga_tnm_train.csv

Training scripts (scripts/experiments/validation/train/):

  • train_validation_bioclinicalmodernbert_{t,n,m}.py — Fine-tune BioClinical-ModernBERT-large per stage
  • train_validation_qwen_27b_{t,n,m}.py — SFT fine-tune Qwen3.5-27B per stage

Prediction scripts (scripts/experiments/validation/predict/):

ScriptDescription
predict_validation_majority.pyMajority-class baseline
predict_validation_logreg.pyBoW + Logistic Regression
predict_validation_regex.pyRegex extraction
predict_validation_cbb.pyClinical-BigBird baseline (jkefeli)
predict_validation_bioclinicalmodernbert.pyFine-tuned BioClinical-ModernBERT
predict_validation_qwen_zs.pyQwen3.5-27B zero-shot
predict_validation_qwen_sft.pyQwen3.5-27B SFT fine-tuned
predict_validation_regex_qwen_zs.pyRegex + Qwen ZS fallback
predict_validation_regex_qwen_sft.pyRegex + Qwen SFT fallback

Phase 2 — Evaluation

Training data: data/interim/TCGA_T0_TNMX_filtered.csv

Training scripts (scripts/experiments/evaluation/train/):

  • train_evaluation_qwen_27b_{t,n,m}.py — SFT fine-tune Qwen3.5-27B per stage on full filtered dataset

Prediction scripts (scripts/experiments/evaluation/predict/):

ScriptDescription
predict_evaluation_regex.pyRegex extraction
predict_evaluation_qwen_zs.pyQwen3.5-27B zero-shot
predict_evaluation_qwen_sft.pyQwen3.5-27B SFT fine-tuned
predict_evaluation_regex_qwen_zs.pyRegex + Qwen ZS fallback
predict_evaluation_regex_qwen_sft.pyRegex + Qwen SFT fallback

Processing Scripts (scripts/processing/)

ScriptDescription
merge_reports_labels_filtered.pyBuild TCGA_T0_TNMX_filtered.csv from raw data
shift_t_labels.pyShift T labels down by 1 in a prediction file (experimental correction)

Submission

The challenge on Codabench has 2 phases. Data for each phase is in data/submission/:

data/submission/
├── 01-validation/
│   ├── challenge/   ← organiser-provided data (train + unlabelled val)
│   └── predict/     ← predictions to upload
├── 02-evaluation/
│   ├── challenge/   ← blind test set (provided by organisers)
│   └── predict/     ← predictions to upload

madrueno/smm4h-heard-2026-tnm-extraction

Python

0

1 commits

updated Apr 27, 2026

See the code

README

TNM Staging Classification from TCGA Pathology Reports

ACL 2026 SMM4H-HeaRD 2026

Task 6: Predicting TNM Staging from TCGA Pathology Reports SMM4H-HeaRD 2026 Workshop @ ACL 2026


This repository contains the URJC team's submission for the TNM multi-label classification challenge: predicting cancer staging components from free-text TCGA pathology reports.

Goal: Build a system that reads pathology reports and predicts the three TNM cancer staging components (Tumor, Node, Metastasis) using NLP models and techniques.

Setup

Requirements

  • Python 3.12+
  • uv as dependency manager

Installation

git clone <repo-url>
cd smm4h-heard-2026-tnm-extraction

uv sync

The TCGA dataset is included in data/raw/.

Project Structure

smm4h-heard-2026-tnm-extraction/
├── data/
│   ├── raw/                            # Original TCGA reports and TNM labels
│   │   ├── text/
│   │   │   └── TCGA_Reports.csv
│   │   └── labels/
│   │       ├── TCGA_T14_patients.csv
│   │       ├── TCGA_N03_patients.csv
│   │       └── TCGA_M01_patients.csv
│   ├── interim/                        # Processed training data
│   │   └── TCGA_T0_TNMX_filtered.csv
│   └── submission/                     # Challenge submission data and predictions
│       ├── 01-validation/
│       └── 02-evaluation/
│
├── models/
│   └── custom/                       # Fine-tuned models (output of training scripts)
│
├── scripts/
│   ├── processing/                   # Data preparation
│   └── experiments/
│       ├── validation/               # Phase 1 scripts
│       │   ├── train/
│       │   ├── predict/
│       │   └── codabench_scorer.py
│       └── evaluation/               # Phase 2 scripts
│           ├── train/
│           └── predict/
│
├── src/tnm/                          # Shared library
│   ├── config.py                     # Paths and stage constants
│   ├── llm/                          # LLM prompts and chat templates
│   └── training/                     # Trainer classes and utilities
│
├── pyproject.toml
├── uv.lock
└── .gitignore

Challenge Description

Task

Multi-label classification of cancer TNM staging from free-text pathology reports (TCGA).

The system predicts three independent labels:

ComponentDescriptionClasses
T (Tumor)Size and extent of the primary tumorT1, T2, T3, T4
N (Node)Spread to regional lymph nodesN0, N1, N2, N3
M (Metastasis)Distant metastasisM0, M1

Data Sources

Pathology Reports

TNM Labels (Ground Truth)

  • Repository: tatonetti-lab/tnm-stage-classifier
  • Local path: data/raw/labels/
    • TCGA_T14_patients.csv — T stage labels (T1–T4)
    • TCGA_N03_patients.csv — N stage labels (N0–N3)
    • TCGA_M01_patients.csv — M stage labels (M0–M1)

Evaluation Metric

Macro-averaged F1 per stage (T, N, M), then averaged across all three stages. Implemented locally in scripts/experiments/validation/codabench_scorer.py.

Processed Data

data/interim/TCGA_T0_TNMX_filtered.csv

Custom training dataset built from TCGA reports and labels. Generated by scripts/processing/merge_reports_labels_filtered.py.

  • Columns: patient_id, text, t, n, m
  • Excludes records with T0, TX, NX, or MX labels
  • Deduplicates on report text to prevent cross-split leakage
  • Used to fine-tune models in the evaluation phase

Experiments

Phase 1 — Validation

Training data: data/submission/01-validation/challenge/tcga_tnm_train.csv

Training scripts (scripts/experiments/validation/train/):

  • train_validation_bioclinicalmodernbert_{t,n,m}.py — Fine-tune BioClinical-ModernBERT-large per stage
  • train_validation_qwen_27b_{t,n,m}.py — SFT fine-tune Qwen3.5-27B per stage

Prediction scripts (scripts/experiments/validation/predict/):

ScriptDescription
predict_validation_majority.pyMajority-class baseline
predict_validation_logreg.pyBoW + Logistic Regression
predict_validation_regex.pyRegex extraction
predict_validation_cbb.pyClinical-BigBird baseline (jkefeli)
predict_validation_bioclinicalmodernbert.pyFine-tuned BioClinical-ModernBERT
predict_validation_qwen_zs.pyQwen3.5-27B zero-shot
predict_validation_qwen_sft.pyQwen3.5-27B SFT fine-tuned
predict_validation_regex_qwen_zs.pyRegex + Qwen ZS fallback
predict_validation_regex_qwen_sft.pyRegex + Qwen SFT fallback

Phase 2 — Evaluation

Training data: data/interim/TCGA_T0_TNMX_filtered.csv

Training scripts (scripts/experiments/evaluation/train/):

  • train_evaluation_qwen_27b_{t,n,m}.py — SFT fine-tune Qwen3.5-27B per stage on full filtered dataset

Prediction scripts (scripts/experiments/evaluation/predict/):

ScriptDescription
predict_evaluation_regex.pyRegex extraction
predict_evaluation_qwen_zs.pyQwen3.5-27B zero-shot
predict_evaluation_qwen_sft.pyQwen3.5-27B SFT fine-tuned
predict_evaluation_regex_qwen_zs.pyRegex + Qwen ZS fallback
predict_evaluation_regex_qwen_sft.pyRegex + Qwen SFT fallback

Processing Scripts (scripts/processing/)

ScriptDescription
merge_reports_labels_filtered.pyBuild TCGA_T0_TNMX_filtered.csv from raw data
shift_t_labels.pyShift T labels down by 1 in a prediction file (experimental correction)

Submission

The challenge on Codabench has 2 phases. Data for each phase is in data/submission/:

data/submission/
├── 01-validation/
│   ├── challenge/   ← organiser-provided data (train + unlabelled val)
│   └── predict/     ← predictions to upload
├── 02-evaluation/
│   ├── challenge/   ← blind test set (provided by organisers)
│   └── predict/     ← predictions to upload