Transformers 文档

PatchTSMixer

PatchTSMixer

概述

PatchTSMixer模型由Vijay Ekambaram、Arindam Jati、Nam Nguyen、Phanwadee Sinthong和Jayant Kalagnanam在TSMixer: Lightweight MLP-Mixer Model for Multivariate Time Series Forecasting中提出。

PatchTSMixer 是一种基于 MLP-Mixer 架构的轻量级时间序列建模方法。在这个 HuggingFace 实现中,我们提供了 PatchTSMixer 的功能,以便轻松地在补丁、通道和隐藏特征之间进行轻量级混合,从而实现有效的多元时间序列建模。它还支持从简单的门控注意力到更复杂的自注意力块的各种注意力机制,这些机制可以根据需要进行定制。该模型可以预训练,随后用于各种下游任务,如预测、分类和回归。

论文的摘要如下:

TSMixer 是一种轻量级的神经架构,完全由多层感知器(MLP)模块组成,专为多变量预测和修补时间序列的表示学习而设计。我们的模型从计算机视觉中MLP-Mixer模型的成功中汲取灵感。我们展示了将视觉MLP-Mixer适应时间序列所涉及的挑战,并引入了经过实证验证的组件以提高准确性。这包括一种新颖的设计范式,即将在线协调头附加到MLP-Mixer骨干上,以显式建模时间序列属性,如层次结构和通道相关性。我们还提出了一种混合通道建模方法,以有效处理噪声通道交互和跨不同数据集的泛化,这是现有修补通道混合方法中的一个常见挑战。此外,在骨干中引入了一种简单的门控注意力机制,以优先考虑重要特征。通过整合这些轻量级组件,我们显著增强了简单MLP结构的学习能力,以最小的计算使用量超越了复杂的Transformer模型。此外,TSMixer的模块化设计使其与监督和掩码自监督学习方法兼容,使其成为时间序列基础模型的有前途的构建块。TSMixer在预测方面以8-60%的显著优势超越了最先进的MLP和Transformer模型。它还在内存和运行时间(2-3倍)显著减少的情况下,以1-2%的优势超越了最新的Patch-Transformer模型基准。

该模型由ajativijaye12gsinthongnamctinwmgiffordkashif贡献。

使用示例

下面的代码片段展示了如何随机初始化一个PatchTSMixer模型。该模型与Trainer API兼容。


from transformers import PatchTSMixerConfig, PatchTSMixerForPrediction
from transformers import Trainer, TrainingArguments,


config = PatchTSMixerConfig(context_length = 512, prediction_length = 96)
model = PatchTSMixerForPrediction(config)
trainer = Trainer(model=model, args=training_args, 
            train_dataset=train_dataset,
            eval_dataset=valid_dataset)
trainer.train()
results = trainer.evaluate(test_dataset)

使用提示

该模型也可用于时间序列分类和时间序列回归。请参阅相应的 PatchTSMixerForTimeSeriesClassificationPatchTSMixerForRegression 类。

资源

  • 一篇深入解释PatchTSMixer的博客文章可以在这里找到。该博客也可以在Google Colab中打开。

PatchTSMixerConfig

transformers.PatchTSMixerConfig

< >

( context_length: int = 32 patch_length: int = 8 num_input_channels: int = 1 patch_stride: int = 8 num_parallel_samples: int = 100 d_model: int = 8 expansion_factor: int = 2 num_layers: int = 3 dropout: float = 0.2 mode: str = 'common_channel' gated_attn: bool = True norm_mlp: str = 'LayerNorm' self_attn: bool = False self_attn_heads: int = 1 use_positional_encoding: bool = False positional_encoding_type: str = 'sincos' scaling: typing.Union[str, bool, NoneType] = 'std' loss: str = 'mse' init_std: float = 0.02 post_init: bool = False norm_eps: float = 1e-05 mask_type: str = 'random' random_mask_ratio: float = 0.5 num_forecast_mask_patches: typing.Union[typing.List[int], int, NoneType] = [2] mask_value: int = 0 masked_loss: bool = True channel_consistent_masking: bool = True unmasked_channel_indices: typing.Optional[typing.List[int]] = None head_dropout: float = 0.2 distribution_output: str = 'student_t' prediction_length: int = 16 prediction_channel_indices: list = None num_targets: int = 3 output_range: list = None head_aggregation: str = 'max_pool' **kwargs )

