CorrDim: Correlation Dimension for Language Models
CorrDim is a Python library for computing the correlation dimension of autoregressive language models from next-token log-probability vectors, based on the paper "Correlation Dimension of Auto-Regressive Large Language Models" (NeurIPS 2025).
Documentation
Full documentation is available at corrdim.readthedocs.io.
Use the docs site for:
- installation details and backend notes
- the full Python API reference
- CLI documentation
- examples and usage patterns
What CorrDim measures
Given a text and an autoregressive language model, CorrDim measures the text's global structural complexity as perceived by that model.
In practice:
- repetitive or degenerate text tends to have a lower correlation dimension
- ordinary fluent text tends to have a higher dimension
- richer long-range structure can produce an even higher dimension
CorrDim is complementary to local metrics such as perplexity: it focuses on sequence-level geometry, not just token-level prediction quality.
How it works
At a high level, CorrDim:
- converts text into a sequence of next-token log-probability vectors
- optionally reduces the vocabulary dimension
- computes a correlation-integral curve over epsilon thresholds
- estimates the correlation dimension by fitting a line in log-log space
For the mathematical details, see the paper.
Installation
CorrDim requires Python 3.10 or newer.
You may use pip or uv to install corrdim.
pip
Linux GPU users: By default, PyPI distributes CPU-only PyTorch on Linux. If you have an NVIDIA GPU, install CUDA PyTorch first. Choose based on your driver version:
CUDA version Min driver Install command cu126 (default) ≥ 525 pip install torch --index-url https://download.pytorch.org/whl/cu126cu130 ≥ 580 pip install torch --index-url https://download.pytorch.org/whl/cu130(For NVIDIA DGX Spark with GB10, use cu130)
Then, run
pip install corrdim
uv
If using uv, please install PyTorch first before installing corrdim
Linux GPU users: By default, PyPI distributes CPU-only PyTorch on Linux. If you have an NVIDIA GPU, install CUDA PyTorch first. Choose based on your driver version:
CUDA version Min driver Install command cu126 (default) ≥ 525 uv add torch --index https://download.pytorch.org/whl/cu126cu130 ≥ 580 uv add torch --index https://download.pytorch.org/whl/cu130(For NVIDIA DGX Spark with GB10, use cu130)
Then, run
uv add corrdim
Quick start
import torch
import corrdim
result = corrdim.measure_text(
"Your text here...",
model="Qwen/Qwen3-0.6B",
precision=torch.float16,
)
print("corrdim:", result.corrdim)
print("fit_r2:", result.fit_r2)
print("linear_region_bounds:", result.linear_region_bounds)
For batched input:
import torch
import corrdim
results = corrdim.measure_texts(
[
"Short sample A...",
"Short sample B...",
],
model="Qwen/Qwen3-0.6B",
precision=torch.float16,
)
for result in results:
print(result.corrdim, result.fit_r2)
Progressive dimension along the sequence
To fit correlation dimension at multiple prefix lengths without re-running the model for each prefix, use measure_text_progressive. It calls progressive_curve_from_text once, then subsamples prefix indices:
skip_prefix_tokens: first prefix index to include (shorter prefixes are skipped)measure_every_tokens: stride between measured indices, orNone(default) to choose from length: fewer than 100 tokens →1, fewer than 1000 →10, otherwise100
The return value is a ProgressiveDimensionResult: by_prefix maps prefix index to a full DimensionResult; corrdims maps index to the fitted scalar only.
import torch
import corrdim
prog_dims = corrdim.measure_text_progressive(
long_text,
model="Qwen/Qwen3-0.6B",
precision=torch.float16,
skip_prefix_tokens=100,
)
for prefix_len, d in sorted(prog_dims.corrdims.items()):
print(prefix_len, d)
API overview
The most important entry points are:
measure_text/measure_textsfor end-to-end text measurementmeasure_text_progressivefor multiple fitted dimensions along sequence prefixes (one model pass)curve_from_text/curve_from_vectorswhen you want the curve firstestimate_dimension_from_curvewhen you already have saved curve dataprogressive_curve_from_textfor prefix-wise analysiscorrelation_integraland related functions for lower-level tensor workflows
For full API details, signatures, return types, and backend behavior, see the documentation site.
CLI
CorrDim includes a corrdim command-line interface:
corrdim measure-text \
--file data/sep60/chaos.txt \
--model Qwen/Qwen3-0.6B
Additional CLI commands and options are documented at corrdim.readthedocs.io.
Backends
CorrDim supports multiple backends for correlation-integral computation:
tritonpytorchpytorch_fastauto
Set the default backend with:
export CORRDIM_CORRINT_BACKEND=pytorch
Or in Python:
import corrdim
print(corrdim.set_corrint_backend("auto"))
print(corrdim.available_corrint_backends())
Tips for systems with limited GPU RAM (e.g., <10GB)
If you run into out-of-memory errors, reduce block_size (default 512) to lower the peak memory usage during correlation-integral computation:
result = corrdim.measure_text(
text,
model="Qwen/Qwen3-0.6B
",
block_size=128,
)
You can also set forward_chunk_size to control how many tokens are processed per forward pass (reduce this value, e.g. 128, on systems with limited GPU RAM):
result = corrdim.measure_text(
text,
model="Qwen/Qwen3-0.6B",
block_size=128,
forward_chunk_size=128,
)
Citation
@inproceedings{du2025correlation,
title={Correlation Dimension of Auto-Regressive Large Language Models},
author={Du, Xin and Tanaka-Ishii, Kumiko},
booktitle={Advances in Neural Information Processing Systems},
year={2025},
arxiv={2510.21258}
}
Links
- Documentation: https://corrdim.readthedocs.io
- Paper: https://arxiv.org/abs/2510.21258
- Repository: https://github.com/kduxin/corrdim
License
MIT License
Metadata
Release files for corrdim 0.3.8
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | |
|---|---|---|---|
| corrdim-0.3.8.tar.gz | 39.9 kB | Details |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Reset |
|---|---|---|---|---|
| corrdim-0.3.8-py3-none-any.whl | Python 3 | none | any | Details |
Total release size: 70.2 kB
Release files / corrdim-0.3.8.tar.gz
| Download URL | corrdim-0.3.8.tar.gz |
|---|---|
| Size | 39.9 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
0b970968cf00cea8f481eb9095c3c47b0eecf77c35fd1b31b1d6e845869eaf4e
|
|
BLAKE2b-256 checksum How to use checksums |
f2d9072323a49fc9ad2f2d7b7edd1565b8d4a46d0490ddf7f948489263c97730
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
uv/0.11.7 {"installer":{"name":"uv","version":"0.11.7","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Ubuntu","version":"24.04","id":"noble","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":null}
|
Release files / corrdim-0.3.8-py3-none-any.whl
| Download URL | corrdim-0.3.8-py3-none-any.whl |
|---|---|
| Size | 30.3 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
7b417ccd58fc15e1754ae25f0ade0fe5e19b9f9062e717dfb8a4171396e21e83
|
|
BLAKE2b-256 checksum How to use checksums |
e0c7f63ae4f6c3e2d6ee5423d171b14fd2f7a87ec39a45a00f4f82485e3f3cd6
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
uv/0.11.7 {"installer":{"name":"uv","version":"0.11.7","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Ubuntu","version":"24.04","id":"noble","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":null}
|