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


相关推荐
deephub29 分钟前
构建自己的AI编程助手:基于RAG的上下文感知实现方案
人工智能·机器学习·ai编程·rag·ai编程助手
AI营销干货站32 分钟前
工业B2B获客难?原圈科技解析2026五大AI营销增长引擎
人工智能
程序员老刘·34 分钟前
重拾Eval能力:D4rt为Flutter注入AI进化基因
人工智能·flutter·跨平台开发·客户端开发
kebijuelun35 分钟前
FlashInfer-Bench:把 AI 生成的 GPU Kernel 放进真实 LLM 系统的“闭环引擎”
人工智能·gpt·深度学习·机器学习·语言模型
Deepoch41 分钟前
Deepoc具身模型开发板:让炒菜机器人成为您的智能厨师
人工智能·机器人·开发板·具身模型·deepoc·炒菜机器人·厨房机器人
Elastic 中国社区官方博客1 小时前
Elastic:DevRel 通讯 — 2026 年 1 月
大数据·数据库·人工智能·elasticsearch·搜索引擎·ai·全文检索
寻星探路1 小时前
【算法专题】滑动窗口:从“无重复字符”到“字母异位词”的深度剖析
java·开发语言·c++·人工智能·python·算法·ai
盈创力和20071 小时前
智慧城市中智能井盖的未来演进:从边缘感知节点到城市智能体
人工智能·智慧城市·智慧市政·智慧水务·智能井盖传感器·综合管廊
njsgcs1 小时前
ppo 找出口模型 训练笔记
人工智能·笔记
萤丰信息1 小时前
从 “钢筋水泥” 到 “数字神经元”:北京 AI 原点社区重构城市进化新逻辑
java·大数据·人工智能·安全·重构·智慧城市·智慧园区