Skip to content
sunlabuiucPublic

Repository files navigation

CTO

Code for Automatically Labeling Clinical Trial Outcomes: A Large-Scale Benchmark for Drug Development

Paper Link (Arxiv): Automatically Labeling Clinical Trial Outcomes: A Large-Scale Benchmark for Drug Development

Dataset Link

Please see Tutorials if you want to play around with CTO as soon as possible. This includes off-the-shelf Google Colab notebooks!

Modules for weakly supervised labeling functions

Each module below turns one data source into weak trial outcome labels, called labeling functions (LFs). The labeling module combines them into the CTO labels.

  • llm_prediction_on_pubmed predicts outcomes from PubMed abstracts. For each drug or biological trial it downloads the abstracts that ClinicalTrials.gov references for the trial and, optionally, the top PubMed search hits for its NCT ID. It keeps the derived, results and search-result abstracts published no later than five years after completion, and selects the two whose titles are closest to the official trial title by PubMedBERT embedding similarity. An LLM then summarizes the two abstracts and predicts success, failure or unsure. The released labels came from gpt-3.5-turbo. The code now defaults to a local model served by vLLM (Qwen/Qwen3.8-27B), with the OpenAI API as an option. The prompt is in get_llm_predictions.py.

  • clinical_trial_linkage links each trial to its likely predecessor trials in earlier phases. Candidates share an intervention type and a generic drug name with the later trial and completed before it started. They are ranked by PubMedBERT embedding similarity and reranked with a cross-encoder. A trial linked to a next-phase trial with a positive cross-encoder score is labeled a success, and a trial with no link a failure, unless it completed within six months of the as-of date. Phase 3 and Phase 2/Phase 3 trials are then matched to FDA Orange Book approvals, and the matched trials are relabeled as successes.

  • news_headlines searches Google News through SerpAPI for "<nct_id> clinical trial", for every completed Phase 1, 2 or 3 drug or biological trial. It scores the title and snippet of each result with the sentiment model cardiffnlp/twitter-roberta-base-sentiment-latest and takes the most common sentiment per trial. A positive or neutral majority votes success, a negative one votes failure, and trials without news abstain.

  • stock_price uses the sponsor's stock price after trial completion. It downloads the daily price history of every sponsor listed in a tickers file from Yahoo Finance. For each trial of those sponsors it computes the 5-day simple moving average (SMA) of the closing price and the slope of that SMA over the 7 trading days after the completion date. A positive slope votes success, and a zero or negative slope votes failure.

  • labeling combines the votes of the modules above with LFs that lfs.py computes from the ClinicalTrials.gov tables of the CTTI (AACT) export, such as trial status, primary-endpoint p-values, results reporting, and the numbers of sites, patients and adverse events. For the LFs that compare a trial's number with a quantile across trials, it scores quantiles from 0.05 to 0.95 per phase (1, 2 and 3) against the labels of the TOP benchmark (all three TOP splits by default) and keeps the LFs whose best accuracy is above 0.5. --label_mode DP uses each kept LF's most accurate quantile, and the other modes use the median. The released labels come from --label_mode RF: a random forest trained on the TOP labels with the other votes as features. By default, the trial status vote and then a significant primary-endpoint p-value take precedence over the model's prediction. A Snorkel label model, majority vote, SVM and logistic regression are also available.

Running the pipeline

pipeline.sh runs the stages you name, in the order given. Settings come from environment variables, and API keys are read from the environment only. ./pipeline.sh with no arguments lists every variable.

Stages

