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


相关推荐
石小石Orz几秒前
星云SDK + 油猴:给LLM塑造肉身,陪伴你在每个网页
前端·人工智能
VIP_CQCRE5 分钟前
用 Ace Data Cloud 快速接入 AI 视频生成:HappyHorse Videos API 实战指南
人工智能·python·api·ai视频生成·acedatacloud
m0_547486667 分钟前
《DeepSeek生成式人工智能教与学》全套PPT课件
人工智能·deepseek
Geeys8 分钟前
拼多多新店快速起流量完整实操
大数据·网络·人工智能
俊哥V14 分钟前
每日 AI 研究简报 · 2026-07-12
人工智能·ai
giszz18 分钟前
【提示词6要素之06约束】给AI画边界,它才不越界
人工智能
南方程序猴20 分钟前
国内怎么接入 GPT、Claude 和 AI 生图?我把常用工具统一到了一个 API 入口
人工智能·gpt
weigangwin22 分钟前
Graphiti 时间知识图谱:从 pip 安装到事实有效期验证
人工智能·知识图谱·pip
AI创界者25 分钟前
【最新】FaceFusion 5.0 一键整合包发布!免环境配置,解压即用(附超详细小白保姆级教程)
人工智能·aigc
SLD_Allen36 分钟前
K8s+Ray:大模型时代AI Workload调度的通用范式
人工智能·容器·kubernetes