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


相关推荐
Jmayday10 分钟前
Pytorch:张量创建及运算
人工智能·pytorch·python
领麦微红外12 分钟前
W-TRS-5.5D1传感器:充电桩的“温度卫士”,解锁安全高效充电新范式
人工智能·安全
SomeB1oody16 分钟前
【Python深度学习】3.4. 循环神经网络(RNN)实战:预测股价
开发语言·人工智能·python·rnn·深度学习·机器学习
ACCELERATOR_LLC23 分钟前
【DataWhale组队学习】DIY-LLM Task2 PyTorch 与资源核算
人工智能·pytorch·深度学习·大模型
Elastic 中国社区官方博客1 小时前
Elastic Security、Observability 和 Search 现在在你的 AI 工具中提供交互式 UI
大数据·运维·人工智能·elasticsearch·搜索引擎·安全威胁分析·可用性测试
一碗白开水一1 小时前
【目标跟踪综述】目标跟踪近3年技术研究,全面了解目标跟踪发展
人工智能·计算机视觉·目标跟踪
Promise微笑1 小时前
AI搜索时代的流量重构:GEO优化深度执行细节与把控体系
人工智能·重构
言萧凡_CookieBoty2 小时前
比 Vibe Coding 更可怕的,是 Vibe Design 吧
人工智能·ai编程
Rick19932 小时前
Spring AI 如何进行权限控制
人工智能·python·spring
Theodore_10222 小时前
深度学习(15):倾斜数据集 & 精确率-召回率权衡
人工智能·笔记·深度学习·机器学习·知识图谱