LSTM的计算公式及理解
一. 入门
对于深度学习和LSTM的新手,可参考零基础入门深度学习系列文章,这些文章用通俗易懂的方式介绍了深度学习的基础知识,包括前向传播和反向传播的数学推导等,适合入门深度学习和LSTM。
零基础入门深度学习(1) - 感知器
零基础入门深度学习(2) - 线性单元和梯度下降
零基础入门深度学习(3) - 神经网络和反向传播算法
零基础入门深度学习(4) - 卷积神经网络
零基础入门深度学习(5) - 循环神经网络
零基础入门深度学习(6) - 长短时记忆网络(LSTM)
零基础入门深度学习(7) - 递归神经网络
二. 计算过程和公式
LSTM的详细计算过程的解释可参考:LSTM以及三重门,遗忘门,输入门,输出门。该文章把下图的计算过程一步一步拆开来解释。
LSTM解决远程遗忘问题的关键是细胞状态cell,上图的上方的水平线贯穿运行。这条水平线形象地说明:上一时刻的细胞状态,先遗忘掉一些不重要的信息(怎么遗忘由决定),然后从当前时刻的输入中添加一些信息(怎么添加由和决定)。细胞状态类似于传送带。直接在整个链上运行,只有一些少量的线性交互。信息在上面流传保持不变会很容易。
The major innovation of LSTM is its memory cell ct which essentially acts as an accumulator of the state information. The cell is accessed, written and cleared by several self-parameterized controlling gates. Every time a new input comes, its information will be accumulated to the cell if the input gate is activated. Also, the past cell status could be “forgotten” in this process if the forget gate is on. Whether the latest cell output will be propagated to the final state is further controlled by the output gate . One advantage of using the memory cell and gates to control information flow is that the gradient will be trapped in the cell (also known as constant error carousels) and be prevented from vanishing too quickly, which is a critical problem for the vanilla RNN model.
LSTM的计算公式:
三. LSTM的变体
peephole LSTM:在计算遗忘门、输入门、输出门时要考虑cell的状态。
耦合遗忘门和输入门:遗忘率和输入率总和为1。
GRU
GRU对LSTM做了两个大改动:
- 将输入门、遗忘门、输出门变为两个门:更新门(Update Gate)和重置门$r_t$(Reset Gate)。
- 将单元状态与输出合并为一个状态:。
【参考资料】
[译] 理解 LSTM(Long Short-Term Memory, LSTM) 网络
【推荐】国内首个AI IDE,深度理解中文开发场景,立即下载体验Trae
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步
· 基于Microsoft.Extensions.AI核心库实现RAG应用
· Linux系列:如何用heaptrack跟踪.NET程序的非托管内存泄露
· 开发者必知的日志记录最佳实践
· SQL Server 2025 AI相关能力初探
· Linux系列:如何用 C#调用 C方法造成内存泄露
· Manus爆火,是硬核还是营销?
· 终于写完轮子一部分:tcp代理 了,记录一下
· 别再用vector<bool>了!Google高级工程师:这可能是STL最大的设计失误
· 震惊!C++程序真的从main开始吗?99%的程序员都答错了
· 单元测试从入门到精通