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 N. Argaw, Isaac S. Kohane

Abstract

While generative foundation models have transformed natural language processing, their application to complex, continuous-time event sequences—such as Electronic Health Records (EHR)—remains challenging due to data irregularity and the lack of standardized tooling. We present Event Stream GPT (ESGPT), an open-source library designed to streamline the pipeline from raw data ingestion to zero-shot evaluation for generative pre-trained transformers on event streams. ESGPT introduces specialized architectures to handle intra-event dependencies and leverages high-performance backends to achieve significant improvements in processing speed and memory efficiency. By providing a unified framework compatible with the Hugging Face ecosystem, ESGPT enables the development of foundation models for medicine and other event-driven domains with the same ease as traditional large language models.

Introduction

The success of Large Language Models (LLMs) is built upon the "foundation model" philosophy: pre-training on massive datasets using a universal objective (next-token prediction) to create versatile models capable of downstream adaptation. However, applying this philosophy to domains like healthcare is non-trivial. Medical data typically takes the form of event streams—sequences of complex events occurring at irregular intervals in continuous time.

Unlike text, where tokens follow a strict ordinal sequence, medical events are inherently multi-dimensional and hierarchical. A single clinical encounter may involve multiple diagnoses, lab orders, and medications, all of which possess internal causal dependencies. Existing tools for processing this data are often fragmented, hardcoded for specific datasets, or unable to scale to the requirements of modern transformer architectures. Event Stream GPT (ESGPT) addresses these gaps by providing a robust, flexible utility for building generative models over these complex sequences.

Methodology and Technical Features

ESGPT is designed to bridge the gap between raw, messy event data and the structured input required by transformer models. The library focuses on three core pillars: configuration-driven pre-processing, high-performance computation, and specialized modeling architectures.

Flexible Pre-processing

ESGPT utilizes a YAML-based configuration system, allowing researchers to define data sources, feature types, and normalization strategies without writing extensive boilerplate code. The library automatically handles outlier detection, vocabulary construction, and data normalization, ensuring that the transition from raw database records to model-ready tensors is reproducible and transparent.

High-Performance Backend

To handle the massive scale of modern EHR datasets, ESGPT leverages the Polars library. By utilizing a multi-threaded, vectorized execution engine, ESGPT can process hundreds of thousands of patient records in minutes. This represents a significant performance leap over traditional Pandas-based pipelines, which often become bottlenecks in large-scale machine learning workflows.

Specialized Architectures

Modeling the "intra-event" relationships is critical for medical accuracy. ESGPT introduces two novel model types to address this:

  • ConditionallyIndependent: This architecture assumes that internal event features are independent of one another given the historical context. This is computationally efficient and serves as a strong baseline.
  • NestedAttention: This more sophisticated approach explicitly models causal dependencies within a single event. For example, it allows the model to learn that a specific medication dosage is dependent on a patient's weight recorded during the same clinical visit, rather than just treating them as simultaneous, unrelated features.

Data Representation and Efficiency

A major hurdle in deep learning for EHR is the high dimensionality and sparsity of the data. Traditional approaches often create dense matrices that waste significant memory on missing values. ESGPT employs an extremely sparse representation strategy, requiring only 1.3% of the memory typically consumed by traditional solutions. This efficiency allows researchers to train larger models on consumer-grade hardware and manage massive datasets like MIMIC-IV with minimal disk footprint.

Empirical Validation

The authors demonstrated the library's versatility and performance across three major datasets:

  1. MIMIC-IV: A public dataset of ~300,000 patients.
  2. All of Us: A diverse US-based EHR dataset (~159,000 subjects).
  3. HF (Heart Failure): A private research dataset (~134,000 subjects).

Key Results

  • Processing Speed: ESGPT successfully pre-processed the entire MIMIC-IV dataset in approximately 30 minutes.
  • Storage Efficiency: The processed MIMIC-IV dataset occupies only 1.2 GB on disk, a dramatic reduction compared to raw PostgreSQL or Parquet formats.
  • End-to-End Integration: In comparison to existing pipelines like TemporAI or MIMIC-Extract, ESGPT is the only tool providing a complete journey from raw extraction to a dedicated PyTorch embedding layer and systematic zero-shot evaluation.

Discussion and Future Work

ESGPT introduces the "universal task" of medicine: predicting the next medical event and its timing. This objective serves as a powerful pre-training mechanism, allowing models to learn the underlying "language" of healthcare. Furthermore, ESGPT is the first library to provide a systematic framework for zero-shot evaluation on event streams, enabling researchers to test a model's ability to perform tasks (such as mortality prediction) without task-specific fine-tuning.

Despite these advancements, the authors note several areas for future development. Currently, the library lacks automated medical logic, such as ontological aggregation (grouping similar drugs) or automatic unit conversion. Future iterations aim to move downstream task specification into the YAML configuration and integrate more robust metrics for fairness, privacy, and bias detection to ensure the ethical deployment of healthcare foundation models.

Summary updated

BibTeX
@inproceedings{mcdermott2023event,
  author = {Matthew B. A. McDermott and Bret Nestor and Peniel N. Argaw and Isaac S. 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