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


相关推荐
Sherlock Ma3 小时前
西瓜书《机器学习》全网最详细解读 第一章:绪论
人工智能·深度学习·考研·机器学习·学习方法·西瓜书·改行学it
烟锁池塘柳03 小时前
【机器学习】一文彻底搞懂正则化(Regularization)
人工智能·深度学习·机器学习
一个天蝎座 白勺 程序猿3 小时前
从AlphaGo到ChatGPT:机器学习基础概念的全景式拆解与工程实践思考
人工智能·机器学习·chatgpt
Luhui Dev4 小时前
Anthropic 2026 最新 Agent Harness 架构完整拆解:Managed Agents
人工智能·架构·agent·luhuidev
skywalk81634 小时前
安装superpowers-zh (AI 编程超能力 · 中文增强版)
人工智能
经济元宇宙4 小时前
摄影培训行业百科:机构选择与学习路径全解析
大数据·人工智能·学习
哥只是传说中的小白5 小时前
GrsaiApi官方正版字字动画插件!支持nano banana pro和gpt-image-2模型
人工智能·gpt·ai作画·开源·aigc·api
GJGCY5 小时前
企业AI Agent落地架构深度解析:LLM+RAG+RPA+工具调用全流程
大数据·人工智能·ai·数字化·智能体
刀法如飞5 小时前
Ontology本体论是什么数据结构?Palantir 技术原理介绍
数据结构·人工智能·ai编程·图论
大神科技AI定制5 小时前
企业级OpenClaw落地指南:如何通过私有化部署构建安全AI Agent工作流?
人工智能·安全