从数学和工程角度理解人工智能的本质

神经网络里面的核心概念与底层原理

- Sigmoid:把数字压到0到1之间,像个概率值。
- ReLU:负数变0,正数不变,简单粗暴但很有效。
- Tanh:把数字压到-1到1之间,像个平衡器。
神经网络经典算法:CNN与RNN
CV领域的CNN(Convolutional Neural Networks)

NLP领域的RNN(Recurrent Neural Networks)

标准RNN
为解决梯度消失推出LSTM
- 遗忘门:决定丢弃哪些过时的信息。
- 输入门:决定添加哪些新的信息到记忆中。
- 输出门:决定当前时间步输出哪些信息。
GRU:LSTM的简化版
- 更新门:控制保留多少旧信息并加入多少新信息。
- 重置门:决定忘掉哪些旧信息并如何与新信息结合。
从自注意机制到Transfermor架构的构建分析
自注意力机制 Self-Attention Mechanism
- 输入表示:假设有一个输入序列(比如一个句子),每个词被表示为一个向量(通常通过词嵌入生成)。
- 计算相似度:对于序列中的每个元素,模型计算它与序列中所有其他元素的“相似度”。这种相似度通常通过向量之间的点积(dot product)计算,点积越大,表示两个元素越相关。
- 生成注意力权重:将相似度通过softmax函数转换为权重,这些权重之和为1,表示每个元素对当前元素的“关注”程度。
- 加权求和:使用这些权重对序列中所有元素的表示进行加权求和,得到一个新的表示,这个表示融合了序列中其他元素的信息。
自注意力机会再算法工程上是如何实现的?
- Query(查询):相当于你在讨论会中提出的问题,你希望得到什么信息。例如:“我现在需要知道A信息。”
- Key(键):相当于每个人的“名片”或者“标签”,它描述了他们所擅长或掌握的信息类别。比如,有人名片上写着“擅长A”,有人写着“擅长B”。
- Value(值):相当于每个人真正提供的内容。当你的问题(Query)与某个人的标签(Key)匹配得很好时,他就会把自己掌握的内容(Value)提供给你。
- 用这个词的 Query 去和所有其他词的 Key 进行比较(计算相似度),找到最相关的信息。
- 按照这些相似度给相关词的 Value 赋予不同的权重(weight)。
- 把这些加权后的 Value 聚合起来,生成对当前词的新的理解。这样,模型就能“关注”到与当前词最相关的信息,从而捕捉到整个句子的语义关系。
多头自注意力
- 将输入分成多个子空间,分别计算注意力。
- 每个“头”关注不同的特征或模式。
- 最后将所有头的输出拼接起来,增强模型捕捉序列丰富信息的能力。
Transformer架构

- 多头自注意力机制(Multi-Head Self-Attention):捕捉输入序列内部的依赖关系。
- 前馈神经网络(Feed-Forward Neural Network, FFN):对每个位置的表示进行独立的非线性变换。MLP 是一个更宽泛的概念,指的是由多层全连接网络构成的模型,Transformer中的FFN特指2层的MLP。Attention整合了Token的上下文信息,FFN则是在这个基础上,更提取更生层次的特征,这些特征能够让模型更加精准的理解和表达语言的含义。
- 附加组件:
- 残差连接(Residual Connections):每个子层后,将输入与输出相加,帮助信息流动。
- 层归一化(Layer Normalization):在残差连接后归一化表示,稳定训练过程。
- 掩码多头自注意力机制(Masked Multi-Head Self-Attention):与编码器的自注意力类似,但使用掩码(masking)确保只关注当前生成位置之前的位置,保持自回归特性。
- 编码器-解码器注意力机制(Encoder-Decoder Attention):使解码器关注编码器的输出,将输入序列信息融入生成过程。
- 前馈神经网络(Feed-Forward Neural Network):与编码器中的FFN相同。
- 附加组件:同样包含残差连接和层归一化。

最后

Attention Is All You Need
The dominant sequence transduction models are based on complex recurrent or convolutional neural networks in an encoder-decoder configuration. The best performing models also connect the encoder...

What Are Transformer Models and How Do They Work?
Transformer models are one of the most exciting new developments in machine learning. They were introduced in the paper Attention is All You Need. Transformers can be used to write stories, essays, poems, answer questions, translate between languages, chat with humans, and they can even pass exams that are hard for humans! But what are they? You’ll be happy to know that the architecture of transformer models is not that complex, it simply is a concatenation of some very useful components, each o
AI Research Blog - The Transformer Blueprint: A Holistic Guide to the Transformer Neural Network Architecture
AI Research Blog - The Transformer Blueprint: A Holistic Guide to the Transformer Neural Network Architecture
A deep dive into Transformer, a neural network architecture that was introduced in the famous paper “attention is all you need” in 2017, its applications, impacts, challenges and future directions
一起AI技术主页主页

