关于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


相关推荐
科研前沿12 分钟前
2026 数字孪生前沿科技:全景迭代报告 —— 镜像视界生成式孪生(Generative DT)技术白皮书
大数据·人工智能·科技·算法·音视频·空间计算
Leinwin32 分钟前
双城奔赴,智领未来:领驭科技亮相2026微软AI Tour上海·香港站
人工智能·科技·microsoft
洋子36 分钟前
Yank Note 系列 13 - 让 AI Agent 进入笔记工作流
前端·人工智能
侠客工坊1 小时前
移动端 RPA 的架构重构:基于侠客工坊多模态视觉大模型的自动化调度系统压测复盘
人工智能·智能手机·重构·架构·rpa·数字员工·侠客工坊
胖墩会武术1 小时前
Obsidian 与 Obsidian Skills 小白入门
人工智能·ai·obsidian·obsidian skills
河北小博博1 小时前
李宏毅Harness Engineering课程逐字稿整理:有时候模型不是不够聪明,只是没有好的Harness
人工智能
Elastic 中国社区官方博客1 小时前
Elastic-caveman : 在不损失 Elastic 最佳效果的情况下,将 AI 响应 tokens 减少64%
大数据·运维·数据库·人工智能·elasticsearch·搜索引擎·全文检索
云天AI实战派1 小时前
Agentic AI 全流程实战:用 OpenAI on AWS 搭一个餐饮补货智能体,从 API 调用到容器化上线
人工智能·云计算·aws
万岳科技程序员小金1 小时前
2026智慧药店系统源码趋势:药店APP+小程序开发新方向
人工智能·电子处方小程序·药店软件开发·药店系统源码·药店app开发·药店平台搭建·药店小程序
xingyuzhisuan2 小时前
稳定性考验:连续跑7天,哪家云主机不重启、不掉线?
服务器·人工智能·gpu算力