关于Transformer的理解

关于Transformer, QKV的意义表示其更像是一个可学习的查询系统,或许以前搜索引擎的算法就与此有关或者某个分支的搜索算法与此类似。


Can anyone help me to understand this image? - #2 by J_Johnson - nlp - PyTorch Forums

Embeddings - these are learnable weights where each token(token could be a word, sentence piece, subword, character, etc) are converted into a vector, say, with 500 values between 0 and 1 that are trainable.

Positional Encoding - for each token, we want to inform the model where it's located, orderwise. This is because linear layers are not ideal for handling sequential information. So we manually pass this in by adding a vector of sine and cosine values on the first 2 elements in the embedding vector.

This sequence of vectors goes through an attention layer, which basically is like a learnable digitized database search function with keys, queries and values. In this case, we are "searching" for the most likely next token.

The Feed Forward is just a basic linear layer, but is applied across each embedding in the sequence separately(i.e. 3 dim tensor instead of 2 dim).

Then the final Linear layer is where we want to get out our predicted next token in the form of a vector of probabilities, which we apply a softmax to put the values in the range of 0 to 1.

There are two sides because when that diagram was developed, it was being used in language translations. But generative language models for next token prediction just use the Transformer decoder and not the encoder.

Here is a PyTorch tutorial that might help you go through how it works.

Language Modeling with nn.Transformer and torchtext --- PyTorch Tutorials 2.0.1+cu117 documentation


相关推荐
沫儿笙2 小时前
YASKAWA机器人焊机气体省气
人工智能·机器人
视界先声2 小时前
教育机器人定制:外观与功能深度指南
人工智能·机器人
Acrelhuang2 小时前
筑牢用电防线:Acrel-1000 自动化系统赋能 35kV 园区高效供电-安科瑞黄安南
java·大数据·开发语言·人工智能·物联网
Elastic 中国社区官方博客2 小时前
使用 Mastra 和 Elasticsearch 构建具有语义回忆功能的知识 agent
大数据·数据库·人工智能·elasticsearch·搜索引擎·ai·全文检索
用户5191495848452 小时前
使用CSS和GSAP创建3D滚动驱动文本动画
人工智能·aigc
网络精创大傻2 小时前
构建 Multilingo:一个集成 Telex 的 AI 翻译代理
人工智能·搜索引擎
AI科技星2 小时前
宇宙的几何诗篇:当空间本身成为运动的主角
数据结构·人工智能·经验分享·算法·计算机视觉
胡桃不是夹子3 小时前
torch和torchvision对应版本匹配官网下载
人工智能·python·深度学习
集和诚JHCTECH3 小时前
专为严苛环境而生:高防护等级工业防水平板WPPC-H1520T(P)
人工智能·嵌入式硬件·平板
mit6.8243 小时前
[手机AI开发sdk] 模型冻结&解冻.pb | `aidlite`加速AI模型
人工智能·智能手机