Attention in transformers, step-by-step | DL6
Demystifying attention, the key mechanism inside transformers and LLMs. Instead of sponsored ad reads, these lessons are funded directly by viewers: https://3b1b.co/support Special thanks to these supporters: https://www.3blue1brown.com/lessons/attention#thanks An equally valuable form of support is to simply share the videos. Demystifying self-attention, multiple heads, and cross-attention. Instead of sponsored ad reads, these lessons are funded directly by viewers: https://3b1b.co/support The first pass for the translated subtitles here is machine-generated, and therefore notably imperfect. To contribute edits or fixes, visit https://www.criblate.com Звуковая дорожка на русском языке: Влад Бурмистров. And yes, at 22:00 (and elsewhere), "breaks" is a typo. ------------------ Here are a few other relevant resources Build a GPT from scratch, by Andrej Karpathy https://youtu.be/kCc8FmEb1nY If you want a conceptual understanding of language models from the ground up, @vcubingx just started a short series of videos on the topic: https://youtu.be/1il-s4mgNdI?si=XaVxj6bsdy3VkgEX If you're interested in the herculean task of interpreting what these large networks might actually be doing, the Transformer Circuits posts by Anthropic are great. In particular, it was only after reading one of these that I started thinking of the combination of the value and output matrices as being a combined low-rank map from the embedding space to itself, which, at least in my mind, made things much clearer than other sources. https://transformer-circuits.pub/2021/framework/index.html Site with exercises related to ML programming and GPTs https://www.gptandchill.ai/codingproblems History of language models by Brit Cruise, @ArtOfTheProblem https://youtu.be/OFS90-FX6pg An early paper on how directions in embedding spaces have meaning: https://arxiv.org/pdf/1301.3781.pdf ------------------ Timestamps: 0:00 - Recap on embeddings 1:39 - Motivating examples 4:29 - The attention pattern 11:08 - Masking 12:42 - Context size 13:10 - Values 15:44 - Counting parameters 18:21 - Cross-attention 19:19 - Multiple heads 22:16 - The output matrix 23:19 - Going deeper 24:54 - Ending ------------------ These animations are largely made using a custom Python library, manim. See the FAQ comments here: https://3b1b.co/faq#manim https://github.com/3b1b/manim https://github.com/ManimCommunity/manim/ All code for specific videos is visible here: https://github.com/3b1b/videos/ The music is by Vincent Rubinetti. https://www.vincentrubinetti.com https://vincerubinetti.bandcamp.com/album/the-music-of-3blue1brown https://open.spotify.com/album/1dVyjwS8FBqXhRunaG5W5u ------------------ 3blue1brown is a channel about animating math, in all senses of the word animate. If you're reading the bottom of a video description, I'm guessing you're more interested than the average viewer in lessons here. It would mean a lot to me if you chose to stay up to date on new ones, either by subscribing here on YouTube or otherwise following on whichever platform below you check most regularly. Mailing list: https://3blue1brown.substack.com Twitter: https://twitter.com/3blue1brown Instagram: https://www.instagram.com/3blue1brown Reddit: https://www.reddit.com/r/3blue1brown Facebook: https://www.facebook.com/3blue1brown Patreon: https://patreon.com/3blue1brown Website: https://www.3blue1brown.com

How might LLMs store facts | DL7
Unpacking the multilayer perceptrons in a transformer, and how they may store facts Instead of sponsored ad reads, these lessons are funded directly by viewers: https://3b1b.co/support An equally valuable form of support is to share the videos. AI Alignment forum post from the Deepmind researchers referenced at the video's start: https://www.alignmentforum.org/posts/iGuwZTHWb6DFY3sKB/fact-finding-attempting-to-reverse-engineer-factual-recall Anthropic posts about superposition referenced near the end: https://transformer-circuits.pub/2022/toy_model/index.html https://transformer-circuits.pub/2023/monosemantic-features Some added resources for those interested in learning more about mechanistic interpretability, offered by Neel Nanda Mechanistic interpretability paper reading list https://www.alignmentforum.org/posts/NfFST5Mio7BCAQHPA/an-extremely-opinionated-annotated-list-of-my-favourite Getting started in mechanistic interpretability https://www.neelnanda.io/mechanistic-interpretability/getting-started An interactive demo of sparse autoencoders (made by Neuronpedia) https://www.neuronpedia.org/gemma-scope#main Coding tutorials for mechanistic interpretability (made by ARENA) https://arena3-chapter1-transformer-interp.streamlit.app/ Звуковая дорожка на русском языке: Влад Бурмистров. Sections: 0:00 - Where facts in LLMs live 2:15 - Quick refresher on transformers 4:39 - Assumptions for our toy example 6:07 - Inside a multilayer perceptron 15:38 - Counting parameters 17:04 - Superposition 21:37 - Up next ------------------ These animations are largely made using a custom Python library, manim. See the FAQ comments here: https://3b1b.co/faq#manim https://github.com/3b1b/manim https://github.com/ManimCommunity/manim/ All code for specific videos is visible here: https://github.com/3b1b/videos/ The music is by Vincent Rubinetti. https://www.vincentrubinetti.com https://vincerubinetti.bandcamp.com/album/the-music-of-3blue1brown https://open.spotify.com/album/1dVyjwS8FBqXhRunaG5W5u ------------------ 3blue1brown is a channel about animating math, in all senses of the word animate. If you're reading the bottom of a video description, I'm guessing you're more interested than the average viewer in lessons here. It would mean a lot to me if you chose to stay up to date on new ones, either by subscribing here on YouTube or otherwise following on whichever platform below you check most regularly. Mailing list: https://3blue1brown.substack.com Twitter: https://twitter.com/3blue1brown Instagram: https://www.instagram.com/3blue1brown Reddit: https://www.reddit.com/r/3blue1brown Facebook: https://www.facebook.com/3blue1brown Patreon: https://patreon.com/3blue1brown Website: https://www.3blue1brown.com
- Author:Taylor
- URL:https://www.taylorblog.top/article/1c82186a-d85d-8009-bbc7-e419694a5b02
- Copyright:All articles in this blog, except for special statements, adopt BY-NC-SA agreement. Please indicate the source!







.png?table=block&id=3492186a-d85d-8036-afa6-d04ba7b9d421&t=3492186a-d85d-8036-afa6-d04ba7b9d421)
.png?table=block&id=3492186a-d85d-801e-bbf0-c3f2af2b27fe&t=3492186a-d85d-801e-bbf0-c3f2af2b27fe)
.png?table=block&id=3372186a-d85d-80a0-8eef-cb0482fa6ec4&t=3372186a-d85d-80a0-8eef-cb0482fa6ec4)