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


相关推荐
甲维斯4 分钟前
Claude和Kimi消耗60亿,价值2.6万,收入0蛋!
人工智能
妍妍爱学习15 分钟前
自动编码器与变分自动编码器:同一脉络下的进化
深度学习·无监督学习·概率模型·自动编码器·变分自动编码器
子兮曰17 分钟前
AI 浏览器 Agent 的安全困局:当自动化工具可以偷走你的登录态
前端·人工智能·后端
FBI HackerHarry浩27 分钟前
AI大模型开发V2第四阶段线性回归
人工智能·算法·线性回归
71777729 分钟前
国产 DevOps 新路径:解析 Gitee 软件工厂本土化、信创、AI 核心优势
人工智能·gitee·devops
小白说大模型1 小时前
人工智能:深度学习中的卷积神经网络(CNN)实战应用
人工智能·深度学习·cnn
众人皆醒我独醉1 小时前
Triton Inference Server:NVIDIA 的推理"瑞士军刀"——LLM 只是它的一种负载
人工智能·面试·ai编程
Vince的修炼之路1 小时前
大模型推理框架SGLang的源码分析
人工智能·架构
码途潇潇2 小时前
Codex Rules 与 Skills:项目级和全局级配置一览
人工智能
饼干哥哥2 小时前
字节Seedance2.5终于上线,这次在收割谁?
人工智能·设计模式·前端框架