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


相关推荐
程序员cxuan11 分钟前
上海团队开源了首个国产记忆模型,554B!这也太狠了
人工智能·后端·程序员
普密斯科技18 分钟前
倾斜安装长工作距离:14X变倍镜头用于激光开封芯片腔体观测案例
人工智能·数码相机·计算机视觉
VIP_CQCRE43 分钟前
GPT Image 2.6 动态表情交付别只发预览:GIF 文件校验、哈希清单与下载排错
图像处理·人工智能·python·gif
Sailing1 小时前
🤔🤔Dify 不必推倒重来,把重逻辑下沉到 LangGraph
人工智能·langchain·agent
oak隔壁找我2 小时前
AI从大语言模型发展至今的核心术语演进表
人工智能
电科_银尘2 小时前
【大模型算法与工程 37】语言模型强化学习基础:策略、奖励与优势
人工智能·算法·语言模型
衡石科技2 小时前
看板发出去之后:评论、订阅与受控发布的工程链路
大数据·运维·人工智能·数据可视化
挖掘狂人2 小时前
AI 会写代码之后,程序员该学什么?
人工智能·程序员·ai编程
艺杯羹2 小时前
11月23日AI前沿复盘:安全双警报、模型降价潮与工程防线
人工智能·网络安全·系统架构·大模型·ai agent