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


相关推荐
AI袋鼠帝38 分钟前
4万Star开源神作曝光顶级AI们的System Prompt!太有意思了~4万Star开源神作曝光顶级AI们的System Prompt!太有意思了~
人工智能
❀͜͡傀儡师2 小时前
AI 中转站(Sub2API)搭建
人工智能·sub2api·ai 中转站
甲维斯2 小时前
Claude“山寨版”来了,支持中文,可配“任意模型”
人工智能·ai编程
测试员周周2 小时前
【AI测试智能体】为什么传统测试方法对智能体失效?
开发语言·人工智能·python·功能测试·测试工具·单元测试·测试用例
RSTJ_16252 小时前
PYTHON+AI LLM DAY THREETY-NINE
开发语言·人工智能·python
怕浪猫2 小时前
荒岛原始无工业、无电力、无设备,从零搭建最基础计算机体系
人工智能·设计模式·面试
2601_949499942 小时前
金价涨、光模块跌?不,它们之间存在更复杂的四重关联
人工智能·区块链
tanis_20772 小时前
Deepseek V4 Pro 新手极速上手指南
人工智能·语言模型
AI袋鼠帝3 小时前
阿里最强视频模型!千问App首发灰测 HappyHorse 1.0
人工智能
tanis_20773 小时前
扫描版中文 PDF 怎么提取文字:用 MinerU 做 OCR + 结构化一体处理
人工智能·pdf·ocr