关于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 小时前
🚀 2026 年 4 月 GitHub 十大热门项目排行榜 🔥
人工智能·github
淡海水3 小时前
【AI模型】常见问题与解决方案
人工智能·深度学习·机器学习
HIT_Weston4 小时前
65、【Agent】【OpenCode】用户对话提示词(费米估算)
人工智能·agent·opencode
njsgcs4 小时前
我的知识是以图片保存的,我的任务状态可能也与图片有关,我把100张知识图片丢给vlm实时分析吗
人工智能
星爷AG I4 小时前
20-4 长时工作记忆(AGI基础理论)
人工智能·agi
#卢松松#4 小时前
用秒悟(meoo)制作了一个GEO查询小工具。
人工智能·创业创新
zandy10114 小时前
Agentic BI 架构实战:当AI Agent接管数据建模、指标计算与可视化全链路
人工智能·架构
数字供应链安全产品选型4 小时前
关键领域清单+SBOM:834号令下软件供应链的“精准治理“逻辑与技术落地路径
人工智能·安全
Flying pigs~~4 小时前
RAG智慧问答项目
数据库·人工智能·缓存·微调·知识库·rag
zuozewei5 小时前
从线下到等保二级生产平台:一次公有云新型电力系统 AI 部署复盘
人工智能