Transformers 文件

PatchTST

Hugging Face's logo
加入 Hugging Face 社群

並獲得增強的文件體驗

開始使用

PatchTST

PyTorch

概述

PatchTST 模型由 Yuqi Nie、Nam H. Nguyen、Phanwadee Sinthong 和 Jayant Kalagnanam 在 “A Time Series is Worth 64 Words: Long-term Forecasting with Transformers” 中提出。

從高層次來看,該模型將時間序列向量化為給定大小的補丁,並透過 Transformer 對生成的向量序列進行編碼,然後透過適當的頭部輸出預測長度的預測。該模型如下圖所示:

model

論文摘要如下:

我們提出了一種用於多元時間序列預測和自監督表示學習的基於 Transformer 的高效模型設計。它基於兩個關鍵元件:(i) 將時間序列分割成子序列級別的補丁,作為 Transformer 的輸入 token;(ii) 通道獨立性,其中每個通道包含一個單變數時間序列,並在所有序列中共享相同的嵌入和 Transformer 權重。補丁設計自然具有三重優勢:區域性語義資訊保留在嵌入中;在相同的回溯視窗下,注意力圖的計算和記憶體使用量呈二次減少;模型可以關注更長的歷史。我們的通道獨立補丁時間序列 Transformer (PatchTST) 與 SOTA 基於 Transformer 的模型相比,可以顯著提高長期預測的準確性。我們還將我們的模型應用於自監督預訓練任務,並獲得出色的微調效能,這優於大型資料集上的監督訓練。將掩碼預訓練表示從一個數據集轉移到其他資料集也產生了 SOTA 預測準確性。

該模型由 namctingsinthongdiepivijaye12wmgiffordkashif 貢獻。原始程式碼可以在 這裡 找到。

用法提示

該模型也可以用於時間序列分類和時間序列迴歸。請參閱相應的 PatchTSTForClassificationPatchTSTForRegression 類。

資源

  • 可以在這裡找到一篇深入解釋 PatchTST 的部落格文章。該部落格也可以在 Google Colab 中開啟。

PatchTSTConfig

class transformers.PatchTSTConfig

< >

( num_input_channels: int = 1 context_length: int = 32 distribution_output: str = 'student_t' loss: str = 'mse' patch_length: int = 1 patch_stride: int = 1 num_hidden_layers: int = 3 d_model: int = 128 num_attention_heads: int = 4 share_embedding: bool = True channel_attention: bool = False ffn_dim: int = 512 norm_type: str = 'batchnorm' norm_eps: float = 1e-05 attention_dropout: float = 0.0 positional_dropout: float = 0.0 path_dropout: float = 0.0 ff_dropout: float = 0.0 bias: bool = True activation_function: str = 'gelu' pre_norm: bool = True positional_encoding_type: str = 'sincos' use_cls_token: bool = False init_std: float = 0.02 share_projection: bool = True scaling: typing.Union[str, bool, NoneType] = 'std' do_mask_input: typing.Optional[bool] = None mask_type: str = 'random' random_mask_ratio: float = 0.5 num_forecast_mask_patches: typing.Union[int, list[int], NoneType] = [2] channel_consistent_masking: typing.Optional[bool] = False unmasked_channel_indices: typing.Optional[list[int]] = None mask_value: int = 0 pooling_type: str = 'mean' head_dropout: float = 0.0 prediction_length: int = 24 num_targets: int = 1 output_range: typing.Optional[list] = None num_parallel_samples: int = 100 **kwargs )