Stage Needs Writes, under SAVE_PATH
download AACT_API_KEY, an API key from a free account at aact.ctti-clinicaltrials.org CTTI_new.zip, the newest CTTI snapshot, unpacked into DATA_PATH
pubmed NCBI_API_KEY and NCBI_EMAIL; a local model server started with llm_prediction_on_pubmed/serve_local_llm.sh (two 48 GB GPUs), or LLM_BACKEND=openai with OPENAI_API_KEY llm_predictions_on_pubmed/pubmed_gpt_outcomes.csv
linkage a GPU; the DrugBank dump in SAVE_PATH/drug_bank/ if you have one (otherwise the bundled clinical_trial_linkage/drug_mapping.json is used); AS_OF_DATE for a fixed cutoff clinical_trial_linkage/trial_linkages/outcome_labels/Merged_all_trial_linkage_outcome_df__FDA_updated.csv
news SERPAPI_API_KEY; weeks at full scale news_headlines/news_lfs.csv
stocks stock_price/tickers.csv with sponsor names and tickers (see stock_price), or TICKERS_PATH stock_labels.csv
labels HINT_PATH, the data/ folder of the TOP repository; CTO_GOLD_PATH, the human gold labels; the outputs of pubmed, linkage, news and stocks phase{1,2,3}_<mode>.csv (the labels), combined_eval_<mode>.csv, run_config_<mode>.json, lf_each_thresh.csv

A full run

pip install -r requirements.txt
export DATA_PATH=/data/cto/ctti SAVE_PATH=/data/cto          # CTTI tables, and every output
export AACT_API_KEY=... NCBI_API_KEY=... NCBI_EMAIL=... SERPAPI_API_KEY=...

./pipeline.sh download
bash llm_prediction_on_pubmed/serve_local_llm.sh &          # Qwen/Qwen3.8-27B through vLLM on GPUs 0,1
./pipeline.sh pubmed linkage news stocks

git clone https://github.com/futianfan/clinical-trial-outcome-prediction
wget https://huggingface.co/datasets/chufangao/CTO/resolve/main/human_labels_2020_2024/human_labels_2020_2024.csv
HINT_PATH=clinical-trial-outcome-prediction/data/ CTO_GOLD_PATH=human_labels_2020_2024.csv \
  LABEL_MODES="RF DP" ./pipeline.sh labels

The labels land in SAVE_PATH/phase{1,2,3}_rf.csv (and _dp.csv for DP); the released labels are the RF ones. The first label mode tunes the per-phase thresholds into lf_each_thresh.csv, and later modes reuse them. Stop the model server once the pubmed stage is done.

Reusing released inputs

The slow or paid stages can be replaced by the files released on Hugging Face. Download a file and point the labels stage at it:

Instead of Set Released file
download DATA_PATH CTTI.zip; it unpacks into a CTTI/ folder, which is the DATA_PATH
linkage LINKAGE_PATH Merged_all_trial_linkage_outcome_df__FDA_updated/Merged_all_trial_linkage_outcome_df__FDA_updated.csv
news STUDIES_WITH_NEWS_PATH news_lfs/news_lfs.csv
stocks STOCK_PATH labels_and_tickers/labels_and_tickers.csv (only its nct_id and Slope columns are read)

The released pubmed_gpt_outcomes.csv predates the prompt fix in get_llm_predictions.py, so rerun the pubmed stage instead of reusing it. GPT_PATH points the labels stage at another copy.

Differences from the release

The released labels also used a labeling function on the number of protocol amendments. It was removed because its source, the ClinicalTrials.gov version history, can only be scraped with a browser, so current runs differ from the release by that labeling function. Everything else is unchanged: with no flags, every script keeps its released behaviour. Options that change labels further (for example PROFILE=v2, lfs.py --lf_polarity abstain or extract_outcome_from_trial_linkage.py --censoring_window per_phase) are opt-in and recorded in run_config_<mode>.json next to the labels.

Tests

The tests run offline on small synthetic inputs, without GPUs, API keys or the full data.

pip install torch --index-url https://download.pytorch.org/whl/cpu   # snorkel needs torch
pip install -r requirements-test.txt
ruff check . && pytest

Reference

@article{gao2024automatically,
  title={Automatically Labeling Clinical Trial Outcomes: A Large-Scale Benchmark for Drug Development},
  author={Gao, Chufan and Pradeepkumar, Jathurshan and Das, Trisha and Thati, Shivashankar and Sun, Jimeng},
  journal={arXiv preprint arXiv:2406.10292},
  year={2024}
}

MIT License

DOI: 10.57967/hf/4597

Authors

Special Thanks

A huge thanks to SerpApi for their powerful search API--an invaluable resource for scalably gathering clinical trial news, making our research faster and more efficient. Specifically, we used SerpAPI to search more than 80,000 clinical trials using their Google search API.

Releases

Packages

Used by

Contributors

Languages