二维位置编码 暂记

本文探讨了Transformer模型中位置编码的重要性和不同实现方式,包括相对位置编码和二维旋转式位置编码。研究了Stand-Alone Self-Attention in Vision Models和Relative Position Representations在视觉任务中的应用,并介绍了2019年和2021年的相关进展,如Rethinking and Improving Relative Position Encoding for Vision Transformer和2LSPE: 2D Learnable Sinusoidal Positional Encoding。此外,还提到了一个PyTorch库,用于实现1D、2D和3D的正弦位置编码,并提供了代码示例来说明如何在模型中添加这些编码。

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

(相对)位置编码

Stand-Alone Self-Attention in Vision Models-NIPS 2019

在这里插入图片描述

[网络主要结构](https://blog.youkuaiyun.com/baigalxy/article/details/93662282)
[Stand-Alone Self-Attention in Vision Models](https://zhuanlan.zhihu.com/p/361259616)
[paer](https://papers.nips.cc/paper/2019/file/3416a75f4cea9109507cacd8e2f2aefc-Paper.pdf)
[现在transformer有什么工作有用二维的位置编码吗?](https://www.zhihu.com/question/476052139)
[实验分析非常精彩 | Transformer中的位置嵌入到底改如何看待?](http://www.360doc.com/content/22/0209/13/99071_1016566082.shtml)

Self-Attention with Relative Position Representations-NAACL 2018

在这里插入图片描述

[Self-Attention with Relative Position Representations](https://www.jianshu.com/p/cb5b2d967e90)

Rethinking and Improving Relative Position Encoding for Vision Transformer-2019

在这里插入图片描述
在这里插入图片描述
在这里插入图片描述
在这里插入图片描述

[paper](https://houwenpeng.com/publications/iRPE.pdf)
[论文阅读:本篇论文提出了四种二维相对位置编码的映射方式,同时分析了Vision Transformer中影响二维相对位置性能的关键因素](https://baijiahao.baidu.com/s?id=1706147979229455598&wfr=spider&for=pc)

二维位置的旋转式位置编码

[科学空间](https://spaces.ac.cn/archives/8265)
[Transformer升级之路:二维位置的旋转式位置编码](https://www.sohu.com/a/482611838_121119001)
[git](https://github.com/ZhuiyiTechnology/roformer)

2LSPE: 2D Learnable Sinusoidal Positional Encoding using Transformer for Scene Text Recognition-2021

[A PyTorch implementation of the 1d and 2d Sinusoidal positional encoding/embedding.](https://github.com/wzlxjtu/PositionalEncoding2D)

https://pypi.org/project/positional-encodings/中:

1D, 2D, and 3D Sinusoidal Postional Encoding (Pytorch and Tensorflow)

An implementation of 1D, 2D, and 3D positional encoding in Pytorch and TensorFlow


pip install positional-encodings


import torch
from positional_encodings import PositionalEncoding1D, PositionalEncoding2D, PositionalEncoding3D

# Returns the position encoding only
p_enc_1d_model = PositionalEncoding1D(10)

# Return the inputs with the position encoding added
p_enc_1d_model_sum = Summer(PositionalEncoding1D(10))

x = torch.rand(1,6,10)
penc_no_sum = p_enc_1d_model(x) # penc_no_sum.shape == (1, 6, 10)
penc_sum = p_enc_1d_model_sum(x)
print(penc_no_sum + x == penc_sum) # True

在这里插入图片描述

在这里插入图片描述

在这里插入图片描述
Efficient Two-Stage Detection of Human-Object Interactions with a Novel Unary-Pairwise Transformer

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值