引數

  • num_input_channels (int, 可選, 預設為 1) — 目標變數的大小,預設情況下,對於單變數目標為 1。對於多變數目標,將 > 1。
  • context_length (int, 可選, 預設為 32) — 輸入序列的上下文長度。
  • distribution_output (str, 可選, 預設為 "student_t") — 當損失為 "nll" 時,模型的分佈輸出頭。可以是 "student_t"、"normal" 或 "negative_binomial"。
  • loss (str, 可選, 預設為 "mse") — 模型對應於 distribution_output 頭部的損失函式。對於引數分佈,它是負對數似然 ("nll"),對於點估計,它是均方誤差 "mse"。
  • patch_length (int, 可選, 預設為 1) — 定義補丁化過程的補丁長度。
  • patch_stride (int, 可選, 預設為 1) — 定義補丁化過程的步幅。
  • num_hidden_layers (int, 可選, 預設為 3) — 隱藏層數量。
  • d_model (int, 可選, 預設為 128) — Transformer 層的維度。
  • num_attention_heads (int, 可選, 預設為 4) — Transformer 編碼器中每個注意力層的注意力頭數量。
  • share_embedding (bool, 可選, 預設為 True) — 在所有通道中共享輸入嵌入。
  • channel_attention (bool, 可選, 預設為 False) — 啟用 Transformer 中的通道注意力塊,允許通道相互關注。
  • ffn_dim (int, 可選, 預設為 512) — Transformer 編碼器中“中間”(通常稱為前饋)層的維度。
  • norm_type (str , 可選, 預設為 "batchnorm") — 每個 Transformer 層的歸一化型別。可以是 "batchnorm""layernorm"
  • norm_eps (float, 可選, 預設為 1e-05) — 為歸一化的數值穩定性新增到分母的值。
  • attention_dropout (float, 可選, 預設為 0.0) — 注意力機率的 dropout 機率。
  • positional_dropout (float, 可選, 預設為 0.0) — 位置嵌入層中的 dropout 機率。
  • path_dropout (float, 可選, 預設為 0.0) — 殘差塊中的 dropout 路徑。
  • ff_dropout (float, 可選, 預設為 0.0) — 前饋網路兩層之間使用的 dropout 機率。
  • bias (bool, 可選, 預設為 True) — 是否在前饋網路中新增偏置。
  • activation_function (str, 可選, 預設為 "gelu") — Transformer 中的非線性啟用函式(字串)。支援 "gelu""relu"
  • pre_norm (bool, 可選, 預設為 True) — 如果 pre_norm 設定為 True,則在自注意力之前應用歸一化。否則,在殘差塊之後應用歸一化。
  • positional_encoding_type (str, 可選, 預設為 "sincos") — 位置編碼。支援選項 "random""sincos"
  • use_cls_token (bool, 可選, 預設為 False) — 是否使用 cls token。
  • init_std (float, 可選, 預設為 0.02) — 截斷正態權重初始化分佈的標準差。
  • share_projection (bool, 可選, 預設為 True) — 在預測頭部的不同通道之間共享投影層。
  • scaling (Union, 可選, 預設為 "std") — 是否透過“均值”縮放器、“標準差”縮放器或不使用縮放器(如果為 None)來縮放輸入目標。如果為 True,則縮放器設定為“均值”。
  • do_mask_input (bool, 可選) — 在預訓練期間是否應用掩碼。
  • mask_type (str, 可選, 預設為 "random") — 掩碼型別。目前只支援 "random""forecast"
  • random_mask_ratio (float, 可選, 預設為 0.5) — 隨機預訓練期間用於掩蓋輸入資料的掩碼比率。
  • num_forecast_mask_patches (intlist, 可選, 預設為 [2]) — 每個批次樣本末尾要掩碼的補丁數量。如果為整數,則批次中的所有樣本將具有相同數量的掩碼補丁。如果為列表,則批次中的樣本將由列表中定義的數字隨機掩碼。此引數僅用於預測預訓練。
  • channel_consistent_masking (bool, 可選, 預設為 False) — 如果通道一致掩碼為 True,則所有通道將具有相同的掩碼模式。
  • unmasked_channel_indices (list, 可選) — 預訓練期間未掩碼的通道索引。列表中的值是 1 到 num_input_channels 之間的數字。
  • mask_value (int, 可選, 預設為 0) — 掩碼補丁中的值將由 mask_value 填充。
  • pooling_type (str, 可選, 預設為 "mean") — 嵌入的池化型別。支援 "mean""max"None
  • head_dropout (float, 可選, 預設為 0.0) — 頭部的 dropout 機率。
  • prediction_length (int, 可選, 預設為 24) — 模型將輸出的預測範圍。
  • num_targets (int, 可選, 預設為 1) — 迴歸和分類任務的目標數量。對於分類,它是類別數量。
  • output_range (list, 可選) — 迴歸任務的輸出範圍。可以設定輸出值的範圍以強制模型在特定範圍內生成值。
  • num_parallel_samples (int, 可選, 預設為 100) — 為機率預測並行生成的樣本數量。

這是用於儲存 PatchTSTModel 配置的配置類。它用於根據指定的引數例項化 PatchTST 模型,定義模型架構。ibm/patchtst 架構。

配置物件繼承自 PretrainedConfig,可用於控制模型輸出。有關更多資訊,請閱讀 PretrainedConfig 的文件。

