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


相关推荐
小小工匠3 分钟前
LLM - 从 Prompt 到上下文工程:面向 Java 的生产级 AI Agent 设计范式
人工智能·prompt·agent·上下文工程
秋刀鱼 ..9 分钟前
2026年光学、物理学与电子信息国际学术会议(OPEI 2026)
运维·人工智能·科技·金融·机器人
xing-xing9 分钟前
Java大模型开发框架Spring AI
java·人工智能·spring
Coder_Boy_12 分钟前
【DDD领域驱动开发】基础概念和企业级项目规范入门简介
java·开发语言·人工智能·驱动开发
乾元15 分钟前
Syslog / Flow / Telemetry 的 AI 聚合与异常检测实战(可观测性)
运维·网络·人工智能·网络协议·华为·自动化·ansible
大千AI助手17 分钟前
编辑相似度(Edit Similarity):原理、演进与多模态扩展
人工智能·机器学习·大模型·编辑距离·相似度·大千ai助手·编辑相似度
数智顾问19 分钟前
(102页PPT)数字化转型,从战略到执行(附下载方式)
大数据·人工智能·物联网
XiaoMu_00121 分钟前
多场景头盔佩戴检测
人工智能·python·深度学习
民乐团扒谱机22 分钟前
【微实验】谱聚类之大规模数据应用——Nyström 方法
人工智能·算法·机器学习·matlab·数据挖掘·聚类·谱聚类
leafff12325 分钟前
一文了解:智能体大模型LangChain 和 Dify有什么区别?
人工智能·架构·langchain