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


相关推荐
WangYaolove13147 分钟前
基于深度学习的中文情感分析系统(源码+文档)
python·深度学习·django·毕业设计·源码
技术狂人16811 分钟前
工业大模型工程化部署实战!4 卡 L40S 高可用集群(动态资源调度 + 监控告警 + 国产化适配)
人工智能·算法·面试·职场和发展·vllm
软件算法开发11 分钟前
基于改进麻雀优化的LSTM深度学习网络模型(ASFSSA-LSTM)的一维时间序列预测算法matlab仿真
深度学习·matlab·lstm·一维时间序列预测·改进麻雀优化·asfssa-lstm
好奇龙猫28 分钟前
【人工智能学习-AI入试相关题目练习-第三次】
人工智能
柳杉1 小时前
建议收藏 | 2026年AI工具封神榜:从Sora到混元3D,生产力彻底爆发
前端·人工智能·后端
狮子座明仔1 小时前
Engram:DeepSeek提出条件记忆模块,“查算分离“架构开启LLM稀疏性新维度
人工智能·深度学习·语言模型·自然语言处理·架构·记忆
阿湯哥1 小时前
AgentScope Java 集成 Spring AI Alibaba Workflow 完整指南
java·人工智能·spring
Java中文社群2 小时前
保姆级喂饭教程:什么是Skills?如何用Skills?
人工智能
2301_800256112 小时前
【人工智能引论期末复习】 第6章 深度学习4 - RNN
人工智能·rnn·深度学习