Chronos<T>

Models & Types · AiDotNet.Finance.Forecasting.Foundation

Chronos-T5 (Ansari et al. 2024) with the finance models’ tensor API: probabilistic forecasting by a T5 language model over mean-scaled, uniformly binned time series tokens.

Inheritance: NeuralNetworkBase<T> → FinancialModelBase<T> → ForecastingModelBase<T> → TimeSeriesFoundationModelBase<T> → Chronos<T>

For Beginners

Chronos turns numbers into “words” (bins) and uses a language model to predict the next words. Sampling many possible continuations and taking their median gives the forecast; their spread gives its uncertainty.

How It Works

This model and ChronosFoundationModel share one network, which matches the official chronos-forecasting code and Hugging Face’s T5 to 1e-12: the MeanScaleUniformBins tokenizer, the T5 v1.0 encoder-decoder, the token cross-entropy, and forecasts as the median of sampled paths (temperature, top-k, top-p). The released checkpoints load with LoadPretrainedWeights into a model built from FromPretrainedConfig.

Forecast reads a context [L] (or a batch [B, L]) and returns the PredictionLength-step median forecast; with quantiles it returns them instead, quantile-major. Training takes a context and the PredictionLength values after it (or a batch of each) and takes one step of the paper’s recipe (AdamW with weight decay 0.01, the learning rate annealed linearly to zero over TrainingSteps) on the cross-entropy of their tokens.

Example

var options = new ChronosFinanceOptions<double>(ChronosOptions<double>.FromPretrainedConfig("chronos-t5-small/config.json"));
var architecture = new NeuralNetworkArchitecture<double>(inputType: InputType.OneDimensional,
    taskType: NeuralNetworkTaskType.Regression, inputSize: options.ContextLength, outputSize: options.PredictionLength);
var model = new Chronos<double>(architecture, options);
model.LoadPretrainedWeights("chronos-t5-small/model.safetensors");
Tensor<double> forecast = model.Forecast(context);

Constructors

Constructor Summary
Chronos(NeuralNetworkArchitecture<T> architecture, ChronosFinanceOptions<T> options, IGradientBasedOptimizer<T, Tensor<T>, Tensor<T>> optimizer) Creates a Chronos-T5, randomly initialized as the official training does.

Properties

Property Summary
FoundationModelSize ModelSize { get; } The released size whose d_model is nearest this model’s (Tiny 256, Mini 384, Small 512, Base 768, Large 1024).
bool IsChannelIndependent { get; }
bool SupportsTraining { get; }
bool UseNativeMode { get; }
int MaxContextLength { get; } The context the model reads; a longer history is truncated to its last ContextLength values.
int MaxPredictionHorizon { get; } The steps one sampling pass predicts; AutoregressiveForecast continues past it.
int NumFeatures { get; }
int NumTokens { get; } The vocabulary: the bins plus PAD and EOS.
int PatchSize { get; }
int PredictionHorizon { get; }
int SequenceLength { get; }
int Stride { get; }

Methods

Method Summary
Dictionary<string, T> Evaluate(Tensor<T> predictions, Tensor<T> actuals)
Dictionary<string, T> GetFinancialMetrics()
Dictionary<string, Tensor<T>> GetNamedLayerActivations(Tensor<T> input) The activations of the layer calls a forecast makes (the network is not a chain of its layers).
ModelMetadata<T> GetModelMetadata()
Tensor<T> ApplyInstanceNormalization(Tensor<T> input) Chronos normalizes inside its tokenizer (mean scaling), so the input passes through unchanged.
Tensor<T> AutoregressiveForecast(Tensor<T> input, int steps) The steps-step median forecast, continuing past PredictionLength as the official pipeline does (the context extended by the median so far).
Tensor<T> Embed(Tensor<T> series) The encoder states of the context’s tokens (the official pipeline’s embed): [L + 1, d_model] for a context [L] (the last ContextLength values and EOS).
void LoadPretrainedWeights(string path) Loads a released Chronos-T5 checkpoint’s model.safetensors; build the model with FromPretrainedConfig of the same checkpoint.
void TrainOnSeries(Tensor<T> series) Trains on one long series with the paper’s recipe (section 5.2 and the official training script): each of TrainingSteps steps draws BatchSize windows split at random points at least MinPast values in, drops observed values with a prob…