摘要
本周课程介绍了自注意力机制(Self-Attention)的基本概念与应用场景。自注意力机制适用于处理可变长度的序列输入,如文本、语音和图结构数据。其核心思想是通过计算输入序列中每个元素与其他元素之间的关联性(Attention Score),动态地聚合全局信息,生成每个位置对应的输出向量。本文详细讲解了自注意力机制的计算过程,包括查询(Query)、键(Key)、值(Value)的生成、注意力分数的计算、多头注意力机制(Multi-head Self-Attention)以及位置编码(Positional Encoding)的作用。最后,将自注意力机制与卷积神经网络(CNN)和循环神经网络(RNN)进行对比,分析其优劣与适用场景。
Abstract
This week's lesson introduces the basic concepts and applications of the self-attention mechanism. Self-attention is suitable for processing variable-length sequence inputs, such as text, audio, and graph-structured data. Its core idea is to compute the relevance (Attention Score) between each element in the input sequence and all other elements, dynamically aggregating global information to generate output vectors for each position. This document explains in detail the computational process of self-attention, including the generation of Query, Key, and Value, the calculation of attention scores, the multi-head self-attention mechanism, and the role of positional encoding. Finally, self-attention is compared with convolutional neural networks (CNN) and recurrent neural networks (RNN), analyzing their strengths, weaknesses, and applicable scenarios.
一.自注意力机制的输入
学习完CNN之后,本周学习另外一个常见的网络架构自注意力机制(Self-Attention)。到目前学习,前面所学的network的输入都是输入一个向量,当遇到复杂情况要输入一组向量而且向量长度会改变时,就要用到自注意力机制。

1.文本处理
在自然语言处理等任务中,输入往往是可变长度的序列,例如一个句子。由于每个句子的长度可能不同,我们通常将每个单词转换为对应的向量表示。因此,模型的输入实际上是一组数量不定的向量,其长度随输入序列的变化而变化。

其中对于如何将一个单词转化成一个向量,最简单的方法是One-hot Encoding(独热编码),可以一个向量表示一个单词,但是单个向量的长度是所有词汇的总数量,并且向量中是没有任何语义关系的。

所以有另外一个方法就是Word Embedding(词嵌入),其会给每个单词一个向量,而这个向量具有语义信息的。

2.音频处理
除了文本处理之外,音频处理也常以向量序列作为输入。例如,可从一
1393



被折叠的 条评论
为什么被折叠?



