Timer-XL can perform zero-shot forecasting by passing a lookback window of time-series data into the model.
Important Implementation Detail: The model output represents a sequence of next-token predictions. To obtain the final forecast for a specific prediction length (e.g., 96), you must select the last token_len tokens from the output sequence.
- Prepare input: Convert your time-series data into a torch tensor of shape
(1, lookback_length, 1). - Forward pass: Call
model(input.unsqueeze(-1), None, None). - Extract prediction: Slice the output to get the last 96 tokens:
output[:, -96:, 0].
# Assuming 'model' is initialized and 'df' is a pandas DataFrame with an 'OT' column
lookback_length = 1440
prediction_length = 96
# Prepare input tensor (1, L, 1)
input_tensor = torch.tensor(df["OT"][:lookback_length]).unsqueeze(0).float()
# Generate forecast
# Note: input is unsqueezed to (1, L, 1) for the model
output = model(input_tensor.unsqueeze(-1), None, None)
# Extract the last 96 tokens as the final prediction
pred = output[:, -96:, 0].squeeze().detach().numpy()