Enhancing the Locality and Breaking the MemoryBottleneck of Transformer on Time Series Forecasting

Enhancing the Locality and Breaking the MemoryBottleneck of Transformer on Time Series Forecasting读后感

目录

摘要

1.引言

2.相关工作

3.背景

3.1问题提出

3.2 Transformer模型

4.方法

4.1 提高transformer模型的局部性

4.2 打破transformer模型的内存瓶颈

 5.实验

5.1合成数据集

5.2真实数据集

6.总结

摘要

提出普通transformer模型存在的两个问题

1.局部不可知

2.内存瓶颈

创新点:此基础上,提出了内存容量仅为O(L(logl)2)的对数稀疏变换,在内存预算受限的情况下,提高了对粒度细、长期依赖性强的时间序列的预测精度

1.引言

对两个问题的研究重点

1.探究长序列的相关性

2.在编码层加入卷积

3.提出Log Transformer 模型,打破内存瓶颈

2.相关工作

3.背景

3.1问题提出

假设N个相关的单变量\mathbf{z}_{i, 1: t_{0}} \triangleq\left[\mathbf{z}_{i, 1}, \mathbf{z}_{i, 2}, \cdots, \mathbf{z}_{i, t_{0}}\right],进行多步\tau预测。另外,有\left\{\mathbf{X}_{i, 1: t_{0}+\tau}\right\}_{i=1}^{N}为一组相关联的基于时间变量的协变量向量,维度为d,建立条件分布模型:

p\left(\mathbf{z}_{i, t_{0}+1: t_{0}+\tau} \mid \mathbf{z}_{i, 1: t_{0}}, \mathbf{x}_{i, 1: t_{0}+\tau} ; \mathbf{\Phi}\right)=\prod_{t=t_{0}+1}^{t_{0}+\tau} p\left(\mathbf{z}_{i, t} \mid \mathbf{z}_{i, 1: t-1}, \mathbf{x}_{i, 1: t} ; \mathbf{\Phi}\right)

将其简化为单步预测模型:p\left(\mathbf{Z}_{t} \mid \mathbf{Z}_{1: t-1}, \mathbf{x}_{1: t} ; \mathbf{\Phi}\right)^{2}\phi为时间序列中学习的参数。

将观察值和协变量串联起来,得出增广矩阵:\mathbf{y}_{t} \triangleq\left[\mathbf{z}_{t-1} \circ \mathbf{x}_{t}\right] \in \mathbb{R}^{d+1}, \quad \mathbf{Y}_{t}=\left[\mathbf{y}_{1}, \cdots, \mathbf{y}_{t}\right]^{T} \in \mathbb{R}^{t \times(d+1)}

探索合适模型进行预测。

3.2 Transformer模型

文章利用多头自注意机制用Transformer 3实例化f,因为自注意使Transformer能够捕捉长期和短期的依赖关系,不同的注意头学习关注时间模式的不同方面。

将简单介绍多头自注意力机制架构:在self-attention layer,一个多头自关注子层同时将Y转换成H个不同查询矩阵Qh、键矩阵Kh、值矩阵Vh其中H=1;···;H.这里是\mathbf{W}_{h}^{Q}, \mathbf{W}_{h}^{K} \in \mathbb{R}^{(d+1) \times d_{k}} \text { and } \mathbf{W}_{h}^{V} \in \mathbb{R}^{(d+1) \times d_{v}}是可学习参数。在这些线性投影之后,缩放的点积注意力计算出一系列向量输出:

 注意,为了避免将来的信息泄漏,通过将所有上三角元素设置为-\infty,应用掩码矩阵M来滤除向右的关注。之后,O1;O2;···;OH是串联和线性投影的。在注意输出的基础上,叠加一个位置前馈子层,该子层由两层全连通网络和中间的ReLU激活组成。

4.方法

4.1 提高transformer模型的局部性

由于节假日和极端天气等各种事件的影响,时间序列中的模式会随着时间的变化而变化,因此,一个观察点是异常点、变化点还是模式的一部分,在很大程度上取决于其周围的环境。然而,在规范Transformer的自关注层中,queries和keys之间的相似性是基于它们的逐点值计算的,而没有充分利用局部上下文(如shape),如图1(a)和(b)所示。局部上下文的Query-key匹配不可知可能会混淆自注意模块的观测值是异常、变化点还是模式的一部分,并带来潜在的优化问题。

本文提出卷积自注意层来解决这个问题,图1(c)和(d)说明了提出的卷积式自我注意的架构视图。

本文使用kernel大小k的因果卷积(causal convolution)(步幅为1)将输入(使用适当的paddings)转换为queries和keys。请注意,因果关系会确保当前位置永远无法获得未来的信息。通过使用因果卷积,生成的queries和keys可以更好地感知局部上下文,从而通过局部上下文信息(如局部形状)来计算它们的相似性,而不是点状值,这有助于准确预测。注意,当k=1时,卷积自注意退化为规范自注意,因而可以看作是一个泛化过程。

4.2 打破transformer模型的内存瓶颈

为了验证方法,文章首先在TRAVINS-F数据集上用一个规范的transformer模型对学习到的注意力模式进行定性评估。traffic-f数据集包含旧金山湾区963条车道的占用率,每20分钟记录一次。我们训练了一个10层的典型变压器在TRAFF-F数据集上充分注意,并将学习到的注意模式可视化。图2中显示了一个示例。第2层清楚地显示了全局模式,然而,第6层和第10层只显示了依赖于模式的稀疏性,这表明可以在不显著影响性能的情况下引入某种形式的稀疏性。更重要的事,对于序列长度为L的序列,计算每对单元之间的注意力分数将导致O(L2)内存占用,使得对具有细粒度和强长期依赖性的长时间序列进行建模变得困难。