>>> from transformers import PatchTSTConfig, PatchTSTModel

>>> # Initializing an PatchTST configuration with 12 time steps for prediction
>>> configuration = PatchTSTConfig(prediction_length=12)

>>> # Randomly initializing a model (with random weights) from the configuration
>>> model = PatchTSTModel(configuration)

>>> # Accessing the model configuration
>>> configuration = model.config

PatchTSTModel

class transformers.PatchTSTModel

< >

( config: PatchTSTConfig )

引數

  • config (PatchTSTConfig) — 模型配置類,包含模型的所有引數。使用配置檔案例項化模型不會載入與模型相關的權重,僅載入配置。請檢視 from_pretrained() 方法來載入模型權重。

裸 PatchTST 模型,輸出原始隱藏狀態,不帶任何特定頭部。

該模型繼承自 PreTrainedModel。請檢視超類文件,瞭解庫為其所有模型實現的通用方法(如下載或儲存、調整輸入嵌入大小、修剪頭部等)。

該模型也是 PyTorch torch.nn.Module 子類。將其作為常規 PyTorch Module 使用,並參考 PyTorch 文件中與一般用法和行為相關的所有事項。

前向傳播

< >

( past_values: Tensor past_observed_mask: typing.Optional[torch.Tensor] = None future_values: typing.Optional[torch.Tensor] = None output_hidden_states: typing.Optional[bool] = None output_attentions: typing.Optional[bool] = None return_dict: typing.Optional[bool] = None )

引數

  • past_values (torch.Tensor,形狀為 (bs, sequence_length, num_input_channels)必需) — 模型的輸入序列。
  • past_observed_mask (torch.BoolTensor,形狀為 (batch_size, sequence_length, num_input_channels)可選) — 布林掩碼,指示哪些 past_values 被觀察到,哪些缺失。掩碼值選擇在 [0, 1]

    • 1 表示**觀察到的**值,
    • 0 表示**缺失**的值(即被零替換的 NaN)。
  • future_values (torch.BoolTensor,形狀為 (batch_size, prediction_length, num_input_channels)可選) — 與 past_values 相關的未來目標值。
  • output_hidden_states (bool, 可選) — 是否返回所有層的隱藏狀態。
  • output_attentions (bool, 可選) — 是否返回所有層的輸出注意力。
  • return_dict (bool, 可選) — 是否返回 ModelOutput 而不是普通元組。

示例

>>> from huggingface_hub import hf_hub_download
>>> import torch
>>> from transformers import PatchTSTModel

>>> file = hf_hub_download(
...     repo_id="hf-internal-testing/etth1-hourly-batch", filename="train-batch.pt", repo_type="dataset"
... )
>>> batch = torch.load(file)

>>> model = PatchTSTModel.from_pretrained("namctin/patchtst_etth1_pretrain")

>>> # during training, one provides both past and future values
>>> outputs = model(
...     past_values=batch["past_values"],
...     future_values=batch["future_values"],
... )

>>> last_hidden_state = outputs.last_hidden_state

PatchTSTForPrediction

class transformers.PatchTSTForPrediction

< >

( config: PatchTSTConfig )

引數

  • config (PatchTSTConfig) — 模型配置類,包含模型的所有引數。使用配置檔案初始化不會載入與模型相關的權重,只加載配置。請檢視 from_pretrained() 方法來載入模型權重。

用於預測的 PatchTST 模型。

該模型繼承自 PreTrainedModel。請檢視超類文件,瞭解庫為其所有模型實現的通用方法(如下載或儲存、調整輸入嵌入大小、修剪頭部等)。

該模型也是 PyTorch torch.nn.Module 子類。將其作為常規 PyTorch Module 使用,並參考 PyTorch 文件中與一般用法和行為相關的所有事項。

前向傳播

< >

( past_values: Tensor past_observed_mask: typing.Optional[torch.Tensor] = None future_values: typing.Optional[torch.Tensor] = None output_hidden_states: typing.Optional[bool] = None output_attentions: typing.Optional[bool] = None return_dict: typing.Optional[bool] = None )

