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


相关推荐
冬奇Lab10 分钟前
Code Agent 解剖(03):各家 LLM 格式不一样,agent 怎么统一对接?
人工智能·开源
lifallen12 分钟前
模型不是函数:claude-cookbooks/misc 十四篇的公共底层
人工智能·学习·ai·ai编程
冬奇Lab15 分钟前
开源项目第189期:DeepTutor — Agent 原生的终身个性化学习工作台,三层记忆+多引擎RAG+Partners
人工智能·开源·资讯
小柯南敲键盘25 分钟前
电商图片翻译工具推荐,批量处理主图视频字幕,免费试用
大数据·人工智能·python·音视频
一次旅行38 分钟前
2026.08.16 AI产业深度解读|国产大模型全面突围,算力硬件/智能安全/人形机器人四大趋势附落地方案
人工智能·安全·机器人
观远数据1 小时前
零售连锁BI选型清单:什么样的场景适合ChatBI,什么样的场景不适合
大数据·人工智能·零售
IT_陈寒1 小时前
Vue的双向绑定把我坑惨了,原来这个场景不能用
前端·人工智能·后端
阿甘编程点滴1 小时前
多角色对话AI配音工具技术解析与功能实测汇总
人工智能
IT爱学堂1 小时前
尚硅谷 - 2025年3月Java+AI大模型应用开发
java·开发语言·人工智能
水镜AI1 小时前
LangGraph 结构化输出:为什么 with_structured_output 一遇到 list 就翻车?
人工智能