Event Stream GPT: A Data Pre-processing and Modeling Library for Generative, Pre-trained Transformers over Continuous-time Sequences of Complex Events

Matthew B. A. McDermott, Bret Nestor, Peniel Argaw, Isaac Kohane

TL;DR

Event Stream GPT (ESGPT) is a new open-source library that brings the power of generative pre-trained transformers (GPTs) to complex, continuous-time event sequences like Electronic Health Records (EHR). By streamlining data pre-processing, sparse embedding, modeling, and zero-shot evaluation, ESGPT overcomes the structural barriers that have previously stalled foundation model research in medicine and other event-driven domains.

What Problem Does This Paper Address?

While Large Language Models (LLMs) excel at processing linear sequences of discrete text tokens, real-world data like medical records consist of continuous-time event streams. These streams present unique challenges: events happen at irregular intervals, feature multi-modal data (e.g., categorical diagnoses alongside continuous lab values), and contain intricate intra-event causal dependencies (e.g., a specific admission type triggers specific medications).

Existing machine learning pipelines lack unified formats, struggle with scalability, and fail to model these complex internal dependencies. This has severely limited the adoption of general-purpose "foundation models" for EHR data, forcing researchers to build fragmented, dataset-specific architectures.

Methods

The authors introduce Event Stream GPT (ESGPT), an end-to-end open-source framework designed to handle the entire lifecycle of event-stream foundation models. Key innovations include:

  • Fast Pre-processing: Leveraging the Polars library to accelerate data manipulation and aggregation across massive datasets.
  • Memory-Efficient Sparse Representation: Instead of scaling with the total vocabulary size, ESGPT's custom PyTorch Dataset and embedding layers use an extremely sparse format that scales linearly only with the actual observations present in a batch.
  • Intra-Event Causal Modeling: Unlike standard text GPTs, ESGPT includes architectures like NestedAttention that allow users to define custom dependency graphs within a single event (e.g., modeling how an event type influences continuous measurements).
  • Hugging Face & PyTorch Lightning Integration: Native compatibility with standard deep learning ecosystems for seamless hyperparameter tuning, generation, and evaluation.
ESGPT End-to-End Data Pipeline

Datasets

The library was validated across three large-scale datasets:

  • MIMIC-IV: A public EHR dataset containing data for ~300,000 patients admitted to the emergency department or ICU.
  • All of Us: A large, public, diverse US-based EHR dataset containing ~159,000 subjects.
  • HF (Heart Failure): A private, IRB-approved dataset from an academic research institution containing ~134,000 patients.

Key Insights and Ideas

  • Sparsity is the Key to Scalability: EHR datasets have massive feature spaces (thousands of possible codes and labs), but any single patient event only contains a tiny fraction of them. By designing a sparse batching strategy, ESGPT avoids the massive memory overhead of traditional dense or multi-indexed dataframes.
  • Events Aren't Just Tokens: Modeling continuous time ($\Delta t$) and internal causal dependencies within a single timestamp requires moving past standard autoregressive token prediction into multi-stage, conditional probability distributions.
  • Standardizing Zero-Shot Evaluation: The authors highlight a critical gap in prior EHR models—the lack of zero-shot evaluation. ESGPT provides a systemized way to perform unsupervised forecasting and map those generations to empirical task labels out of the box.

Key Results

  • Massive Speed and Storage Gains: Pre-processing the entire MIMIC-IV dataset took only ~30 minutes and compressed the output to a mere 1.2 GB on disk.
  • Dramatic Memory Reduction: In the MIMIC-IV example, ESGPT’s sparse batch representation required only 1.3% of the memory compared to traditional, less sparse solutions.
  • Cross-Dataset Versatility: The pipeline successfully generalized to public Parquet data (All of Us) and private CSV data (HF), maintaining rapid processing speeds and significant space reductions across all three settings.

Limitations and Future Work

  • Pre-processing Depth: ESGPT currently lacks advanced clinical pre-processing features like automatic unit conversion or ontological aggregation (e.g., grouping similar medical codes).
  • Downstream Task Definition: Defining fine-tuning tasks still requires writing manual Python code rather than using a simple configuration language.
  • Evaluation Metrics: Future work needs to incorporate dedicated metrics for fairness, privacy sensitivity, and tracking the emergence of foundation model capabilities more cost-efficiently.

Summary updated

BibTeX
@inproceedings{mcdermott2023event,
  author = {Matthew B. A. McDermott and Bret Nestor and Peniel Argaw and Isaac Kohane},
  title = {{Event Stream GPT: A Data Pre-processing and Modeling Library for Generative, Pre-trained Transformers over Continuous-time Sequences of Complex Events}},
  booktitle = {Advances in Neural Information Processing Systems},
  year = {2023},
}
Figure