参数

  • context_length (int, optional, defaults to 32) — 输入序列的上下文/历史长度。
  • patch_length (int, optional, defaults to 8) — 输入序列的补丁长度。
  • num_input_channels (int, optional, defaults to 1) — 输入变量的数量。对于单变量,设置为1。
  • patch_stride (int, 可选, 默认为 8) — 确定两个连续补丁之间的重叠。如果我们想要不重叠的补丁,将其设置为 patch_length(或更大)。
  • num_parallel_samples (int, optional, 默认为 100) — 用于概率预测的并行生成的样本数量。
  • d_model (int, 可选, 默认为 8) — 模型的隐藏维度。建议将其设置为 patch_length 的倍数(即 patch_length 的 2-5 倍)。较大的值表示模型更复杂。
  • expansion_factor (int, 可选, 默认为 2) — 在MLP内部使用的扩展因子。建议范围为2-5。较大的值表示模型更复杂。
  • num_layers (int, optional, 默认为 3) — 使用的层数。推荐范围是 3-15。较大的值表示模型更复杂。
  • dropout (float, optional, 默认为 0.2) — PatchTSMixer 骨干网络的 dropout 概率。推荐范围为 0.2-0.7
  • mode (str, 可选, 默认为 "common_channel") — 混音器模式。决定如何处理通道。允许的值:“common_channel”,“mix_channel”。在 “common_channel”模式下,我们遵循通道独立建模,没有显式的通道混合。通道 混合通过跨通道的共享权重以隐式方式发生。(首选的第一种方法)在 “mix_channel”模式下,除了补丁和特征混合器外,我们还遵循显式的通道混合。(当通道相关性对建模非常重要时首选的方法)
  • gated_attn (bool, 可选, 默认为 True) — 启用门控注意力机制.
  • norm_mlp (str, 可选, 默认为 "LayerNorm") — 归一化层(BatchNorm 或 LayerNorm)。
  • self_attn (bool, 可选, 默认为 False) — 启用跨补丁的Tiny自注意力。当Vanilla PatchTSMixer的输出与门控注意力的结果不令人满意时,可以启用此功能。启用此功能会导致显式的成对注意力和跨补丁的建模。
  • self_attn_heads (int, 可选, 默认为 1) — 自注意力头的数量。仅在 self_attn 设置为 True 时有效。
  • use_positional_encoding (bool, 可选, 默认为 False) — 启用位置嵌入用于小型自注意力层。仅在 self_attn 设置为 True 时有效。
  • positional_encoding_type (str, 可选, 默认为 "sincos") — 位置编码。支持选项 "random""sincos"。仅在 use_positional_encoding 设置为 True 时有效
  • scaling (stringbool, 可选, 默认为 "std") — 是否通过“mean”缩放器、“std”缩放器或无缩放器(如果为 None)来缩放输入目标。如果为 True,则 缩放器设置为“mean”。
  • loss (string, 可选, 默认为 "mse") — 模型的损失函数,对应于 distribution_output 头。对于参数分布,它是负对数似然(“nll”),对于点估计,它是均方误差“mse”。
  • init_std (float, optional, 默认为 0.02) — 截断正态权重初始化分布的标准差。
  • post_init (bool, 可选, 默认为 False) — 是否使用来自 transformers 库的自定义权重初始化,或者使用 PyTorch 中的默认初始化。将其设置为 False 将执行 PyTorch 的权重初始化。
  • norm_eps (float, optional, 默认为 1e-05) — 一个添加到分母中的值,用于归一化的数值稳定性。
  • mask_type (str, optional, 默认为 "random") — 用于掩码预训练模式的掩码类型。允许的值为“random”、“forecast”。在随机掩码中,点被随机掩码。在预测掩码中,点被掩码到末尾。
  • random_mask_ratio (float, 可选, 默认值为 0.5) — 当 mask_typerandom 时使用的掩码比例。值越高表示掩码越多。
  • num_forecast_mask_patches (intlist, 可选, 默认为 [2]) — 每个批次样本末尾要掩码的补丁数量。如果是一个整数,批次中的所有样本将具有相同数量的掩码补丁。如果是一个列表,批次中的样本将根据列表中定义的数字随机掩码。此参数仅用于预测预训练。
  • mask_value (float, optional, defaults to 0.0) — 使用的掩码值。
  • masked_loss (bool, optional, defaults to True) — 是否仅在掩码部分计算预训练损失,或在整个输出上计算。
  • channel_consistent_masking (bool, optional, defaults to True) — 当为真时,时间序列的所有通道的掩码将相同。否则,掩码位置将因通道而异。
  • unmasked_channel_indices (list, optional) — 在预训练期间未被屏蔽的通道。
  • head_dropout (float, 可选, 默认值为 0.2) — PatchTSMixer 头的丢弃概率。
  • distribution_output (string, 可选, 默认为 "student_t") — 当损失为“nll”时,模型的分布发射头。可以是“student_t”、“normal”或“negative_binomial”。
  • prediction_length (int, optional, 默认为 16) — 预测任务中要预测的时间步数。也称为预测范围。
  • prediction_channel_indices (list, 可选) — 要预测的通道索引列表。如果为None,则预测所有通道。目标数据应包含所有通道,我们在计算损失之前明确过滤预测和目标中的通道。
  • num_targets (int, optional, 默认为 3) — 回归任务中的目标数量(回归变量的维度)。
  • output_range (list, optional) — 用于限制回归任务的输出范围。默认为 None.
  • head_aggregation (str, 可选, 默认为 "max_pool") — 用于分类或回归任务的聚合模式。允许的值为 None, “use_last”, “max_pool”, “avg_pool”。

