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


相关推荐
猿饵块1 小时前
视觉slam--框架
人工智能
yvestine2 小时前
自然语言处理——Transformer
人工智能·深度学习·自然语言处理·transformer
SuperW2 小时前
OPENCV图形计算面积、弧长API讲解(1)
人工智能·opencv·计算机视觉
山海不说话3 小时前
视频行为标注工具BehaviLabel(源码+使用介绍+Windows.Exe版本)
人工智能·python·计算机视觉·视觉检测
虹科数字化与AR4 小时前
安宝特方案丨船舶智造的“AR+AI+作业标准化管理解决方案”(装配)
人工智能·ar·ar眼镜·船舶智造·数字工作流·智能装配
飞哥数智坊5 小时前
Coze实战第13讲:飞书多维表格读取+豆包生图模型,轻松批量生成短剧封面
人工智能
newxtc6 小时前
【配置 YOLOX 用于按目录分类的图片数据集】
人工智能·目标跟踪·分类
kooboo china.6 小时前
Tailwind CSS 实战:基于 Kooboo 构建 AI 对话框页面(八):异步处理逻辑详解
前端·css·人工智能·编辑器·html·交互