引數

  • past_values (形狀為 (bs, sequence_length, num_input_channels)torch.Tensor必填) — 模型的輸入序列
  • past_observed_mask (形狀為 (batch_size, sequence_length, num_input_channels)torch.BoolTensor可選) — 布林掩碼,用於指示哪些 past_values 被觀測到,哪些是缺失的。掩碼值選擇在 [0, 1] 之間:

    • 1 表示**觀測到的**值,
    • 0 表示**缺失的**值(即被零替換的 NaN)。
  • future_values (形狀為 (bs, forecast_len, num_input_channels)torch.Tensor可選) — 與 past_values 相關的未來目標值
  • output_hidden_states (bool, 可選) — 是否返回所有層的隱藏狀態
  • output_attentions (bool, 可選) — 是否返回所有層的注意力輸出
  • return_dict (bool, 可選) — 是否返回 ModelOutput 而不是普通元組。

示例

>>> from huggingface_hub import hf_hub_download
>>> import torch
>>> from transformers import PatchTSTConfig, PatchTSTForPrediction

>>> file = hf_hub_download(
...     repo_id="hf-internal-testing/etth1-hourly-batch", filename="train-batch.pt", repo_type="dataset"
... )
>>> batch = torch.load(file)

>>> # Prediction task with 7 input channels and prediction length is 96
>>> model = PatchTSTForPrediction.from_pretrained("namctin/patchtst_etth1_forecast")

>>> # during training, one provides both past and future values
>>> outputs = model(
...     past_values=batch["past_values"],
...     future_values=batch["future_values"],
... )

>>> loss = outputs.loss
>>> loss.backward()

>>> # during inference, one only provides past values, the model outputs future values
>>> outputs = model(past_values=batch["past_values"])
>>> prediction_outputs = outputs.prediction_outputs

PatchTSTForClassification

class transformers.PatchTSTForClassification

< >

( config: PatchTSTConfig )

引數

  • config (PatchTSTConfig) — 模型配置類,包含模型的所有引數。使用配置檔案初始化不會載入與模型相關的權重,只加載配置。請檢視 from_pretrained() 方法來載入模型權重。

用於分類的 PatchTST 模型。

該模型繼承自 PreTrainedModel。請檢視超類文件,瞭解庫為其所有模型實現的通用方法(如下載或儲存、調整輸入嵌入大小、修剪頭部等)。

該模型也是 PyTorch torch.nn.Module 子類。將其作為常規 PyTorch Module 使用,並參考 PyTorch 文件中與一般用法和行為相關的所有事項。

前向傳播

< >

( past_values: Tensor target_values: typing.Optional[torch.Tensor] = None past_observed_mask: typing.Optional[bool] = None output_hidden_states: typing.Optional[bool] = None output_attentions: typing.Optional[bool] = None return_dict: typing.Optional[bool] = None ) transformers.models.patchtst.modeling_patchtst.PatchTSTForClassificationOutputtuple(torch.FloatTensor)

引數

  • past_values (形狀為 (bs, sequence_length, num_input_channels)torch.Tensor必填) — 模型的輸入序列
  • target_values (torch.Tensor可選) — 與 past_values 相關的標籤
  • past_observed_mask (形狀為 (batch_size, sequence_length, num_input_channels)torch.BoolTensor可選) — 布林掩碼,用於指示哪些 past_values 被觀測到,哪些是缺失的。掩碼值選擇在 [0, 1] 之間:

    • 1 表示**觀測到的**值,
    • 0 表示**缺失的**值(即被零替換的 NaN)。
  • output_hidden_states (bool可選) — 是否返回所有層的隱藏狀態。有關更多詳細資訊,請參見返回張量下的 hidden_states
  • output_attentions (bool可選) — 是否返回所有注意力層的注意力張量。有關更多詳細資訊,請參見返回張量下的 attentions
  • return_dict (bool可選) — 是否返回 ModelOutput 而不是普通元組。

返回

transformers.models.patchtst.modeling_patchtst.PatchTSTForClassificationOutputtuple(torch.FloatTensor)

一個 transformers.models.patchtst.modeling_patchtst.PatchTSTForClassificationOutput 或一個 torch.FloatTensor 元組(如果傳遞 return_dict=Falseconfig.return_dict=False),包含根據配置 (PatchTSTConfig) 和輸入的不同元素。

  • loss (*可選*,在提供 labels 時返回,形狀為 (1,)torch.FloatTensor) — 總損失,是掩碼語言模型損失和下一個序列預測(分類)損失的總和。

  • prediction_logits (形狀為 (batch_size, num_targets)torch.FloatTensor) — PatchTST 建模頭的預測分數(SoftMax 之前的分數)。

  • hidden_states (tuple[torch.FloatTensor]可選,在傳遞 output_hidden_states=Trueconfig.output_hidden_states=True 時返回) — 形狀為 (batch_size, sequence_length, hidden_size)torch.FloatTensor 元組(如果模型有嵌入層,則包括嵌入層輸出,加上每層輸出)。

    模型在每個層輸出的隱藏狀態以及可選的初始嵌入輸出。

  • attentions (tuple[torch.FloatTensor]可選,在傳遞 output_attentions=Trueconfig.output_attentions=True 時返回) — 形狀為 (batch_size, num_heads, sequence_length, sequence_length)torch.FloatTensor 元組(每層一個)。

    注意力 softmax 後的注意力權重,用於計算自注意力頭中的加權平均值。

