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


相关推荐
WPF工业上位机6 小时前
YXGK.FakeVM深度学习之5语义分割
人工智能·深度学习
落叶无情6 小时前
ICEF认知操作系统:四类约束全维度全覆盖,是全谱系系统化约束体系
人工智能
碳基硅坊6 小时前
Gemma 4 12B 让AI创作更私密更高效
人工智能·gemma-4-12b
weixin_468466856 小时前
大模型新手入门与实战指南
人工智能·深度学习·ai·大模型
装不满的克莱因瓶6 小时前
掌握 RNN 与 LSTM 模型结构
人工智能·python·rnn·深度学习·神经网络·ai·lstm
jeffer_liu6 小时前
Spring AI 生产级实战:裁判员
java·人工智能·后端·spring·大模型
weixin_446260857 小时前
Agent 会自行回避吗?测量 LLM 智能体合规性的带内访问拒绝信号
人工智能
努力学习_小白7 小时前
ResNeXt-50——学习记录
pytorch·深度学习·学习
Kobebryant-Manba7 小时前
记录动手学深度学习基础知识
人工智能·深度学习