<?xml version="1.0" encoding="utf-8" standalone="yes"?><rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom"><channel><title>Deep-Learning on Blog</title><link>https://blog.sivn.net.cn/tags/deep-learning/</link><description>Recent content in Deep-Learning on Blog</description><generator>Hugo -- gohugo.io</generator><language>zh-cn</language><lastBuildDate>Wed, 06 May 2026 17:08:40 +0800</lastBuildDate><atom:link href="https://blog.sivn.net.cn/tags/deep-learning/index.xml" rel="self" type="application/rss+xml"/><item><title>Neural Network 中的 Weight 与 Activation</title><link>https://blog.sivn.net.cn/post/nn-weight-and-activation/</link><pubDate>Wed, 06 May 2026 17:08:40 +0800</pubDate><guid>https://blog.sivn.net.cn/post/nn-weight-and-activation/</guid><description>&lt;h2 id="weight权重"&gt;Weight（权重）
&lt;/h2&gt;&lt;p&gt;权重是神经网络中可学习的参数，决定了输入如何被变换。&lt;/p&gt;
&lt;p&gt;以 Attention 机制为例，&lt;code&gt;weight&lt;/code&gt; 是 Q/K/V 投影矩阵：&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;&lt;strong&gt;Q&lt;/strong&gt; (Query): 查询向量&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;K&lt;/strong&gt; (Key): 键向量&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;V&lt;/strong&gt; (Value): 值向量&lt;/li&gt;
&lt;/ul&gt;
&lt;h3 id="attention-计算流程"&gt;Attention 计算流程
&lt;/h3&gt;&lt;ol&gt;
&lt;li&gt;
&lt;p&gt;输入 &lt;code&gt;X&lt;/code&gt; 经过三套不同的线性层，得到 Q/K/V：&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;&lt;code&gt;Q = X @ Wq&lt;/code&gt;&lt;/li&gt;
&lt;li&gt;&lt;code&gt;K = X @ Wk&lt;/code&gt;&lt;/li&gt;
&lt;li&gt;&lt;code&gt;V = X @ Wv&lt;/code&gt;&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;用 &lt;code&gt;Q&lt;/code&gt; 和 &lt;code&gt;K&lt;/code&gt; 计算注意力分数：&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;&lt;code&gt;Attention = softmax(Q @ K^T / sqrt(d))&lt;/code&gt;&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;用注意力分数对 &lt;code&gt;V&lt;/code&gt; 加权求和，得到输出：&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;&lt;code&gt;Output = Attention @ V&lt;/code&gt;&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;/ol&gt;
&lt;h2 id="activation激活值"&gt;Activation（激活值）
&lt;/h2&gt;&lt;p&gt;Activation 是神经网络的中间特征/输出值，即输入经过某一层（layer）之后临时算出来的结果。&lt;/p&gt;
&lt;p&gt;例如：&lt;/p&gt;
&lt;pre tabindex="0"&gt;&lt;code&gt;h = relu(X @ W + b) # h 就是这一层的 activation
&lt;/code&gt;&lt;/pre&gt;&lt;p&gt;注意区分：&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;&lt;strong&gt;Weight&lt;/strong&gt;：模型学到的参数，训练后固定&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Activation&lt;/strong&gt;：每次前向传播时动态计算的中间结果，随输入变化&lt;/li&gt;
&lt;/ul&gt;</description></item></channel></rss>