Skip to content
 
 

Latest commit

 

History

37 Commits

Folders and files

NameName
Last commit message
Last commit date
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

CLEF: Controllable Sequence Editing for Biological and Clinical Trajectories

Authors:

Overview of CLEF

Counterfactual thinking is a fundamental objective in biology and medicine. "What if" scenarios are critical for reasoning about the underlying mechanisms of cells, patients, diseases, and drugs: "What if we treat the cells with the drug every one or 24 hours?" and "What if we perform the surgery on the patient today or next year?" We should reason about both the choice and timing of the counterfactual condition. Thus, counterfactual generation requires precise and context-specific edits that adhere to temporal and structural constraints.

Sequence models generate counterfactuals by modifying parts of a sequence based on a given condition, enabling reasoning about "what if" scenarios. While these models excel at conditional generation, they lack fine-grained control over when and where edits occur. Existing approaches either focus on univariate sequences or assume that interventions affect the entire sequence globally. However, many applications require precise, localized modifications, where interventions take effect only after a specified time and impact only a subset of co-occurring variables.

We develop CLEF, a controllable sequence editing approach for instance-wise counterfactual generation. CLEF learns temporal concepts that represent the trajectories of the sequences to enable accurate counterfactual generation guided by a given condition. We show that the learned temporal concepts help preserve temporal and structural constraints in the generated outputs. By design, CLEF is flexible with any type of sequential data encoder. We demonstrate through comprehensive experiments on four novel benchmark datasets in cellular reprogramming and patient immune dynamics that CLEF outperforms state-of-the-art models by up to 36.01% and 65.71% (MAE) on immediate and delayed sequence editing, respectively. We also show that any pretrained sequence encoder can gain controllable sequence editing capabilities when finetuned with CLEF. Moreover, CLEF outperforms baselines in zero-shot counterfactual generation of cellular trajectories by up to 14.45% and 63.19% (MAE) on immediate and delayed sequence editing, respectively. Further, precise edits via user interaction can be performed directly on CLEF's learned concepts. We demonstrate through real-world case studies that CLEF, given precise edits on specific temporal concepts, can generate realistic "healthy" counterfactual trajectories for patients originally with type 1 diabetes mellitus.

Installation and Setup

1️⃣ Download the Repo

First, clone the GitHub repository:

git clone https://github.com/mims-harvard/CLEF
cd CLEF

2️⃣ File and Folder Configurations

Step 2a) Inside CLEF/project_config.py, change PROJECT_DIR = [insert your own project directory path].

Step 2b) Create an empty CLEF/results folder.

3️⃣ Set Up Environment

This codebase leverages Python, Pytorch, etc. To create an environment with all of the required packages, please ensure that conda is installed and then execute the commands:

conda env create -f environment.yml
conda activate clef_env

Please note that the environment file is for Linux environments and not compatible with macOS. If you're using a cluster, it's recommended to run conda env create -f environment.yml in an interactive node first before you submit your job script. Inside your job script, include the following before you run the training file:

source ~/.bashrc
conda activate clef_env

4️⃣ Set Up Wandb

Step 4a) Inside CLEF/model/train.py, replace the entity in the wandb.innit function to be your Wandb team name.

wandb.init(config = hparams_raw, project = "clef_project", entity = "[insert your Wandb team name]")

To find your Wandb team name: log into wandb → go to user settings → look under 'Default Team' to find your team location.

Step 4b) There are two common ways to log into wandb

  1. Run wandb login in your terminal
  2. Inside your SLURM job script, include export WANDB_API_KEY = [your API key] before you run the training file.

Additional Resources

@article{li2026clef,
  title={Controllable Sequence Editing for Biological and Clinical Trajectories},
  author={Li, Michelle M and Li, Kevin and Ektefaie, Yasha and Jin, Ying and Huang, Yepeng and Messica, Shvat and Cai, Tianxi and Zitnik, Marinka},
  journal={arXiv:2502.03569},
  year={2025}
}

Questions

Please leave a Github issue or contact Michelle Li at michelleli@g.harvard.edu.

About

Controllable Sequence Editing for Counterfactual Generation

Resources

Stars

0 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages