Transformer 里的注意力机制到底是怎么算的?
注意力可以理解为一次「按相关程度加权求和」。对序列里的每个词,模型都会算出三个向量:查询 Q、键 K 和值 V。一个词要关注谁,就拿自己的 Q 去和所有词的 K 做点积,点积越大,说明两者越相关。
得到这些分数之后,模型先把它们除以 √dk,再送进 softmax,变成一组加起来等于 1 的权重。除以 √dk 是为了防止点积随维度增大而变得过大,让 softmax 落进梯度几乎为零的区域。最后用这组权重对所有词的 V 加权求和,就得到了这个词新的表示。
多头注意力则是把这个过程并行做好几遍,每个「头」用不同的投影去捕捉不同类型的关系,比如有的头盯语法结构,有的头盯指代关系,最后再把各个头的结果拼起来。
How is attention in a Transformer actually computed?
Think of attention as a weighted average by relevance. For every token the model computes three vectors: a query Q, a key K and a value V. To decide what a token should attend to, it takes the dot product of its Q with every token's K; a larger product means a stronger match.
The scores are then divided by √dk and passed through a softmax, which turns them into weights that sum to 1. Dividing by √dk keeps the dot products from growing with the dimension and pushing the softmax into a region where its gradients all but vanish. Finally the weights are used to average every token's V, giving that token its new representation.
Multi-head attention runs this several times in parallel. Each head uses its own projections to pick up a different kind of relation, one tracking syntax, another tracking references, and the heads' outputs are concatenated at the end.
在 AI 回答的页边,问清楚那一段。 Ask about one passage, in the margin.
在 AI 回答里选中看不懂的一句话,右键「旁注追问」,一个只针对这段话的小对话就在原地展开。主对话不被打断,也不用上下翻找。
Highlight the sentence you don’t get in an AI answer, right-click “Ask in a side note”, and a small conversation about just that passage opens in place. The main chat stays untouched, and you never scroll away.
激活码绑定你的邮箱,换电脑时用同一邮箱登录即可恢复。
The code binds to your email; sign in with it again on a new computer.
在这些网站上可用:DeepSeek · Kimi · 豆包 · 腾讯元宝 · ChatGPT · ClaudeWorks on DeepSeek · Kimi · Doubao · Yuanbao · ChatGPT · Claude
三步用上Three steps
插件在商店里免费安装,在本站购买激活码后解锁。
Install the extension for free from the store, then unlock it with a code bought here.
-
免费安装插件Install for free
从 Chrome 应用商店或 Edge 扩展商店安装。没有激活之前,插件只显示激活入口。
Get it from the Chrome Web Store or Edge Add-ons. Until it is activated, the extension only shows the activation screen.
两个商店都即将上架Both listings are coming soon -
在本站购买激活码Buy a code here
$5,支持支付宝和微信支付。付款成功后激活码只显示一次,同时自动下载为 txt 文件。
$5, paid with Alipay or WeChat Pay. After payment the code is shown once and downloaded as a .txt file.
-
登录并激活Sign in and activate
点浏览器工具栏上的 Glossa 图标,用邮箱收验证码登录(也可以用 Google 登录),再输入激活码。激活码随即失效,之后换电脑、重装插件,用同一个邮箱登录即可恢复。
Click the Glossa icon in the toolbar, sign in with a code sent to your email (or with Google), then enter the code. The code is then used up; on a new computer or after reinstalling, sign in with the same email.
价格与须知Price & terms
付款之前,这五条请先看一遍。
Please read these five notes before you pay.
- 价格Price
- $5,一次性付款,不订阅,没有免费试用。
- $5, paid once. No subscription and no free trial.
- 需要You need
- 电脑上的 Chrome 或 Edge 浏览器,以及一个能收邮件的邮箱(QQ、163、Gmail 等都可以),激活和换设备时都要用到。不支持手机。
- Chrome or Edge on a computer, and an email address you can receive mail at, used for activation and when you move devices. Phones are not supported.
- 激活码The code
- 付款后只显示一次,并自动下载为 txt 文件,请立刻保存。一个激活码只能激活一次,绑定一个账号。
- Shown once after payment and downloaded as a .txt file, so save it right away. Each code activates once and binds to one account.
- 回答从哪来Who answers
- 旁注用你在当前网站已登录的账号提问,不需要 API Key。DeepSeek、Kimi、豆包、元宝的历史记录里会多出一条以「[Glossa 旁注]」开头的对话;ChatGPT、Claude 使用临时或无痕对话,不留记录。
- Side questions are asked on the site you are on, with the account you are already signed in to. No API key. On DeepSeek, Kimi, Doubao and Yuanbao an extra chat starting with “[Glossa 旁注]” appears in your history; ChatGPT and Claude use temporary or incognito chats that leave no history.
- 退款Refunds
- 没有激活过的激活码,付款后 7 天内可以申请全额退款。详见退款政策。
- A code that has never been activated can be refunded in full within 7 days of payment. See the refund policy.
常见问题Questions
可以直接在这个网页上用吗?Can I use it on this page?
不能。上面那段是演示,回答是预先写好的。Glossa 是浏览器插件,装好并激活后,在你平时用的 AI 网站上划词即可使用。
No. The chat above is a demonstration with a prepared answer. Glossa is a browser extension; once installed and activated, you use it on the AI sites you already use.
激活码丢了怎么办?I lost my code. What now?
如果还没激活,请把订单号和付款记录截图发到 chenghaodong257@gmail.com,核实后为你补发。如果已经激活,就不再需要激活码了:在新设备上用同一个邮箱登录即可。
If it was never activated, email your order number and a screenshot of the payment to chenghaodong257@gmail.com and we will reissue it after checking. If it was activated, you no longer need it: sign in with the same email on the new device.
它会读取我的聊天内容吗?Does it read my chats?
只在你主动发起旁注时,读取你选中的段落和它所在的那条回答,交给你当前所在的网站作答。聊天内容不会发到 Glossa 的服务器;我们只记录订单和激活所需的信息,见隐私政策。
Only when you start a side note, and only the passage you selected and the answer it belongs to, which go to the site you are on. Chat content is never sent to Glossa’s servers; we keep only what orders and activation need. See the privacy policy.
网站改版后插件失效了怎么办?What if a site redesign breaks it?
这些网站改版频繁,我们会尽快更新适配,已激活的用户会自动收到更新。遇到问题请发邮件告诉我们。
These sites change often. We update the extension as quickly as we can, and activated users receive the fix automatically. Email us if something stops working.
可以在几台电脑上用?How many computers can I use?
激活码绑定的是你登录的邮箱,不是电脑。在 Chrome 或 Edge 里用同一个邮箱登录即可使用。
The code binds to the email you sign in with, not a computer. Sign in with that email in Chrome or Edge to use it.
提供技术咨询吗?Do you offer technical consulting?
提供。软件使用、AI 工具应用和程序开发方面的一对一线上答疑,按次收费。请发邮件到 chenghaodong257@gmail.com 说明你的需求。
Yes. One-to-one online help with software, AI tools and programming, charged per session. Email chenghaodong257@gmail.com with what you need.