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


相关推荐
世岩清上16 分钟前
AI驱动的智能运维:从自动化到自主化的技术演进与架构革新
运维·人工智能·自动化
K2_BPM18 分钟前
告别“单点智能”:AI Agent如何重构企业生产力与流程?
人工智能
TMT星球20 分钟前
深业云从人工智能产业投资基金设立,聚焦AI和具身智能相关产业
人工智能
哥布林学者29 分钟前
吴恩达深度学习课程四:计算机视觉 第二周:经典网络结构 (三)1×1卷积与Inception网络
深度学习·ai
鼾声鼾语41 分钟前
matlab的ros2发布的消息,局域网内其他设备收不到情况吗?但是matlab可以订阅其他局域网的ros2发布的消息(问题总结)
开发语言·人工智能·深度学习·算法·matlab·isaaclab
Dingdangcat861 小时前
中药材图像识别与分类 RetinaNet-R101-FPN模型详解
人工智能·数据挖掘
老蒋新思维1 小时前
创客匠人视角:智能体重构创始人 IP,知识变现从 “内容售卖” 到 “能力复制” 的革命
大数据·网络·人工智能·tcp/ip·创始人ip·创客匠人·知识变现
Honmaple1 小时前
Spring AI 2.x 发布:全面拥抱 Java 21,Redis 史诗级增强
java·人工智能·spring
古城小栈1 小时前
区块链 + AI:医疗诊断模型存证上链技术实践与探索
人工智能·区块链
丹宇码农2 小时前
Index-TTS2 从零到一:完整安装与核心使用教程
人工智能·ai·tts