PatchTSTForClassification 的前向方法,覆蓋了 __call__ 特殊方法。

儘管前向傳遞的定義需要在此函式中進行,但之後應呼叫 Module 例項,而不是此函式,因為前者負責執行預處理和後處理步驟,而後者會默默地忽略它們。

示例

>>> from transformers import PatchTSTConfig, PatchTSTForClassification

>>> # classification task with two input channel2 and 3 classes
>>> config = PatchTSTConfig(
...     num_input_channels=2,
...     num_targets=3,
...     context_length=512,
...     patch_length=12,
...     stride=12,
...     use_cls_token=True,
... )
>>> model = PatchTSTForClassification(config=config)

>>> # during inference, one only provides past values
>>> past_values = torch.randn(20, 512, 2)
>>> outputs = model(past_values=past_values)
>>> labels = outputs.prediction_logits

PatchTSTForPretraining

class transformers.PatchTSTForPretraining

< >

( config: PatchTSTConfig )

引數

  • config (PatchTSTConfig) — 模型配置類,包含模型的所有引數。使用配置檔案初始化不會載入與模型相關的權重,只加載配置。請檢視 from_pretrained() 方法來載入模型權重。

用於預訓練的 PatchTST 模型。

該模型繼承自 PreTrainedModel。請檢視超類文件,瞭解庫為其所有模型實現的通用方法(如下載或儲存、調整輸入嵌入大小、修剪頭部等)。

該模型也是 PyTorch torch.nn.Module 子類。將其作為常規 PyTorch Module 使用,並參考 PyTorch 文件中與一般用法和行為相關的所有事項。

前向傳播

< >

( past_values: Tensor past_observed_mask: typing.Optional[torch.Tensor] = None output_hidden_states: typing.Optional[bool] = None output_attentions: typing.Optional[bool] = None return_dict: typing.Optional[bool] = None )

引數

  • past_values (形狀為 (bs, sequence_length, num_input_channels)torch.Tensor必填) — 模型的輸入序列
  • past_observed_mask (形狀為 (batch_size, sequence_length, num_input_channels)torch.BoolTensor可選) — 布林掩碼,用於指示哪些 past_values 被觀測到,哪些是缺失的。掩碼值選擇在 [0, 1] 之間:

    • 1 表示**觀測到的**值,
    • 0 表示**缺失的**值(即被零替換的 NaN)。
  • output_hidden_states (bool可選) — 是否返回所有層的隱藏狀態
  • output_attentions (bool可選) — 是否返回所有層的注意力輸出
  • return_dict (bool可選) — 是否返回 ModelOutput 而不是普通元組。

示例

>>> from huggingface_hub import hf_hub_download
>>> import torch
>>> from transformers import PatchTSTConfig, PatchTSTForPretraining

>>> file = hf_hub_download(
...     repo_id="hf-internal-testing/etth1-hourly-batch", filename="train-batch.pt", repo_type="dataset"
... )
>>> batch = torch.load(file)

>>> # Config for random mask pretraining
>>> config = PatchTSTConfig(
...     num_input_channels=7,
...     context_length=512,
...     patch_length=12,
...     stride=12,
...     mask_type='random',
...     random_mask_ratio=0.4,
...     use_cls_token=True,
... )
>>> # Config for forecast mask pretraining
>>> config = PatchTSTConfig(
...     num_input_channels=7,
...     context_length=512,
...     patch_length=12,
...     stride=12,
...     mask_type='forecast',
...     num_forecast_mask_patches=5,
...     use_cls_token=True,
... )
>>> model = PatchTSTForPretraining(config)

>>> # during training, one provides both past and future values
>>> outputs = model(past_values=batch["past_values"])

>>> loss = outputs.loss
>>> loss.backward()

PatchTSTForRegression

class transformers.PatchTSTForRegression

