<?xml version="1.0" encoding="utf-8" standalone="yes"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom">
  <channel>
    <title>Transformer on Techunder</title>
    <link>https://techunder.tech/docs/transformer/</link>
    <description>Recent content in Transformer on Techunder</description>
    <generator>Hugo</generator>
    <language>zh-CN</language>
    <atom:link href="https://techunder.tech/docs/transformer/index.xml" rel="self" type="application/rss+xml" />
    <item>
      <title>自注意力机制</title>
      <link>https://techunder.tech/docs/transformer/1-self-attention/</link>
      <pubDate>Mon, 01 Jan 0001 00:00:00 +0000</pubDate>
      <guid>https://techunder.tech/docs/transformer/1-self-attention/</guid>
      <description>&lt;!-- Copyright © 2026 Techunder (Guanhua Liu) | All Rights Reserved | https://techunder.tech | Email: techunder@163.com --&gt;&#xA;&lt;div class=&#34;page-title&#34;&gt;自注意力机制&lt;/div&gt;&#xA;&lt;div class=&#34;page-info&#34;&gt;&#xA;   &lt;span class=&#34;original-tag&#34;&gt;原创&lt;/span&gt;&#xA;  发布时间：2026-04-08 | 更新时间：2026-04-08&#xA;&lt;/div&gt;&#xA;&#xA;&lt;p&gt;自注意力机制（Self-Attention Mechanism）是 Transformer 模型的核心机制。&lt;/p&gt;&#xA;&lt;p&gt;下文是按推理（生成）的过程来描述的。&lt;/p&gt;&#xA;&lt;h1 id=&#34;整体流程&#34;&gt;整体流程&lt;a class=&#34;anchor&#34; href=&#34;#%e6%95%b4%e4%bd%93%e6%b5%81%e7%a8%8b&#34;&gt;#&lt;/a&gt;&lt;/h1&gt;&#xA;&lt;ol&gt;&#xA;&lt;li&gt;输入一句话 → 切成 token（词元）&lt;/li&gt;&#xA;&lt;li&gt;每个 token 变成 embedding 向量 → 得到一组 embedding 向量列表&lt;/li&gt;&#xA;&lt;li&gt;每个 embedding 向量都分别被映射成 Q、K、V 三个向量&lt;/li&gt;&#xA;&lt;li&gt;预测下一个字时，拿最后一个字的 Q，去跟前面所有字的 K 算相关性，相关性 = 权重&lt;/li&gt;&#xA;&lt;li&gt;用权重对前面所有 token 的 V 加权融合 → 得到单头注意力 output&lt;/li&gt;&#xA;&lt;li&gt;拼接多个单头注意力的 output → 映射回 embedding 向量列表&lt;/li&gt;&#xA;&lt;li&gt;最后输出映射：$d_{model}$ → $d_{vocab}$ → softmax → token 概率&lt;/li&gt;&#xA;&lt;/ol&gt;&#xA;&lt;h1 id=&#34;token-映射&#34;&gt;Token 映射&lt;a class=&#34;anchor&#34; href=&#34;#token-%e6%98%a0%e5%b0%84&#34;&gt;#&lt;/a&gt;&lt;/h1&gt;&#xA;&lt;p&gt;假设我们有 3 个 token：「我」、「爱」、「你」。&lt;/p&gt;</description>
    </item>
  </channel>
</rss>