这是用于存储PatchTSMixerModel配置的配置类。它用于根据指定的参数实例化一个PatchTSMixer模型,定义模型架构。使用默认值实例化配置将产生与ibm/patchtsmixer-etth1-pretrain架构相似的配置。

配置对象继承自PretrainedConfig,可用于控制模型输出。阅读PretrainedConfig的文档以获取更多信息。

示例:

>>> from transformers import PatchTSMixerConfig, PatchTSMixerModel

>>> # Initializing a default PatchTSMixer configuration
>>> configuration = PatchTSMixerConfig()

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

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

PatchTSMixerModel

transformers.PatchTSMixerModel

< >

( config: PatchTSMixerConfig mask_input: bool = False )

参数

  • config (PatchTSMixerConfig) — 模型配置类,包含模型的所有参数。使用配置文件初始化不会加载与模型相关的权重,只会加载配置。查看 from_pretrained() 方法以加载模型权重。
  • mask_input (bool, 可选, 默认为 False) — 如果为True,将启用掩码。否则为False。

用于时间序列预测的PatchTSMixer模型。

该模型继承自PreTrainedModel。请查看超类文档以了解库为其所有模型实现的通用方法(如下载或保存、调整输入嵌入的大小、修剪头部等)。

该模型也是一个PyTorch torch.nn.Module 子类。 将其作为常规的PyTorch模块使用,并参考PyTorch文档以获取与一般使用和行为相关的所有信息。

前进

< >

( past_values: Tensor observed_mask: typing.Optional[torch.Tensor] = None output_hidden_states: typing.Optional[bool] = False return_dict: typing.Optional[bool] = None ) transformers.models.patchtsmixer.modeling_patchtsmixer.PatchTSMixerModelOutputtuple(torch.FloatTensor)

