Instructions to use Layer6/CCPFN with libraries, inference providers, notebooks, and local apps. Follow these links to get started.
- Libraries
- CCPFN
How to use Layer6/CCPFN with CCPFN:
# No code snippets available yet for this library. # To use this model, check the repository files and the library's documentation. # Want to help? PRs adding snippets are welcome at: # https://github.com/huggingface/huggingface.js
- Notebooks
- Google Colab
- Kaggle
Add model card, paper link, and usage instructions
#1
by nielsr HF Staff - opened
README.md
CHANGED
|
@@ -1,3 +1,81 @@
|
|
| 1 |
---
|
| 2 |
license: apache-2.0
|
|
|
|
| 3 |
---
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
---
|
| 2 |
license: apache-2.0
|
| 3 |
+
pipeline_tag: other
|
| 4 |
---
|
| 5 |
+
|
| 6 |
+
# CCPFN: Causal Foundation Models with Continuous Treatments
|
| 7 |
+
|
| 8 |
+
This repository contains the weights for **CCPFN** (Continuous Causal Prior-Fitted Network), the first causal foundation model for continuous treatment settings, as presented in the paper [Causal Foundation Models with Continuous Treatments](https://huggingface.co/papers/2605.15133).
|
| 9 |
+
|
| 10 |
+
By leveraging in-context learning, CCPFN estimates the *conditional expected potential outcome* (CEPO), defined as $𝔼[Y(t) \mid X = x]$, predicting causal effects across a wide variety of unseen tasks without any additional training or fine-tuning.
|
| 11 |
+
|
| 12 |
+
* **Repository (Inference):** [layer6ai-labs/CCPFN-inference](https://github.com/layer6ai-labs/CCPFN-inference)
|
| 13 |
+
* **Paper:** [Causal Foundation Models with Continuous Treatments](https://huggingface.co/papers/2605.15133)
|
| 14 |
+
|
| 15 |
+
## Installation
|
| 16 |
+
|
| 17 |
+
You can install the inference package via `pip`:
|
| 18 |
+
|
| 19 |
+
```bash
|
| 20 |
+
pip install ccpfn
|
| 21 |
+
```
|
| 22 |
+
|
| 23 |
+
## Quick Start
|
| 24 |
+
|
| 25 |
+
Here is a simple example demonstrating how to run CCPFN for CEPO estimation:
|
| 26 |
+
|
| 27 |
+
```python
|
| 28 |
+
import numpy as np
|
| 29 |
+
import torch
|
| 30 |
+
from ccpfn import CEPOEstimator
|
| 31 |
+
|
| 32 |
+
device = torch.device("cuda:0" if torch.cuda.is_available() else "cpu")
|
| 33 |
+
|
| 34 |
+
# Define true individual treatment-response function
|
| 35 |
+
def treatment_response(x, t):
|
| 36 |
+
return np.cos(x[..., 0]) + 2 * x[..., 1] * t
|
| 37 |
+
|
| 38 |
+
# Define treatment assignment function
|
| 39 |
+
def treatment(x):
|
| 40 |
+
return 1 + np.sin(x[..., 2])
|
| 41 |
+
|
| 42 |
+
# Create synthetic data - covariates, treatment, outcome
|
| 43 |
+
rng = np.random.default_rng(seed=42)
|
| 44 |
+
n_samples, n_features = 2048, 3
|
| 45 |
+
X = rng.standard_normal((n_samples, n_features))
|
| 46 |
+
T = treatment(X)
|
| 47 |
+
Y = treatment_response(X, T) + 0.1 * rng.standard_normal((n_samples,))
|
| 48 |
+
|
| 49 |
+
# Context/query (train/test) split
|
| 50 |
+
test_ratio = 0.3
|
| 51 |
+
ctx_idx = rng.choice(n_samples, int((1 - test_ratio) * n_samples), replace=False)
|
| 52 |
+
qry_idx = np.setdiff1d(np.arange(n_samples), ctx_idx)
|
| 53 |
+
X_ctx, X_qry = X[ctx_idx], X[qry_idx]
|
| 54 |
+
T_ctx, Y_ctx = T[ctx_idx], Y[ctx_idx]
|
| 55 |
+
T_qry = rng.random((X_qry.shape[0],)) # Counterfactual treatments
|
| 56 |
+
|
| 57 |
+
# CEPO Estimation
|
| 58 |
+
estimator = CEPOEstimator(device=device)
|
| 59 |
+
estimator.fit(X_ctx, T_ctx, Y_ctx)
|
| 60 |
+
cepo_pred = estimator.estimate_cepo(X_qry, T_qry)
|
| 61 |
+
|
| 62 |
+
# Evaluation and results
|
| 63 |
+
cepo_true = treatment_response(X_qry, T_qry)
|
| 64 |
+
rmse = np.sqrt(np.mean((cepo_true - cepo_pred) ** 2))
|
| 65 |
+
print("Results:")
|
| 66 |
+
print(f"RMSE: {rmse:.4f}")
|
| 67 |
+
```
|
| 68 |
+
|
| 69 |
+
## Citation
|
| 70 |
+
|
| 71 |
+
```bibtex
|
| 72 |
+
@misc{stith2026causalfoundationmodelscontinuous,
|
| 73 |
+
title={Causal Foundation Models with Continuous Treatments},
|
| 74 |
+
author={Christopher Stith and Medha Barath and Vahid Balazadeh and Jesse C. Cresswell and Rahul G. Krishnan},
|
| 75 |
+
year={2026},
|
| 76 |
+
eprint={2605.15133},
|
| 77 |
+
archivePrefix={arXiv},
|
| 78 |
+
primaryClass={cs.LG},
|
| 79 |
+
url={https://arxiv.org/abs/2605.15133},
|
| 80 |
+
}
|
| 81 |
+
```
|