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


相关推荐
愚公搬代码11 分钟前
【愚公系列】《MCP协议与AI Agent开发》011-MCP协议标准与规范体系(交互协议与状态码体系)
人工智能·交互
小程故事多_8020 分钟前
LangGraph系列:多智能体终极方案,ReAct+MCP工业级供应链系统
人工智能·react.js·langchain
진영_22 分钟前
深度学习打卡第R4周:LSTM-火灾温度预测
人工智能·深度学习·lstm
陈希瑞28 分钟前
从 0 到 1:Vue3+Django打造现代化宠物商城系统(含AI智能顾问)
人工智能·django·宠物
std787940 分钟前
微软Visual Studio 2026正式登场,AI融入开发核心操作体验更流畅
人工智能·microsoft·visual studio
美狐美颜SDK开放平台43 分钟前
什么是美颜sdk?美型功能开发与用户体验优化实战
人工智能·算法·ux·直播美颜sdk·第三方美颜sdk·视频美颜sdk
Mxsoft6191 小时前
电力绝缘子污秽多源感知与自适应清洁策略优化
人工智能
悟空CRM服务1 小时前
开源的力量:如何用开源技术构建高效IT架构?
java·人工智能·架构·开源·开源软件
机器人行业研究员1 小时前
机器人“小脑”萎缩,何谈“大脑”智慧?六维力/关节力传感器才是“救命稻草”
人工智能·机器人·人机交互·六维力传感器·关节力传感器
互联网科技看点1 小时前
多场景服务机器人代理品牌深度解析
人工智能·机器人