Transformer - Outputs(Shifted Right)

本文讨论了Transformer模型中的Outputs处理,特别是ShiftedRight操作,即在输出序列中添加起始符(sos)以调整位置,以便于批次处理。介绍了特殊token如startofsequence和padding的作用。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

Transformer - Outputs(Shifted Right)

flyfish

在这里插入图片描述

在这里插入图片描述
输入: “je suis etudiant”
预期输出 : “i am a student”
除了普通词汇之外,模型还引入了一些特殊token,常有的(start of sequence)、(end of sequence)以及(padding)等。
用于标记输出序列的开始,
用于表示序列的结束,
则用于填充较短序列至相同长度以便于批处理。

对Outputs有Shifted Right操作。Shifted Right 实质上是给输出添加特殊token。

正常的输出序列位置关系如下:

0-"je"
1-"suis"
2-"etudiant"

但在执行的过程中,我们在初始输出中添加了起始符,相当于将输出整体右移一位(Shifted Right),所以输出序列变成如下情况:

0-<sos>
1-"je"
2-"suis"
3-"etudiant"

在这里插入图片描述
The Illustrated Transformer

### Video Swin Transformer Architecture and Implementation The **Swin Transformer**, initially designed for image processing tasks, has been extended to video understanding through hierarchical vision transformers that utilize shifted windows. In the context of videos, this model captures spatiotemporal information effectively while maintaining computational efficiency. #### Spatial-Temporal Modeling with Shifted Windows In video applications, the core idea remains similar but extends into three dimensions—height, width, and time—to form cubes instead of patches used in images. The shifting mechanism alternates between different window positions across frames during each layer transformation process[^1]. This design allows local modeling within non-overlapping windows at one stage followed by cross-window connections via shifted windows in subsequent stages, ensuring both locality sensitivity and global receptive fields are captured efficiently without excessive computation cost. #### Hierarchical Feature Extraction Process For handling long-range dependencies over space-time volumes: - Initially divides input sequences into small cubic regions. - Applies self-attention mechanisms inside these localized areas independently. - Gradually merges outputs from previous layers' smaller units into larger ones as depth increases. Such hierarchy facilitates multi-scale representation learning critical for complex motion patterns recognition found commonly within moving pictures or clips. ```python import torch.nn as nn from timm.models.layers import DropPath, trunc_normal_ class WindowAttention(nn.Module): """Window based multi-head self attention (W-MSA) module with relative position bias.""" def __init__(self, dim, window_size, num_heads, qkv_bias=True, attn_drop=0., proj_drop=0.): super().__init__() ... def swin_transformer_v2(img_size=(224, 224), patch_size=(4, 4), in_chans=3, embed_dim=96, depths=[2, 2, 6, 2], num_heads=[3, 6, 12, 24], window_size=7, mlp_ratio=4., ... ): """ Constructs a Swin Transformer V2 model specifically tailored towards video data. Adjustments include adapting parameters like img_size to accommodate frame dimensions along temporal axis when necessary. """ ``` #### Parallelization Benefits Over Traditional Methods Compared against traditional methods such as LSTMs which rely heavily on sequential computations limiting their scalability potential especially under high-dimensional inputs; architectures built upon Transformers offer significant advantages due to inherent parallelizability properties allowing faster training times alongside better performance metrics achieved overall[^2].
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

二分掌柜的

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值