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


相关推荐
程序员泠零澪回家种桔子16 分钟前
RAG中的Embedding技术
人工智能·后端·ai·embedding
雨大王51217 分钟前
工业AI与汽车制造业升级:从“中国制造”到“中国智造”
人工智能
Dyanic18 分钟前
DSFuse:一种用于特征保真度的红外与可见光图像融合的双扩散结构
人工智能·机器学习·计算机视觉
无风听海25 分钟前
CBOW 模型中输入矩阵、输出矩阵与词表向量矩阵深入解析
人工智能·机器学习·矩阵
lxs-29 分钟前
使用 OpenCV 进行图像识别:人脸与物体检测
人工智能·opencv·计算机视觉
薛定e的猫咪34 分钟前
【ICRA 2025】面向杂技机器人的分阶段奖励塑形:一种约束多目标强化学习方法
人工智能·深度学习·机器学习·机器人
高洁0137 分钟前
产品数字孪生体与数字样机及数字化交付的应用
人工智能·深度学习·算法·数据挖掘·transformer
chatexcel39 分钟前
ChatExcel 多模态解析能力上线:AI 自动生成结构化表格实践
人工智能
CHrisFC1 小时前
江苏硕晟LIMS pro3.0:引领实验室信息管理新高度
大数据·人工智能
LOnghas12111 小时前
YOLO11-SPPF-LSKA实现橡胶密封圈表面缺陷检测,提升检测精度与效率
人工智能·计算机视觉·目标跟踪