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


相关推荐
weixin_446260852 分钟前
AgentsCAD:基于多智能体大模型推理与几何特征识别的FDM增材制造自动化设计
人工智能·自动化·制造
bkl_92133 分钟前
AI Agent 零基础入门:基于GPT-5.5搭建自动化工作流全实操
人工智能·gpt·自动化
Xi-Xu8 分钟前
什么时候需要 Multi-agent:不是分工,而是运行边界
人工智能·经验分享·安全
冬哥聊AI11 分钟前
蚂蚁三面追问:Agent 有哪些设计模式?别背名词了,四层框架才是正确答法
人工智能
啥都生14 分钟前
arXiv正式单飞,承诺继续免费
人工智能
水如烟19 分钟前
孤能子视角:三十六计之隔岸观火——时序相位选择
人工智能
‿hhh30 分钟前
Dify核心模块详解:从文本生成到智能体
人工智能·学习·microsoft·agent·上下文·记忆
大鱼>33 分钟前
模型可解释性:特征重要性/SHAP/LIME
人工智能·python·机器学习·lstm
霖大侠34 分钟前
Decoupled and Reusable Adaptation for Efficient Cross-Modal Transfer
人工智能·深度学习·算法·机器学习·transformer
xin(n_n)b42 分钟前
《深度学习与大模型工程化》79/358
深度学习