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


相关推荐
HXDGCL6 分钟前
大会观察 | 破除创新链堵点:论“工厂直供”模式如何加速自动化核心部件迭代
大数据·人工智能·自动化·自动化生产线·环形导轨
梵得儿SHI9 分钟前
(第八篇)Spring AI 核心技术攻坚:模型评估与调优 - 提升 AI 响应质量的双轮驱动实践
人工智能
果粒蹬i9 分钟前
生成式 AI 质量控制:幻觉抑制与 RLHF 对齐技术详解
前端·人工智能·easyui
数据与后端架构提升之路10 分钟前
实战:手搓一个“BEV 级”自动驾驶训练加速平台 —— 当 RTX 4090 遇上多模态数据
人工智能·机器学习·自动驾驶
互联网科技看点12 分钟前
国产 CAD主机厂快速响应应用方案
人工智能
五度易链-区域产业数字化管理平台16 分钟前
五度易链企业数据服务架构思考:从“存数据”到“用数据”的全周期解决方案
大数据·人工智能·架构
HyperAI超神经16 分钟前
【vLLM 学习】Rlhf Utils
人工智能·深度学习·学习·机器学习·ai编程·vllm
OpenCSG23 分钟前
提示词工程到AgenticOps:OpenCSG公益课
大数据·人工智能·开源·opencsg
悟纤26 分钟前
Suno AI 音乐节奏设计完全指南 | Suno高级篇 | 第23篇
人工智能·suno·suno ai·suno api·ai music
EasyGBS40 分钟前
EasyGBS的金融网点全场景智能可视化监管方案设计
大数据·人工智能