CodeTS: Verifiable Text-to-Time Series Generation via Executable Code

Xudong Yuan, Shunyu Liu, Tongya Zheng, Huiping Zhuang, Mingli Song, Kaixuan ChenarXiv 2026

TL;DR

CodeTS introduces a novel "Text-to-Code-to-TS" paradigm that uses executable Python code as an explicit intermediate interface for text-to-time series generation. By combining synthetic data warmup with execution-guided reinforcement learning, it delivers a powerful zero-shot generation framework that can even outperform fully supervised, domain-specific baselines.

What Problem Does This Paper Address?

Generating realistic time series data from natural language descriptions (Text-to-TS) is a massive boon for domains where data is scarce, sensitive, or expensive to collect, such as healthcare, finance, and climate science. However, current state-of-the-art methods rely on implicit latent spaces to map text directly to numerical sequences. This creates a "black box" where the underlying generation logic is completely hidden, making it impossible to verify if specific constraints (like a particular trend or a sudden spike) are actually being respected, or to directly optimize the generation process.

Figure 1: Illustration of the Text-to-TS process and the proposed Text-to-Code-to-TS process.

Methods

CodeTS solves this by breaking the problem into two explicit steps: Code Generation and Code Execution. Instead of outputting raw numbers, the model generates a structured JSON object containing a set of parameters and a Python function (generate_ts) designed to synthesize the time series.

To train this without human-annotated code, the authors use a clever two-stage pipeline:

  1. Supervised Code Initialization (SFT): They bootstrap the model using rule-based synthetic "Text-Code-TS" triplets generated from structured temporal attributes (e.g., predefined trends, seasonality, local events, and noise).
  2. Reinforcement Learning with Verifiable Rewards (RLVR): To align the model with real-world data where code doesn't exist, they optimize it on real Text-TS pairs using Group Relative Policy Optimization (GRPO). The model is guided by a multi-stage reward function that checks:
  3. Format Validity: Does it output the correct JSON structure?
  4. Code Executability: Does the code compile and run safely in a sandbox?
  5. Time Series Quality: Does the executed output match the target sequence's length, pointwise values (MSE), global shape (Pearson correlation), and statistical variance?
Figure 2: Overview of CodeTS. (a) Synthetic Text-Code-TS triplets are constructed from structured temporal attributes. (b) Execution-based rewards verify normalized format, code executability, and time series quality. (c) The model is first initialized on synthetic triplets by SFT and then optimized on real Text-TS pairs with execution-based rewards and GRPO. At inference time, CodeTS maps input text to normalized code and executes it to generate the target time series.

Datasets

  • Synthetic Dataset: 500 synthetic triplets used for the initial SFT warmup phase.
  • Real-World Training Data: 6,300 real text-time series pairs harvested from diverse public sources (e.g., Alibaba Cluster Trace, Binance BTC/USDT, Google COVID-19 Open Data) to train the RLVR stage.
  • Evaluation Benchmarks: 8 public time-series datasets (ETTh1, ETTh2, ETTm1, ETTm2, Electricity, Exchange, Weather, and Web) converted into text-conditioned benchmarks via a deterministic signal analysis pipeline across three generation lengths (96, 192, and 336 points).

Key Insights and Ideas

  • Code as a Universal Interface: Code serves as an ideal bridge because complex temporal features—like linear trends, sinusoidal seasonality, and Gaussian noise—are easily and explicitly parameterized in programming logic.
  • Learning to Code Without Real Code: The paper proves you don't need a massive dataset of human-written code to teach an LLM to generate domain-specific programs. Synthetic bootstrapping combined with execution-based RL is highly effective.
  • The Power of Verifiable Feedback: By evaluating the output of the code rather than the code tokens themselves, the model learns robust, functional programming logic rather than just memorizing syntax templates.

Key Results

  • Zero-Shot Beats Supervised: Remarkably, CodeTS evaluated zero-shot outperformed fully supervised baselines (like Diffusion-TS and TimeVQVAE) that were trained directly on the target datasets. On average across all benchmarks, CodeTS reduced Mean Squared Error (MSE) from 0.0733 (the best baseline) to 0.0321—a 56.2% relative improvement.
  • Superior Shape Preservation: CodeTS achieved a massive leap in Pearson correlation (0.6808 vs. 0.2279 for the best supervised baseline), showing it captures the true underlying dynamics of the text prompt far better than traditional generative models.
  • Robustness and Reliability: Compared to standard zero-shot LLMs (like GPT-4o-mini or ChatTime), CodeTS maintained a near-100% code execution success rate while drastically reducing alignment errors.
Table 1: Comparison with supervised time series generation baselines. CodeTS is evaluated zero-shot, while all supervised baselines are trained separately on each target dataset and generation length. Bold and underline denote the best and second-best results.

Limitations and Future Work

  • Univariate Only: The current framework is strictly limited to generating univariate (single-variable) time series.
  • Sensitivity to Ambiguity: If a text description is vague or misses crucial temporal attributes, the model can struggle to generate accurate code.
  • Future Directions: The authors plan to extend CodeTS to multivariate temporal data and explore richer execution-based reward functions tailored to highly data-scarce, high-value application scenarios.

Summary updated

BibTeX
@misc{yuan2026codets,
  author = {Xudong Yuan and Shunyu Liu and Tongya Zheng and Huiping Zhuang and Mingli Song and Kaixuan Chen},
  title = {{CodeTS: Verifiable Text-to-Time Series Generation via Executable Code}},
  year = {2026},
  eprint = {2609.15393},
  archivePrefix = {arXiv},
  url = {https://arxiv.org/abs/2609.15393},
}
Figure