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


相关推荐
SeaExculbur14 分钟前
search_notes:一个简单的知识库 Agent Demo
人工智能·agent
无能者狂怒39 分钟前
机器视觉引导第二篇:眼在手上(Eye-in-Hand)单相机,为什么标定必须“方向取反”?
人工智能·数码相机·计算机视觉
Csvn1 小时前
一个请求等 60 秒?分层超时 + 指数退避,让 LLM 调用扛得住抖动(A01)
人工智能·aigc·agent
挖掘狂人1 小时前
为什么我们很难做出和英伟达媲美的 AI 芯片?
人工智能·芯片
AAA修煤气灶刘哥2 小时前
权重已经读进缓存了,7B 模型怎么还要等 43 秒?
人工智能·性能优化·阿里巴巴
oil欧哟2 小时前
AI Agent 的高效上下文工程:核心原理与实战拆解
人工智能
邂逅and回眸2 小时前
机器人的软件栈:ROS 2、实时中间件与数据流
人工智能·中间件·机器人
AAA修煤气灶刘哥2 小时前
AI 写的 SQL 跑通了,为什么和财务报表对不上?
人工智能·后端·算法
程序员cxuan3 小时前
这 6 个 Gemini 命令,真给我用爽了
人工智能·后端·程序员