参数

  • past_values (torch.FloatTensor of shape (batch_size, seq_length, num_input_channels)) — Context values of the time series. For a pretraining task, this denotes the input time series to predict the masked portion. For a forecasting task, this denotes the history/past time series values. Similarly, for classification or regression tasks, it denotes the appropriate context values of the time series.

    对于单变量时间序列,num_input_channels 维度应为 1。对于多变量时间序列,它大于 1。

  • output_hidden_states (bool, optional) — 是否返回所有层的隐藏状态。
  • return_dict (bool, 可选) — 是否返回一个ModelOutput而不是一个普通的元组。
  • observed_mask (torch.FloatTensor of shape (batch_size, sequence_length, num_input_channels), optional) — 布尔掩码,用于指示哪些past_values被观察到,哪些缺失。掩码值在[0, 1]中选择:
    • 1 表示值是观察到的
    • 0 表示值是缺失的(即被零替换的NaNs)。

返回

transformers.models.patchtsmixer.modeling_patchtsmixer.PatchTSMixerModelOutputtuple(torch.FloatTensor)

一个 transformers.models.patchtsmixer.modeling_patchtsmixer.PatchTSMixerModelOutput 或一个由 torch.FloatTensor 组成的元组(如果传递了 return_dict=False 或当 config.return_dict=False 时),包含各种 元素,具体取决于配置(PatchTSMixerConfig)和输入。

  • last_hidden_state (torch.FloatTensor 形状为 (batch_size, num_channels, num_patches, d_model)) — 模型最后一层的输出的隐藏状态。
  • hidden_states (tuple(torch.FloatTensor), 可选) — 模型在每一层输出的隐藏状态。
  • patch_input (torch.FloatTensor 形状为 (batch_size, num_channels, num_patches, patch_length)) — 输入到模型的补丁数据。
  • mask: (torch.FloatTensor 形状为 (batch_size, num_channels, num_patches),可选) — 布尔张量,指示在掩码补丁中为 True,否则为 False。
  • loc: (torch.FloatTensor 形状为 (batch_size, 1, num_channels),可选) — 给出每个通道的上下文窗口的平均值。如果启用了 revin,则在模型外部用于 revin 反归一化。
  • scale: (torch.FloatTensor 形状为 (batch_size, 1, num_channels),可选) — 给出每个通道的上下文窗口的标准差。如果启用了 revin,则在模型外部用于 revin 反归一化。

PatchTSMixerModel 的 forward 方法,重写了 __call__ 特殊方法。

尽管前向传递的配方需要在此函数内定义,但之后应该调用Module实例而不是这个,因为前者负责运行预处理和后处理步骤,而后者会默默地忽略它们。

PatchTSMixerForPrediction

transformers.PatchTSMixerForPrediction

< >

( config: PatchTSMixerConfig )

参数

  • config (PatchTSMixerConfig) — 配置.

PatchTSMixer 用于预测应用。

前进

< >

( past_values: Tensor observed_mask: typing.Optional[torch.Tensor] = None future_values: typing.Optional[torch.Tensor] = None output_hidden_states: typing.Optional[bool] = False return_loss: bool = True return_dict: typing.Optional[bool] = None ) transformers.models.patchtsmixer.modeling_patchtsmixer.PatchTSMixerForPredictionOutputtuple(torch.FloatTensor)

