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


相关推荐
盖雅工场4 分钟前
业务波动适配型排班,破解零售服务业人力失衡难题
大数据·人工智能
人工智能AI技术9 分钟前
【Agent从入门到实践】45 与后端系统集成:Agent作为服务,嵌入业务流程
人工智能·python
想你依然心痛9 分钟前
PaddlePaddle-v3.3:国产深度学习框架的全新突破
人工智能·深度学习·paddlepaddle
waeng_luo14 分钟前
如何利用AI提高鸿蒙开发效率:从Rules到智能开发实践
人工智能·华为·harmonyos
Aurora@Hui15 分钟前
GSAP (GreenSock Animation Platform)
人工智能·python
ViiTor_AI18 分钟前
2026 年 AI 配音工具深度对比:视频旁白与有声书为什么越来越依赖语音克隆?
人工智能·音视频·语音识别
Rabbit_QL20 分钟前
【LLM原理学习】N-gram 语言模型实战教学指南(从原理到代码)
人工智能·学习·语言模型
会算数的⑨25 分钟前
Spring AI Alibaba学习(一)—— RAG
java·人工智能·后端·学习·spring·saa
sensen_kiss26 分钟前
INT301 生物计算(神经网络)Coursework 解析(知识点梳理)
人工智能·笔记·深度学习·神经网络
万岳软件开发小城31 分钟前
2026医疗数字化趋势:互联网医院系统源码与智慧医院APP全面爆发
大数据·人工智能·互联网医院系统源码·互联网医院app开发·互联网医院小程序·医院软件开发