Metadata-Version: 2.5
Name: tstokenizers
Version: 0.1.0
Summary: Time series tokenizer for autoregressive modeling
Author-email: Yi Jiang <yijiang@temporis.co>
License-Expression: Apache-2.0
License-File: LICENSE
Requires-Dist: datasets~=4.8.4
Requires-Dist: numpy~=2.0
Requires-Dist: pandas~=2.2
Requires-Dist: scipy~=1.15
Requires-Dist: tokenizers~=0.21.4
Requires-Dist: transformers~=4.51.3
Description-Content-Type: text/markdown

# tstokenizers

Time series tokenizer for autoregressive modeling. Converts multivariate time
series into text, then trains a BPE tokenizer on it. Based on the FAST method
by Physical Intelligence.

## Installation

```bash
pip install tstokenizers
```

## Usage

Serialize a DataFrame into text. Its row count must be a multiple of
`patch_len`.

```python
from tstokenizers import Serializer
import numpy as np
import pandas as pd

df = pd.DataFrame({
    'sin': np.sin(np.linspace(0, 10, 128)),
    'cos': np.cos(np.linspace(0, 10, 128)),
})
quantiles = df.quantile([0.01, 0.99])

serializer = Serializer(quantiles, patch_len=8, quant_scale=100)
text = serializer.encode(df)
df_decoded = serializer.decode(text)
patch_text_len = serializer.patch_text_len()
```

Train a BPE tokenizer on a Hugging Face dataset with a `text` column:

```bash
tstokenizers-train --dataset-path=path --output-path=path --vocab-size=1024
```

Encode text into token ids:

```python
from transformers import AutoTokenizer
from tstokenizers import Processor

processor = Processor(AutoTokenizer.from_pretrained(path))
token_ids = processor.encode(text, patch_text_len)
```

## Citation

This package applies the FAST approach to time series:

Pertsch et al., "FAST: Efficient Action Tokenization for Vision-Language-Action Models", 2025.
https://arxiv.org/abs/2501.09747

## License

Apache 2.0