参数

  • past_values (torch.FloatTensor of shape (batch_size, seq_length, num_input_channels)) — Context values of the time series. For a pretraining task, this denotes the input time series to predict the masked portion. For a forecasting task, this denotes the history/past time series values. Similarly, for classification or regression tasks, it denotes the appropriate context values of the time series.

    对于单变量时间序列,num_input_channels 维度应为 1。对于多变量时间序列,它大于 1。

  • output_hidden_states (bool, optional) — 是否返回所有层的隐藏状态。
  • return_dict (bool, 可选) — 是否返回一个ModelOutput而不是一个普通的元组。
  • observed_mask (torch.FloatTensor of shape (batch_size, sequence_length, num_input_channels), optional) — 布尔掩码,用于指示哪些past_values被观察到,哪些缺失。掩码值在[0, 1]中选择:
    • 1 表示值是观察到的
    • 0 表示值是缺失的(即被零替换的NaNs)。
  • future_values (torch.FloatTensor of shape (batch_size, target_len, num_input_channels) for forecasting, — (batch_size, num_targets) for regression, or (batch_size,) for classification, optional): Target values of the time series, that serve as labels for the model. The future_values is what the Transformer needs during training to learn to output, given the past_values. Note that, this is NOT required for a pretraining task.

    对于一个预测任务,形状应该是(batch_size, target_len, num_input_channels)。即使我们只想通过设置prediction_channel_indices参数中的索引来预测特定的通道,也要传递包含所有通道的目标数据,因为在损失计算之前,预测和目标的通道过滤将手动应用。

  • return_loss (bool, 可选) — 是否在forward调用中返回损失。

返回

transformers.models.patchtsmixer.modeling_patchtsmixer.PatchTSMixerForPredictionOutputtuple(torch.FloatTensor)

一个 transformers.models.patchtsmixer.modeling_patchtsmixer.PatchTSMixerForPredictionOutput 或一个由 torch.FloatTensor 组成的元组(如果传递了 return_dict=False 或当 config.return_dict=False 时),包含各种 元素,具体取决于配置(PatchTSMixerConfig)和输入。

  • prediction_outputs (torch.FloatTensor 形状为 (batch_size, prediction_length, num_input_channels)) — 预测头部的预测输出。
  • last_hidden_state (torch.FloatTensor 形状为 (batch_size, num_input_channels, num_patches, d_model)) — 在通过头部之前的骨干嵌入。
  • hidden_states (tuple(torch.FloatTensor), 可选) — 模型在每层输出处的隐藏状态加上可选的初始嵌入输出。
  • loss (可选, 当提供 y 时返回, torch.FloatTensor 形状为 ()) — 总损失。
  • loc (torch.FloatTensor, 可选 形状为 (batch_size, 1, num_input_channels)) — 输入均值
  • scale (torch.FloatTensor, 可选 形状为 (batch_size, 1, num_input_channels)) — 输入标准差

PatchTSMixerForPrediction 的前向方法,重写了 __call__ 特殊方法。

尽管前向传递的配方需要在此函数内定义,但之后应该调用Module实例而不是这个,因为前者负责运行预处理和后处理步骤,而后者会默默地忽略它们。

PatchTSMixerForTimeSeriesClassification

transformers.PatchTSMixerForTimeSeriesClassification

< >

( config: PatchTSMixerConfig )

参数

  • config (PatchTSMixerConfig) — 配置.

PatchTSMixer 用于分类应用。

前进

< >

( past_values: Tensor target_values: Tensor = None output_hidden_states: typing.Optional[bool] = False return_loss: bool = True return_dict: typing.Optional[bool] = None ) transformers.models.patchtsmixer.modeling_patchtsmixer.PatchTSMixerForTimeSeriesClassificationOutputtuple(torch.FloatTensor)

参数

  • past_values (torch.FloatTensor of shape (batch_size, seq_length, num_input_channels)) — Context values of the time series. For a pretraining task, this denotes the input time series to predict the masked portion. For a forecasting task, this denotes the history/past time series values. Similarly, for classification or regression tasks, it denotes the appropriate context values of the time series.

    对于单变量时间序列,num_input_channels 维度应为 1。对于多变量时间序列,它大于 1。

  • output_hidden_states (bool, optional) — 是否返回所有层的隐藏状态。
  • return_dict (bool, 可选) — 是否返回一个ModelOutput而不是一个普通的元组。
  • target_values (torch.FloatTensor of shape (batch_size, target_len, num_input_channels) for forecasting, — (batch_size, num_targets) for regression, or (batch_size,) for classification, optional): Target values of the time series, that serve as labels for the model. The target_values is what the Transformer needs during training to learn to output, given the past_values. Note that, this is NOT required for a pretraining task.

    对于一个预测任务,形状应该是(batch_size, target_len, num_input_channels)。即使我们只想通过设置prediction_channel_indices参数中的索引来预测特定的通道,也要传递包含所有通道的目标数据,因为在损失计算之前,预测和目标的通道过滤将手动应用。

    对于分类任务,它的形状为(batch_size,)

    对于回归任务,它的形状为(batch_size, num_targets)

  • return_loss (bool, 可选) — 是否在forward调用中返回损失。

