Skip to content

Embeddings

polars_ts.adapters.embeddings

Foundation model embedding adapters (Chronos, MOMENT).

Extract fixed-length embedding vectors from pre-trained time series foundation models, returning a polars DataFrame suitable for downstream clustering or classification.

_extract_series(df, target_col, id_col, time_col)

Extract per-series arrays, preserving variable lengths.

_arrays_to_result(ids, embeddings, id_col, prefix)

Convert id list + embedding matrix to a polars DataFrame.

to_chronos_embeddings(df, model_name='amazon/chronos-t5-small', target_col='y', id_col='unique_id', time_col='ds', device='cpu', batch_size=32, trust_remote_code=False)

Extract embeddings from a Chronos foundation model.

Loads the specified Chronos model and extracts encoder embeddings for each time series, mean-pooled over the time dimension.

Requires torch and transformers.

Parameters

df Input DataFrame with time series data. model_name HuggingFace model identifier for a Chronos model. target_col Column with the values to embed. id_col Column identifying each time series. time_col Column with timestamps for ordering. device Torch device ("cpu", "cuda", etc.). batch_size Number of series to process at once. trust_remote_code Whether to allow executing code from the model repository. Security warning: enabling this allows arbitrary code execution from the remote model. Only set to True for models you trust.

Returns

pl.DataFrame DataFrame with columns [id_col, emb_0, emb_1, ..., emb_d].

to_moment_embeddings(df, model_name='AutonLab/MOMENT-1-large', target_col='y', id_col='unique_id', time_col='ds', device='cpu')

Extract embeddings from a MOMENT foundation model.

Loads the specified MOMENT model and extracts representation embeddings for each time series.

Requires torch and momentfm.

Parameters

df Input DataFrame with time series data. model_name HuggingFace model identifier for a MOMENT model. target_col Column with the values to embed. id_col Column identifying each time series. time_col Column with timestamps for ordering. device Torch device ("cpu", "cuda", etc.).

Returns

pl.DataFrame DataFrame with columns [id_col, emb_0, emb_1, ..., emb_d].