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


相关推荐
Geoffwo1 分钟前
脑控设备涉及的交叉领域
人工智能
cxr8284 分钟前
智能体工程(Agent Engineering)
人工智能·智能体·认知架构·认知工程
CAE虚拟与现实4 分钟前
AI 编程助手的语境下Fork是什么意思?
人工智能·claude·codex·豆包·deepseek
nix.gnehc7 分钟前
工具选型:5 个工具对比
人工智能·eval·评测
道影子20 分钟前
维性力网:超越时间的拓扑宇宙观
人工智能·深度学习·神经网络·拓扑学
小猴子爱上树22 分钟前
TikTok Shop视频自动翻译工具实战教程
人工智能·python·音视频·机器翻译
一键生成网站24 分钟前
互联网团队AI生成原型工具评测对比与AI一键生成工作流指南
人工智能·
人间凡尔赛33 分钟前
世界模型入门实战:从RTFM到理解物理世界 | 2026深度技术解析
javascript·人工智能·深度学习·机器学习
工业HMI实战笔记34 分钟前
【无标题】
大数据·人工智能·ui·自动化·人机交互·交互
腻害兔39 分钟前
【若依项目-产品经理视角】深度拆解 RuoYi-Vue-Pro 认证与权限:RBAC + 数据权限,这套“门禁系统“到底怎么设计的?
java·vue.js·人工智能·产品经理·ai编程