Skip to main content

Sample- And Population-Level Causal Discovery from Event Sequences using Autoregressive Models

Project description

seq2cause

seq2cause: Turns any discrete sequence of events into a causal graph using autoregressive models (LLaMA, GPT, RNN, Mamba).

PyPI version License: MIT Python 3.8+

seq2cause is a Python library for Causal Discovery on Discrete Event Sequences. It bridges the gap between Autoregressive Models (Language Models, RNN, Mambda) and Causal Discovery by treating autoregressive models as density estimators to perform parallelized CI-tests on GPUs.

🚀 Key Features

  • Bring Your Own Model: Plug in any HuggingFace/PyTorch model (GPT-2, LLaMA, RNN) trained on your discrete sequences (logs, codes, symbols).
  • Scaling: To thousands of events: The memory complexity scales linearly with the vocabulary and sequence length. Optimized for sparse, high-dimensional streams (e.g., Vehicle Diagnostics, Server Logs, User Journeys).
  • Multiple GPUs Acceleration: Batch processing for analyzing thousands of events in seconds using multiple GPUs.
  • Delayed Effects: Are identifiable up to the sequence length
  • Causal Relationships Type: We explain event-to-event, event-to-outcome causal graphs from single sequences and also an aggregation of global event-to-outcome scenarios with instance time causal graphs and summary causal graph.

📦 Installation

pip install seq2cause

⚡ Quick Start

Recover the causal graph from your logs in 3 lines of code.

📚 How It Works

seq2cause implements the TRACE framework (Temporal Reconstruction via Autoregressive Causal Estimation) for the event-to-event causal discovery and OSCAR for the event-to-outcome.

Graph Types

You can precise the graph types, which includes [redo graph namming and parameters in packages, put time instrance, summary graph]:

  • Event-to-Event (per sequence): Implements the TRACE algorithm using Conditional Mutual Information (CMI) approximation.
  • Event-to-Outcome (per sequence): Implements the OSCAR algorithm which target event-to-outcome relationships using a second autoregressive models to predict outcomes.
  • Event-to-Outcome (global): Implements the CARGO algorithm which aggregate the per-sequence causal graph to provide a global causal relationship of observational data.

Future works

  • Time series: Implements causal discovery for time series using autoregressive models (normalizing flows, AR models)

🔗 Citation

If you use seq2cause in your research, please cite our works:

@software{math2026seq2cause,
  author = {Math, Hugo},
  title = {seq2cause: Sample- and Population-Level Causal Discovery from Event Sequences using Autoregressive Models},
  year = {2026},
  publisher = {PyPI},
  url = {[https://pypi.org/project/seq2cause/](https://pypi.org/project/seq2cause/)},
  version = {0.1.4}
}
@misc{math2026tracescalableamortizedcausal,
      title={Scalable Sample-Level Causal Discovery in Event Sequences via Autoregressive Density Estimation},
      author={Hugo Math and Rainer Lienhart},
      year={2026},
      eprint={2602.01135},
      archivePrefix={arXiv},
      primaryClass={cs.LG},
      url={https://arxiv.org/abs/2602.01135},
}
@inproceedings{
math2025oneshot,
title={One-Shot Multi-Label Causal Discovery in High-Dimensional Event Sequences},
author={Hugo Math and Robin Sch{\"o}n and Rainer Lienhart},
booktitle={NeurIPS 2025 Workshop on CauScien: Uncovering Causality in Science},
year={2025},
url={https://openreview.net/forum?id=z7NT8vGWC2}
}
@inproceedings{
math2025towards,
title={Towards Practical Multi-label Causal Discovery in High-Dimensional Event Sequences via One-Shot Graph Aggregation},
author={Hugo Math and Rainer Lienhart},
booktitle={NeurIPS 2025 Workshop on Structured Probabilistic Inference {\&} Generative Modeling},
year={2025},
url={https://openreview.net/forum?id=1HZfpuDVeW}
}

📄 License

This project is licensed under the MIT License - see the LICENSE file for details.

🔧 Building

Ruff is used to add only clean code. A pre-commit will be automatically run.

pre-commit run --all-files
git add .
git commit -m "corrected import jaxtyping"

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

seq2cause-0.1.4.tar.gz (9.4 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

seq2cause-0.1.4-py3-none-any.whl (8.9 kB view details)

Uploaded Python 3

File details

Details for the file seq2cause-0.1.4.tar.gz.

File metadata

  • Download URL: seq2cause-0.1.4.tar.gz
  • Upload date:
  • Size: 9.4 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.7

File hashes

Hashes for seq2cause-0.1.4.tar.gz
Algorithm Hash digest
SHA256 2bc4f16b691af293741c9a606a51b152c020f6a7918026a0aa2b1fce6c05ec43
MD5 2d5a04c07355ce1d9518b78527c960c9
BLAKE2b-256 75657b957652f08bd4b07bb123fd4e81bdba33367073e5bff6c9220b93b2528b

See more details on using hashes here.

Provenance

The following attestation bundles were made for seq2cause-0.1.4.tar.gz:

Publisher: publish.yml on Mathugo/seq2cause

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file seq2cause-0.1.4-py3-none-any.whl.

File metadata

  • Download URL: seq2cause-0.1.4-py3-none-any.whl
  • Upload date:
  • Size: 8.9 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.7

File hashes

Hashes for seq2cause-0.1.4-py3-none-any.whl
Algorithm Hash digest
SHA256 2f464c47cd51122667df4862feb81526e2eab6c36ec1c61ea075f1790cfb0567
MD5 9e747413cd840b5426ae93b021f71f62
BLAKE2b-256 b9fdd7ccabd97fcfa7ce2d50a8099d2aa94b66e8c08ad3295287e0e122d6c2ea

See more details on using hashes here.

Provenance

The following attestation bundles were made for seq2cause-0.1.4-py3-none-any.whl:

Publisher: publish.yml on Mathugo/seq2cause

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page