> ## Documentation Index
> Fetch the complete documentation index at: https://docs.priorlabs.ai/llms.txt
> Use this file to discover all available pages before exploring further.

> ## Agent Instructions
> TabPFN-3 and later versions support up to 1,000,000 rows, subject to feature count and checkpoint/API limits.
> For large datasets, use per-estimator subsampling, e.g. inference_config={"SUBSAMPLE_SAMPLES": 100_000}, in TabPFNClassifier or TabPFNRegressor from tabpfn or tabpfn_client.
> Pass raw pandas DataFrames to fit and predict. Categorical strings/categories, raw text, and missing feature values are handled automatically; no manual integer/one-hot encoding, imputation, scaling, or outlier removal is needed.

# Energy-based data generation

> TabEBM: Tabular Energy-Based Model for synthetic data generation.

## Installation

```bash theme={null}
pip install tabpfn-extensions
```

## `TabEBM`

[ View source ](https://github.com/PriorLabs/tabpfn-extensions/blob/840c15a1848a986b39c85bc17efc61e0e377f983/src/tabpfn_extensions/tabebm/tabebm.py#L63)

`TabEBM`: Tabular Energy-Based Model for synthetic data generation.

This class implements an energy-based model that uses TabPFN as the underlying
classifier to define energy functions. It generates synthetic tabular data
using Stochastic Gradient Langevin Dynamics (SGLD) sampling.

The core idea is to treat each class as having its own energy landscape,
where real data points have low energy and synthetic points are generated
by following the energy gradient through SGLD sampling.

Initialize `TabEBM` with optimized configuration.

```python theme={null}
TabEBM(
    max_data_size: int = 10000,
)
```

**Parameters**

| Parameter | Type | Default | Description |
| - | - | - | - |
| `max_data_size` | `int` | `10000` | Maximum number of data points to use for training.           Larger datasets will be subsampled to this size. |

***

## `TabEBM.add_surrogate_negative_samples`

[ View source ](https://github.com/PriorLabs/tabpfn-extensions/blob/840c15a1848a986b39c85bc17efc61e0e377f983/src/tabpfn_extensions/tabebm/tabebm.py#L579)

Create surrogate negative samples for [`TabEBM`](https://docs.priorlabs.ai/api-reference/python/tabpfn-extensions/tabebm#tabebm-tabebm-tabebm)'s binary classification approach.

This method creates artificial "negative" samples at specified distances from the origin
to enable energy-based modeling through binary classification. The surrogate negatives
help define the energy landscape by providing clear decision boundaries.

For 2D data, negatives are placed at the four corners of a square centered at origin.
For higher dimensions, random combinations of ±`distance_negative_class` are used.

```python theme={null}
TabEBM.add_surrogate_negative_samples(
    X: np.ndarray | torch.Tensor,
    distance_negative_class: float = 5,
) -> tuple[np.ndarray | torch.Tensor, np.ndarray | torch.Tensor]
```

**Parameters**

| Parameter | Type | Default | Description |
| - | - | - | - |
| `X` | `np.ndarray \| torch.Tensor` | Required | Real data samples (expected to be approximately standardized) Shape: (num\_samples, num\_features) |
| `distance_negative_class` | `float` | `5` | Distance of surrogate negatives from origin                    Larger values create more distinct separation |

**Returns**

| Type | Description |
| - | - |
| `tuple[np.ndarray \| torch.Tensor, np.ndarray \| torch.Tensor]` | Tuple of (X\_ebm, y\_ebm) where: - X\_ebm: Combined real and surrogate samples - y\_ebm: Binary labels (0 for real data, 1 for surrogates) |

***

## `TabEBM.compute_energy`

[ View source ](https://github.com/PriorLabs/tabpfn-extensions/blob/840c15a1848a986b39c85bc17efc61e0e377f983/src/tabpfn_extensions/tabebm/tabebm.py#L529)

Compute [`TabEBM`](https://docs.priorlabs.ai/api-reference/python/tabpfn-extensions/tabebm#tabebm-tabebm-tabebm) class-specific energy function.

The energy function is defined as:
E\_c(x) = -log(exp(f^c(x)\[0]) + exp(f^c(x)\[1]))

Where f^c(x) are the logits from the class-specific binary classifier.
Lower energy corresponds to higher probability of belonging to the target class.

```python theme={null}
TabEBM.compute_energy(
    logits: torch.Tensor | np.ndarray,
    return_unnormalized_prob: bool = False,
) -> torch.Tensor | np.ndarray
```

**Parameters**

| Parameter | Type | Default | Description |
| - | - | - | - |
| `logits` | `torch.Tensor \| np.ndarray` | Required | Model's unnormalized logits for each class    Shape: (num\_samples, num\_classes) |
| `return_unnormalized_prob` | `bool` | `False` | If `True`, return exp(-energy) instead of energy |

**Returns**

| Type | Description |
| - | - |
| `torch.Tensor \| np.ndarray` | Energy values (or unnormalized probabilities) for each sample |

**Raises**

`ValueError`

If logits are not unnormalized or have wrong type

***

## `TabEBM.generate`

[ View source ](https://github.com/PriorLabs/tabpfn-extensions/blob/840c15a1848a986b39c85bc17efc61e0e377f983/src/tabpfn_extensions/tabebm/tabebm.py#L112)

Generate synthetic samples using Stochastic Gradient Langevin Dynamics (SGLD).

This method creates synthetic data by treating the TabPFN classifier as an energy
function and using SGLD to sample from the learned energy landscape. For each class,
it creates a binary classification problem (target class vs surrogate negatives)
and samples new points by following energy gradients.

```python theme={null}
TabEBM.generate(
    X: np.ndarray | torch.Tensor | pd.DataFrame,
    y: np.ndarray | torch.Tensor | pd.Series,
    num_samples: int,
    starting_point_noise_std: float = 0.01,
    sgld_step_size: float = 0.1,
    sgld_noise_std: float = 0.01,
    sgld_steps: int = 200,
    distance_negative_class: float = 5,
    seed: int = 42,
    verbose: bool = False,
) -> dict[str, np.ndarray]
```

**Parameters**

| Parameter | Type | Default | Description |
| - | - | - | - |
| `X` | `np.ndarray \| torch.Tensor \| pd.DataFrame` | Required | Input features of shape (n\_samples, n\_features) |
| `y` | `np.ndarray \| torch.Tensor \| pd.Series` | Required | Target labels of shape (n\_samples,) |
| `num_samples` | `int` | Required | Number of synthetic samples to generate per class |
| `starting_point_noise_std` | `float` | `0.01` | Standard deviation of noise added to real data                     points when initializing SGLD chains |
| `sgld_step_size` | `float` | `0.1` | Step size for gradient updates in SGLD sampling |
| `sgld_noise_std` | `float` | `0.01` | Standard deviation of noise added at each SGLD step |
| `sgld_steps` | `int` | `200` | Number of SGLD steps to perform |
| `distance_negative_class` | `float` | `5` | Distance for placing surrogate negative samples                    from the origin (used to create binary classification) |
| `seed` | `int` | `42` | Random seed for reproducibility |
| `verbose` | `bool` | `False` | Whether to print verbose information during sampling |

**Returns**

| Type | Description |
| - | - |
| `dict[str, np.ndarray]` | Dictionary mapping class names to generated samples: \{     'class\_0': [`np.ndarray`](https://numpy.org/doc/stable/reference/generated/numpy.ndarray.html) of shape (`num_samples`, n\_features),     'class\_1': [`np.ndarray`](https://numpy.org/doc/stable/reference/generated/numpy.ndarray.html) of shape (`num_samples`, n\_features),     ... } |

***

## `TabEBM.train_test_split_allow_full_train`

[ View source ](https://github.com/PriorLabs/tabpfn-extensions/blob/840c15a1848a986b39c85bc17efc61e0e377f983/src/tabpfn_extensions/tabebm/tabebm.py#L669)

Enhanced train-test split that supports full training mode.

This method extends sklearn's train\_test\_split to handle the case where
`test_size`=0, which means we want to use all data for training (no validation).
This is useful for [`TabEBM`](https://docs.priorlabs.ai/api-reference/python/tabpfn-extensions/tabebm#tabebm-tabebm-tabebm)'s energy-based training approach.

```python theme={null}
TabEBM.train_test_split_allow_full_train(
    X: np.ndarray | torch.Tensor,
    y: np.ndarray | torch.Tensor,
    test_size: float | None = None,
    train_size: float | None = None,
    random_state: int | None = None,
    shuffle: bool = True,
    stratify: np.ndarray | torch.Tensor | None = None,
) -> tuple[np.ndarray | torch.Tensor, np.ndarray | torch.Tensor, np.ndarray | torch.Tensor, np.ndarray | torch.Tensor]
```

**Parameters**

| Parameter | Type | Default | Description |
| - | - | - | - |
| `X` | `np.ndarray \| torch.Tensor` | Required | — |
| `y` | `np.ndarray \| torch.Tensor` | Required | — |
| `test_size` | `float \| None` | `None` | Fraction of data for testing (if 0, enables full train mode) |
| `train_size` | `float \| None` | `None` | Fraction of data for training |
| `random_state` | `int \| None` | `None` | Random seed for reproducibility |
| `shuffle` | `bool` | `True` | Whether to shuffle data before splitting |
| `stratify` | `np.ndarray \| torch.Tensor \| None` | `None` | Array-like for stratified splitting |

**Returns**

| Type | Description |
| - | - |
| `tuple[np.ndarray \| torch.Tensor, np.ndarray \| torch.Tensor, np.ndarray \| torch.Tensor, np.ndarray \| torch.Tensor]` | Tuple of (X\_train, X\_val, y\_train, y\_val) In full train mode, X\_train=`X` and y\_train=y |

***

## `seed_everything`

[ View source ](https://github.com/PriorLabs/tabpfn-extensions/blob/840c15a1848a986b39c85bc17efc61e0e377f983/src/tabpfn_extensions/tabebm/tabebm.py#L45)

Set random seeds for reproducibility across all libraries.

```python theme={null}
seed_everything(
    seed: int,
) -> None
```

**Parameters**

| Parameter | Type | Default | Description |
| - | - | - | - |
| `seed` | `int` | Required | Random seed value |

**Returns**

| Type | Description |
| - | - |
| `None` | — |

***

## `to_numpy`

[ View source ](https://github.com/PriorLabs/tabpfn-extensions/blob/840c15a1848a986b39c85bc17efc61e0e377f983/src/tabpfn_extensions/tabebm/tabebm.py#L21)

Convert input data to numpy array format.

```python theme={null}
to_numpy(
    X: np.ndarray | torch.Tensor | pd.DataFrame | None,
) -> np.ndarray | None
```

**Parameters**

| Parameter | Type | Default | Description |
| - | - | - | - |
| `X` | `np.ndarray \| torch.Tensor \| pd.DataFrame \| None` | Required | Input data in various formats (numpy array, torch tensor, pandas DataFrame, or `None`) |

**Returns**

| Type | Description |
| - | - |
| `np.ndarray \| None` | numpy array representation of the input data, or `None` if input is `None` |

**Raises**

`ValueError`

If input type is not supported


This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.