返回

transformers.models.patchtsmixer.modeling_patchtsmixer.PatchTSMixerForTimeSeriesClassificationOutputtuple(torch.FloatTensor)

一个 transformers.models.patchtsmixer.modeling_patchtsmixer.PatchTSMixerForTimeSeriesClassificationOutput 或一个由 torch.FloatTensor 组成的元组(如果传递了 return_dict=False 或当 config.return_dict=False 时),包含各种 元素,具体取决于配置(PatchTSMixerConfig)和输入。

  • prediction_outputs (torch.FloatTensor 形状为 (batch_size, num_labels)) — 分类头的预测输出。
  • last_hidden_state (torch.FloatTensor 形状为 (batch_size, num_input_channels, num_patches, d_model)) — 通过头之前的骨干嵌入。
  • hidden_states (tuple(torch.FloatTensor), 可选) — 模型在每层输出处的隐藏状态加上可选的初始嵌入输出。
  • loss (可选, 当提供 y 时返回, torch.FloatTensor 形状为 ()) — 总损失。

PatchTSMixerForTimeSeriesClassification 的前向方法,重写了 __call__ 特殊方法。

尽管前向传递的配方需要在此函数内定义,但之后应该调用Module实例而不是这个,因为前者负责运行预处理和后处理步骤,而后者会默默地忽略它们。

PatchTSMixerForPretraining

transformers.PatchTSMixerForPretraining

< >

( config: PatchTSMixerConfig )

参数

  • config (PatchTSMixerConfig) — 配置.

PatchTSMixer 用于掩码预训练。

前进

< >

( past_values: Tensor observed_mask: typing.Optional[torch.Tensor] = None output_hidden_states: typing.Optional[bool] = False return_loss: bool = True return_dict: typing.Optional[bool] = None ) transformers.models.patchtsmixer.modeling_patchtsmixer.PatchTSMixerForPreTrainingOutputtuple(torch.FloatTensor)

参数

  • past_values (torch.FloatTensor of shape (batch_size, seq_length, num_input_channels)) — Context values of the time series. For a pretraining task, this denotes the input time series to predict the masked portion. For a forecasting task, this denotes the history/past time series values. Similarly, for classification or regression tasks, it denotes the appropriate context values of the time series.

    对于单变量时间序列,num_input_channels 维度应为 1。对于多变量时间序列,它大于 1。

  • output_hidden_states (bool, optional) — 是否返回所有层的隐藏状态。
  • return_dict (bool, 可选) — 是否返回一个 ModelOutput 而不是一个普通的元组。
  • observed_mask (torch.FloatTensor of shape (batch_size, sequence_length, num_input_channels), optional) — 布尔掩码,用于指示哪些past_values被观察到,哪些缺失。掩码值在[0, 1]中选择:
    • 1 表示值是观察到的
    • 0 表示值是缺失的(即被零替换的NaNs)。
  • return_loss (bool, 可选) — 是否在forward调用中返回损失。

返回

transformers.models.patchtsmixer.modeling_patchtsmixer.PatchTSMixerForPreTrainingOutputtuple(torch.FloatTensor)

