temporal
Welcome to the temporal
tutorial! In this guide, you’ll learn how to build and train your first time series forecasting model with temporal
. We’ll cover:
build_time_series_transformer
function to instantiate your model..generate()
method to make predictions.In temporal
, you define your model’s architecture using a TransformerTimeSeriesConfig
object. This dataclass allows you to specify everything from the model’s dimensions to the types of layers you want to use.
Let’s start with a simple example: a single-layer encoder-only Transformer with a linear output head for point forecasting.
from temporal.configs import TransformerTimeSeriesConfig
config = TransformerTimeSeriesConfig(
feature_size=1, # The number of features in your time series
context_length=128, # The length of the input sequence
prediction_length=24, # The number of steps to forecast
d_model=64, # The hidden dimension of the model
encoder_blocks=[{"type": "default_encoder"}], # A single encoder layer
output_head_config={"type": "linear", "output_size": 1}, # A linear output head
)
That’s it! You’ve just defined a complete Transformer model.
from temporal.models import build_time_series_transformer
model = build_time_series_transformer(config)
This function takes your configuration and uses the temporal builder and registry to assemble all the necessary components into a complete PyTorch model.
Let’s create some dummy data and make a forecast.
import torch
# Create a dummy input tensor of shape (batch_size, context_length, feature_size)
context = torch.randn(1, 128, 1)
# Generate a forecast for the next 24 time steps
forecast = model.generate(context, prediction_length=24)
print(forecast.shape) # torch.Size([1, 24, 1])
Congratulations! You’ve just built and used your first temporal model.
What’s Next? Now that you’ve seen the basics, you’re ready to explore the more advanced features of temporal. Check out the Core Concepts guide to learn about the underlying design of the framework, or dive into the Transformer Capabilities guide to see all the powerful components that temporal has to offer.