< >

( config: PatchTSTConfig )

引數

  • config (PatchTSTConfig) — 模型配置類,包含模型的所有引數。使用配置檔案初始化不會載入與模型相關的權重,只加載配置。請檢視 from_pretrained() 方法來載入模型權重。

用於迴歸的 PatchTST 模型。

該模型繼承自 PreTrainedModel。請檢視超類文件,瞭解庫為其所有模型實現的通用方法(如下載或儲存、調整輸入嵌入大小、修剪頭部等)。

該模型也是 PyTorch torch.nn.Module 子類。將其作為常規 PyTorch Module 使用,並參考 PyTorch 文件中與一般用法和行為相關的所有事項。

前向傳播

< >

( past_values: Tensor target_values: typing.Optional[torch.Tensor] = None past_observed_mask: typing.Optional[torch.Tensor] = None output_hidden_states: typing.Optional[bool] = None output_attentions: typing.Optional[bool] = None return_dict: typing.Optional[bool] = None ) transformers.models.patchtst.modeling_patchtst.PatchTSTForRegressionOutputtuple(torch.FloatTensor)

引數

  • past_values (形狀為 (bs, sequence_length, num_input_channels)torch.Tensor必填) — 模型的輸入序列
  • target_values (形狀為 (bs, num_input_channels)torch.Tensor) — 與 past_values 相關的目標值
  • past_observed_mask (形狀為 (batch_size, sequence_length, num_input_channels)torch.BoolTensor可選) — 布林掩碼,用於指示哪些 past_values 被觀測到,哪些是缺失的。掩碼值選擇在 [0, 1] 之間:

    • 1 表示**觀測到的**值,
    • 0 表示**缺失的**值(即被零替換的 NaN)。是否返回 ModelOutput 而不是普通元組。
  • output_hidden_states (bool可選) — 是否返回所有層的隱藏狀態。有關更多詳細資訊,請參見返回張量下的 hidden_states
  • output_attentions (bool可選) — 是否返回所有注意力層的注意力張量。有關更多詳細資訊,請參見返回張量下的 attentions
  • return_dict (bool可選) — 是否返回 ModelOutput 而不是普通元組。

返回

transformers.models.patchtst.modeling_patchtst.PatchTSTForRegressionOutputtuple(torch.FloatTensor)

一個 transformers.models.patchtst.modeling_patchtst.PatchTSTForRegressionOutput 或一個 torch.FloatTensor 元組(如果傳遞 return_dict=Falseconfig.return_dict=False),包含根據配置 (PatchTSTConfig) 和輸入的不同元素。

  • loss (*可選*,在提供 labels 時返回,形狀為 (1,)torch.FloatTensor) — 均方誤差損失。

  • regression_outputs (形狀為 (batch_size, num_targets)torch.FloatTensor) — 時間序列建模頭的迴歸輸出。

  • hidden_states (tuple[torch.FloatTensor]可選,在傳遞 output_hidden_states=Trueconfig.output_hidden_states=True 時返回) — 形狀為 (batch_size, sequence_length, hidden_size)torch.FloatTensor 元組(如果模型有嵌入層,則包括嵌入層輸出,加上每層輸出)。

    模型在每個層輸出的隱藏狀態以及可選的初始嵌入輸出。

  • attentions (tuple[torch.FloatTensor]可選,在傳遞 output_attentions=Trueconfig.output_attentions=True 時返回) — 形狀為 (batch_size, num_heads, sequence_length, sequence_length)torch.FloatTensor 元組(每層一個)。

    注意力 softmax 後的注意力權重,用於計算自注意力頭中的加權平均值。

PatchTSTForRegression 的前向方法,覆蓋了 __call__ 特殊方法。

儘管前向傳遞的定義需要在此函式中進行,但之後應呼叫 Module 例項,而不是此函式,因為前者負責執行預處理和後處理步驟,而後者會默默地忽略它們。

示例

>>> from transformers import PatchTSTConfig, PatchTSTForRegression

>>> # Regression task with 6 input channels and regress 2 targets
>>> model = PatchTSTForRegression.from_pretrained("namctin/patchtst_etth1_regression")

>>> # during inference, one only provides past values, the model outputs future values
>>> past_values = torch.randn(20, 512, 6)
>>> outputs = model(past_values=past_values)
>>> regression_outputs = outputs.regression_outputs
< > 在 GitHub 上更新

© . This site is unofficial and not affiliated with Hugging Face, Inc.