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


相关推荐
子兮曰20 分钟前
CLI正在吞掉GUI:不是替代,是统治,AI时代的入口争夺战
人工智能·github·命令行
星星也在雾里37 分钟前
Dify Agent + FastAPI + PostgreSQL实现数据库查询
数据库·人工智能·fastapi
Maschera9639 分钟前
openclaw-lark 的 Bot@Bot 跨Bot提及功能 - 开发经验分享
人工智能·node.js
TDengine (老段)1 小时前
以事件为核心 + 以资产为核心:工业数据中缺失的关键一环
大数据·数据库·人工智能·时序数据库·tdengine·涛思数据
阿里云大数据AI技术1 小时前
欣和大数据阿里云上升级,打造湖仓一体平台
大数据·人工智能
CC数分1 小时前
大模型时代的数据分析:AI会取代数据分析师吗?
人工智能·数据挖掘·数据分析
忙什么果1 小时前
transformer学习笔记2
笔记·学习·transformer
PHOSKEY1 小时前
直面消费电子检测新挑战——光子精密3D工业相机折叠屏铰链检测应用方案
人工智能
guslegend1 小时前
RAG系统的需求分析
人工智能·大模型
飞哥数智坊1 小时前
AI编程教程多到爆炸,而我依然选择再做一套,而且完全免费
人工智能