提出对数LogSparse Transformer,它只需要为每层中的每个单元计算O(log L)点积。此外,我们只需要堆叠多达O(log L)层,模型将能够访问每个单元的信息。因此,内存使用的总成本仅为O(L(logl)2)。将II_{l}^{k}定义为在第k~(k+1)层的计算过程中,单元l可以关注的单元索引集。在transformer的标准自注意中,I_{l}^{k}=\{j: j \leq l\},允许每个单元关注它过去的所有单元和它自己,如图3(a)所示。然而,这种算法的空间复杂度随输入长度呈二次增长。为了缓解这一问题,我们建议选择指数的子集I_{l}^{k} \subset\{j: j \leq l\},这样I_{l}^{k}就不会随着L增长得太快。\left|I_{l}^{k}\right| \propto \log L是选择指标的有效方法。

 

详细推导公式不说明,本文提出了对数稀疏自注意,允许每个单元只关注它的前一个具有指数步长的单元和它自己。

 具体公式如下:

I_{l}^{k}=\left\{l-2^{\left\lfloor\log _{2} l\right\rfloor}, l-2^{\left\lfloor\log _{2} l\right\rfloor-1}, l-\right. \left.2^{\left\lfloor\log _{2} l\right\rfloor-2}, \ldots, l-2^{0}, l\right\}

定理一:对于\forall l \text { and } j \leq l,如果我们堆叠\left\lfloor\log _{2} l\right\rfloor+11层,至少有一条从单元j到单元l的路径。此外,对于j<l,从单元j到单元l的可行唯一路径的数目以O\left(\left\lfloor\log _{2}(l-j)\right\rfloor !\right)的速率增加

定理1意味着,尽管每一层的内存使用量呈指数下降(从O(L2)到O(Llog2)),但只要我们稍微“深入”一点--将层数取为Blog2LC+1,信息仍然可以从任何单元流到任何其他单元。注意,这意味着总的内存使用量为O(L(log2L)2),并解决了Transformer在GPU内存约束下臭名昭著的可伸缩性瓶颈[1]。此外,随着两个单元之间的距离越来越远,路径的数量在log2(l-j)中以超指数的速度增加,这表明有丰富的信息流用于建模微妙的长期依赖关系。

局部注意力(Local Attention):可以允许每个单元密集地关注其大小为O(log2 L)的左窗口中的单元,以便更多的局部信息,例如趋势,可以用于当前步长预测。在相邻单元格之外,我们可以恢复LogSparse关注策略,如图3(c)所示

重启注意力(Restart Attention):可以将长度为L的整个输入分成多个子序列,并将每个子序列的长度设置为L_{s u b} \propto L,对每个子序列采用对数稀疏注意策略。一个例子如图3(d)所示

采用局部关注和重启关注不会改变稀疏关注策略的复杂性,但会创建更多的路径,减少路径中所需的边数。注意,可以将局部注意和重新开始注意结合在一起。

 5.实验

5.1合成数据集

为了证明Transformer捕捉长期依赖关系的能力,我们对合成数据进行了实验。具体来说,我们产生一个分段的正弦信号

f(x)=\left\{\begin{array}{ll} A_{1} \sin (\pi x / 6)+72+N_{x} & x \in[0,12) \\ A_{2} \sin (\pi x / 6)+72+N_{x} & x \in[12,24) \\ A_{3} \sin (\pi x / 6)+72+N_{x} & x \in\left[24, t_{0}\right) \\ A_{4} \sin (\pi x / 12)+72+N_{x} & x \in\left[t_{0}, t_{0}+24\right) \end{array}\right.

特点: 24 步预测,3-layer 具有自注意力机制的 canonical Transformer 与3层LSTM对比,使用ρ-分位数损失

5.2真实数据集

1.数据集介绍

2.长期和短期预测

用RNN回归模型对比,短期预测是7天滚动预测,(用前7天的数据预测后面一天)。直接一次性预测七天数据。cnn 自注意层对长短期预测都有效。

3.稀疏注意

6.总结

Good day! The cost of university tuition fees has been a topic of concern among students and parents alike. Some argue that the fees are too high, limiting access to higher education, while others believe that the cost is justified by the quality of education and facilities provided. In this article, we will examine the different perspectives surrounding university tuition fees and explore the impact they have on students. Firstly, it is important to acknowledge that higher education is a valuable investment. Research has shown that individuals with a university degree earn significantly more over their lifetime compared to those without. This is because university education equips students with new skills, knowledge and networks, enhancing their employability and career prospects. However, the rising cost of tuition fees is making it increasingly difficult for students from lower-income families to pursue a degree. This is because tuition fees may not only be a financial burden but can also discourage students psychologically and create extra stress. Furthermore, many students are forced to accumulate significant debt in order to pay for their education. This debt can leave them struggling financially for years after graduation, burdening them with the responsibility to pay back the borrowed amount. In some cases, students are forced to delay important milestones, such as buying a house or starting a family, due to this financial burden. In addition to the financial impact, the high cost of tuition fees can also have a psychological impact on students. It can create a sense of pressure to succeed academically in order to justify the cost of their education, potentially leading to burnout, stress and anxiety. It can also lead to a sense of resentment towards the university and the feeling that students are being taken advantage of. In conclusion, university tuition fees are a complicated issue with both positive and negative effects. While it is important to acknowledge the value of higher education, we must also address the rising cost of tuition fees and the impact it has on students. Whether it is by increasing government funding for education, providing more scholarships, or reducing operational costs, solutions must be found to ensure that access to higher education is available to all, regardless of their financial background. I hope this article was informative and useful to you. Good luck with your studies!
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值