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


相关推荐
Engineer邓祥浩14 小时前
宏观认知(3):AI战略与社会影响——吴恩达《AI for Everyone》Week3学习笔记
人工智能·笔记·学习
weixin_4684668514 小时前
图像连通域分析新手实战指南
图像处理·人工智能·深度学习·ai·机器视觉·连通域
狒狒热知识15 小时前
中小企业品牌破局之道178软文网以轻量化传播助力软文营销从零到一
人工智能
J2虾虾15 小时前
Spring AI Alibaba - Models 模型
人工智能·spring·microsoft
万俟淋曦15 小时前
【论文速递】2026年第01周(Dec-28-Jan-03)(Robotics/Embodied AI/LLM)
人工智能·ai·机器人·大模型·论文·robotics·具身智能
不务正业的小主治15 小时前
ezygene-多种算法计算免疫评分
人工智能·r语言·简析基因·ezygene·免疫分析
程序大视界15 小时前
AI多模态大模型技术全景(2026):从“拼接“到“原生统一“,一文读懂底层架构与主流方案
人工智能·架构·多模态
qcx2315 小时前
【系统学AI】15 RAG评测体系:RAGAS四维+TruLens+ARES全套方案
人工智能·rag·评测
AI专业测评15 小时前
【无标题】
人工智能·aigc·ai写作·测评·网文
完成大叔15 小时前
模块二,Agent推理模式价值呈现
人工智能