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


相关推荐
道可云17 分钟前
道可云AI元宇宙平台入选2025年度视听系统典型案例
人工智能
AI-小柒44 分钟前
从零入门大语言模型(LLM):系统学习路线与实践指南
大数据·开发语言·人工智能·学习·信息可视化·语言模型·自然语言处理
才聚PMP1 小时前
NPI项目如何用控制计划(CP)锁死 “量产一致性”?
人工智能
marteker1 小时前
现代租赁汽车的原厂锁车和解锁警报声替换成科基蛙的叫声
人工智能
remender9991 小时前
降本增效双赋能,IT人力外包成企业破局新路径
大数据·人工智能·物联网
Peter·Pan爱编程1 小时前
RegexBox:让正则表达式变得简单,AI 驱动的正则工具箱
人工智能·正则表达式
马士兵教育1 小时前
AI大模型通用智能体项目从原理到落地:Agent Skills 的核心逻辑与中间件 + 动态工具实践方案+架构项目实战!
人工智能·中间件·架构
C++ 老炮儿的技术栈1 小时前
KUKA机器人程序抓料
linux·运维·c语言·人工智能·机器人·库卡
wangmengxxw1 小时前
SpringAI-简介及入门案例
人工智能·springai
IT阳晨。1 小时前
【CNN卷积神经网络(吴恩达)】深度卷积网络(实例探究)学习笔记
深度学习·cnn