一个 transformers.models.patchtsmixer.modeling_patchtsmixer.PatchTSMixerForPreTrainingOutput 或者一个包含多个元素的 torch.FloatTensor 元组(如果传递了 return_dict=False 或者当 config.return_dict=False 时),具体取决于配置(PatchTSMixerConfig)和输入。

  • prediction_outputs (torch.FloatTensor 形状为 (batch_size, num_input_channels, num_patches, patch_length)) — 来自预训练头的预测输出。
  • hidden_states (tuple(torch.FloatTensor), 可选) — 模型在每层输出时的隐藏状态。
  • last_hidden_state (torch.FloatTensor 形状为 (batch_size, num_input_channels, num_patches, d_model)) — 在通过头之前的骨干嵌入。
  • loss (可选, 当提供 y 时返回, torch.FloatTensor 形状为 ()) — 总损失

PatchTSMixerForPretraining 的前向方法,重写了 __call__ 特殊方法。

尽管前向传递的配方需要在此函数内定义,但之后应该调用Module实例而不是这个,因为前者负责运行预处理和后处理步骤,而后者会默默地忽略它们。

PatchTSMixerForRegression

transformers.PatchTSMixerForRegression

< >

( config: PatchTSMixerConfig )

参数

  • config (PatchTSMixerConfig) — 配置.

PatchTSMixer 用于回归应用。

前进

< >

( past_values: Tensor target_values: Tensor = None output_hidden_states: typing.Optional[bool] = False return_loss: bool = True return_dict: typing.Optional[bool] = None ) transformers.models.patchtsmixer.modeling_patchtsmixer.PatchTSMixerForRegressionOutputtuple(torch.FloatTensor)

参数

  • past_values (torch.FloatTensor of shape (batch_size, seq_length, num_input_channels)) — Context values of the time series. For a pretraining task, this denotes the input time series to predict the masked portion. For a forecasting task, this denotes the history/past time series values. Similarly, for classification or regression tasks, it denotes the appropriate context values of the time series.

    对于单变量时间序列,num_input_channels 维度应为 1。对于多变量时间序列,它大于 1。

  • output_hidden_states (bool, optional) — 是否返回所有层的隐藏状态。
  • return_dict (bool, 可选) — 是否返回一个ModelOutput而不是一个普通的元组。
  • target_values (torch.FloatTensor of shape (batch_size, target_len, num_input_channels) for forecasting, — (batch_size, num_targets) for regression, or (batch_size,) for classification, optional): Target values of the time series, that serve as labels for the model. The target_values is what the Transformer needs during training to learn to output, given the past_values. Note that, this is NOT required for a pretraining task.

    对于一个预测任务,形状应该是(batch_size, target_len, num_input_channels)。即使我们只想通过设置prediction_channel_indices参数中的索引来预测特定的通道,也要传递包含所有通道的目标数据,因为在损失计算之前,预测和目标的通道过滤将手动应用。

    对于分类任务,它的形状为(batch_size,)

    对于回归任务,它的形状为(batch_size, num_targets)

  • return_loss (bool, 可选) — 是否在forward调用中返回损失。

返回

transformers.models.patchtsmixer.modeling_patchtsmixer.PatchTSMixerForRegressionOutputtuple(torch.FloatTensor)

一个 transformers.models.patchtsmixer.modeling_patchtsmixer.PatchTSMixerForRegressionOutput 或一个由 torch.FloatTensor 组成的元组(如果传递了 return_dict=False 或当 config.return_dict=False 时),包含各种 元素,具体取决于配置(PatchTSMixerConfig)和输入。

  • regression_outputs (torch.FloatTensor 形状为 (batch_size, num_targets)) — 回归头的预测输出。
  • last_hidden_state (torch.FloatTensor 形状为 (batch_size, num_input_channels, num_patches, d_model)) — 通过头之前的骨干嵌入。
  • hidden_states (tuple(torch.FloatTensor), 可选) — 模型在每层输出处的隐藏状态加上可选的初始嵌入输出。
  • loss (可选, 当提供 y 时返回, torch.FloatTensor 形状为 ()) — 总损失。

PatchTSMixerForRegression 的前向方法,重写了 __call__ 特殊方法。

尽管前向传递的配方需要在此函数内定义,但之后应该调用Module实例而不是这个,因为前者负责运行预处理和后处理步骤,而后者会默默地忽略它们。

< > Update on GitHub