Universal Transformer 论文解读

论文出处:Universal Transformers

摘要

RNN一直是sequence modeling task 的主要选择。然而,固有的序列计算让它训练很慢,FCNN 和CNN架构在一些例如机器翻译在内的序列建模任务中取得了更好的结果,因为同时计算所有输入,所以并行性强,训练时间更快。然而,一些FCNN架构,例如vanilla transformer在一些简单的任务上不能处理RNN能够轻松应对的东西,例如 copy string,或者是当string长度超过训练数据集时的简单推断任务。我们提出了universal transformer :parallel-in-time self-attentive recurrent sequence model

  • UT将诸如Transformer之类的前馈序列模型的可并行性和全局接受域与RNN的递归归纳相结合
  • 添加了一个动态的按位暂停机制
  • 在一些特定的假设下,被认为是图灵完备的

1.介绍

Transformer好处:

  • 卷积和例如transformer的fully-attentional feed-forward architectures在一系列sequence moding task(尤其是机器翻译)上用来代替RNN,可以并行,并且处理了RNN的长序列梯度消失问题。
  • 每个位置的representation都可以知道其他位置的representation,这就拥有了一个global receptive field,而CNN只有一个有限的感受野

Transformer缺陷:

  • 具有固定的不同层的Transformer 抛弃了RNN在处理迭代和递归转换上的归纳偏置。我们的实验表明这种归纳偏置在一些算法或者是不同复杂度的语言理解任务上至关重要:相比于神经网图灵机,stack RNN,Transformer对于在训练时没有出现过的句子长度泛化性能并不好。

UT 好处:(真爱吹牛逼)

  • 在一些特定的假设下,可以被认为是图灵完备的。
  • 结合了Transformer的并行性和全局感受野以及RNN的时序归纳偏置
  • 组成:
    • 在每一个时序步骤,使用一个自注意力机制并行的精简所有位置的 representation,然后紧接一个depth-wise separable convolution或者position-wise fully-connected layer
    • 舔加了一个dynamic per-position halting mechanism,让模型为每个位置动态的选择精简步骤次数,
  • 吹牛逼的结果:
    several algorithmic tasks and the bAbI language understanding task,比transformer lstm 好,在LAMBADA text understanding dataset,具有按位暂停的UT实现了了SOTA

2.模型介绍

2.1 UT

依然是使用了Encoder-Decoder架构,都使用了RNN架构,但并不是在位置上进行时序操作,而是在每个位置representation上的修订的版本上进行时序操作。
在每一个时序步骤,首先进行自注意力机制来更新每个位置的向量表示。然后,应用一个转移函数(在时序和位置上都共享)独立的作用于每一个位置
因为时序转移函数可以使用任意次数,这就代表UT会有可变的深度

2.1.1 Encoder

下面,介绍一下如何计算 Ht
下面省略了 dropout
在这里插入图片描述

  • multi head scaled dot-product attention (不多介绍了)
  • transition function:separable convolution 或者是 position -wise FCNN
  • two-dimensional (position, time) coordinate embeddings
    在这里插入图片描述

2.1.2 decoder

没啥可以说的 ,跟原来一样,保留自回归特性。

2.2 DYNAMIC HALTING

在一些序列处理模型中,有一些位置(单词)比其他的更ambiguous,因此应该分配更多的处理资源。
Adaptive Computation Time (ACT) 是一个动态调整RNN中每个位置的symbol的计算步数的机制,以模型在每一步所产生的scalar halting probability为基础
我们在每一个位置增加dynamic ACT halting mechanism.一旦per-symbol 时序块停止了,当前的状态就会直接被copy到下一个时间步,直到所有的块都停止,或者是到达一个最大数量步数。

3.实验和分析

原文中提到了很多,我们这里只列举第一个。

3.1 BABI QUESTION-ANSWERING

目标是在给定许多可能编码多个支持事实的英语句子的情况下回答问题。 目的是通过要求对每个故事中呈现的语言事实进行某种类型的推理来衡量各种形式的语言理解。
不赘述了 看不懂

4. 讨论

当设定为一个固定的步数后,UT相当于一个共享参数的Transformer。然而,因为per-symbol时序转移函数可以被应用任意次数,我们更合理的称之为并行RNN,保留了Transformer计算效率,以及RNN归纳偏置,另外,使用动态暂停机制,可以根据输入数据调整计算步骤数量。
给定足够的内存,可以被用来模仿图灵机,因此克服了Transformer的缺陷

5.结论

在一些语言理解和算法任务上表现良好。
主要由两个关键:

  • 共享参数
  • 为了构建一个图灵完备的机器,相比于固定深度的UT,我们引进ACT,拥有停止或者继续计算的能力。
### Universal Transformer in Deep Learning Architecture Universal Transformers (UTs) represent an advanced variant of the traditional Transformer model, designed to enhance performance on a variety of tasks by dynamically adjusting computation based on input complexity[^1]. Unlike standard Transformers that apply fixed layers across all inputs, UTs introduce iterative refinement through repeated application of the same layer with different parameters at each step. #### Key Features of Universal Transformers - **Dynamic Computation**: Instead of having multiple distinct layers as seen in conventional architectures like BERT or vanilla Transformers, UTs reuse a single set of weights iteratively over several steps. - **Adaptive Computation Time**: The number of iterations can vary depending upon how complex the task is, allowing more processing power where needed without wasting resources elsewhere. - **Halting Mechanism**: A halting mechanism determines when sufficient information has been processed for accurate predictions. This feature contributes significantly towards efficiency gains while maintaining high accuracy levels. #### Implementation Details Implementing a Universal Transformer involves modifying typical self-attention mechanisms within transformer blocks so they operate recursively rather than sequentially: ```python import torch.nn as nn class UniversalTransformerBlock(nn.Module): def __init__(self, d_model=512, nhead=8, dim_feedforward=2048, dropout=0.1): super().__init__() # Define sub-layers including multi-head attention and feed-forward network self.self_attn = nn.MultiheadAttention(d_model, nhead, dropout=dropout) self.feed_forward = nn.Sequential( nn.Linear(d_model, dim_feedforward), nn.ReLU(), nn.Dropout(dropout), nn.Linear(dim_feedforward, d_model)) # Add normalization after residual connections self.norm1 = nn.LayerNorm(d_model) self.norm2 = nn.LayerNorm(d_model) def forward(self, src, mask=None): # Apply recursive operations here instead of stacking static layers pass # Placeholder for actual implementation logic ``` The above code snippet outlines part of what would be required to implement such functionality but leaves out specifics related to recursion control structures necessary for achieving true universality according to UT principles outlined earlier.
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值