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


相关推荐
2501_945318497 分钟前
CAIE证书是否可查、可验证?
人工智能
weixin_416660078 分钟前
技术分析:豆包生成带公式文案导出Word乱码的底层机理
人工智能·word·豆包
爱吃泡芙的小白白12 分钟前
深入浅出:卷积神经网络(CNN)池化层全解析——从MaxPool到前沿发展
人工智能·神经网络·cnn·池化层·最大值池化·平均值池化
jigsaw_zyx18 分钟前
提示词工程
人工智能·算法
jdyzzy22 分钟前
什么是 JIT 精益生产模式?它与传统的生产管控方式有何不同?
java·大数据·人工智能·jit
LittroInno24 分钟前
TVMS视频管理平台 —— 多种目标跟踪模式
人工智能·计算机视觉·目标跟踪
查无此人byebye29 分钟前
突破性图像分词技术TiTok:32个Token实现高效图像重建与生成
人工智能
Niuguangshuo30 分钟前
DALL-E 2:从CLIP潜变量到高质量图像生成的突破
人工智能·深度学习·transformer
偷吃的耗子30 分钟前
【CNN算法理解】:基于训练好的MNIST CNN模型进行预测
人工智能·算法·cnn
Elastic 中国社区官方博客30 分钟前
跳过 MLOps:通过 Cloud Connect 使用 EIS 为自管理 Elasticsearch 提供托管云推理
大数据·数据库·人工智能·elasticsearch·搜索引擎·ai·全文检索