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


相关推荐
全栈独立开发者30 分钟前
架构师日记:当点餐系统遇上 AI —— 基于 Spring AI + Pgvector + DeepSeek 的架构设计思路
人工智能
谷歌开发者31 分钟前
Web 开发指向标|开发者工具 AI 辅助功能的 5 大实践应用
前端·人工智能
kkai人工智能1 小时前
AI写作:从“废话”到“爆款”
开发语言·人工智能·ai·ai写作
づ安眠丶乐灬6 小时前
计算机视觉中的多视图几何 - 1
人工智能·vscode·计算机视觉
2503_928411566 小时前
项目中的一些问题(补充)
人工智能·python·tensorflow
MarkHD6 小时前
智能体在车联网中的应用 第1天 车联网完全导论:从核心定义到架构全景,构建你的知识坐标系
人工智能·架构
中科米堆6 小时前
塑料制品企业部署自动化三维扫描仪设备,解决注塑件变形问题-中科米堆CASAIM
人工智能
星图云6 小时前
从数据累积到精准解析:AI解译打造遥感数据高效利用新范式
人工智能·卫星遥感
飞哥数智坊7 小时前
AI 大厂的“护城河”,也会成为它们的束缚
人工智能·创业