每日论文|长短期记忆(Long Short-Term Memory, 1997)


This is the second piece in the Daily Paper series, following yesterday’s 1986 letter on back-propagation. If a recurrent net must store information across long time intervals, standard backpropagation through time often fails. This 1997 Neural Computation article introduces long short-term memory (LSTM). Only the abstract is translated in full; the rest is a bilingual reading guide, not a line-by-line translation of the paper. The article is copyright Massachusetts Institute of Technology and is not released under an open licence that permits free adaptation.

这是「每日论文」的第 2 篇,接在昨天的 1986 年反向传播短文之后。循环网络若要把信息存过很长的时间间隔,标准的沿时间反向传播往往会失败。1997 年这篇 Neural Computation 长文提出了长短期记忆(LSTM)。下面只对摘要做完整的中英对照,其余是导读,不逐段翻译全文。本文版权属于麻省理工学院出版社,不是允许自由改编的开放许可。

Bibliographic details 论文信息

  • Title 标题:Long Short-Term Memory
  • Authors 作者:Sepp Hochreiter、Jürgen Schmidhuber
  • Affiliations 单位:Fakultät für Informatik, Technische Universität München, 80290 München, Germany 慕尼黑工业大学信息学系(Hochreiter);Corso Elvezia 36, 6900 Lugano, Switzerland 瑞士卢加诺 IDSIA(Schmidhuber)
  • Journal 期刊:Neural Computation Vol. 9 第 9 卷,issue 8 第 8 期,pp. 1735–1780 第 1735–1780 页
  • Communicated by 沟通编辑:Ronald Williams
  • Published 发表:15 November 1997 1997 年 11 月 15 日(received 28 August 1995 1995 年 8 月 28 日收稿;accepted 24 February 1997 1997 年 2 月 24 日接受)
  • DOI:10.1162/neco.1997.9.8.1735

The bibliographic details above were checked against the official MIT Press page and the 1997 typeset PDF. An earlier technical report, FKI-207-95 (August 1995, Technische Universität München), is the basis of the journal article.

以上著录已对照 MIT Press 期刊页面与 1997 年正式排印 PDF 核对。更早的技术报告是两人 1995 年 8 月在慕尼黑工大发布的 FKI-207-95,期刊稿即以此为基础。

Abstract 摘要

The English text below is the published abstract, quoted verbatim after checking the official MIT Press page and the original PDF. The Chinese that follows is a complete translation. Hochreiter (1991) refers to the first author’s thesis analysis of the problem.

下面的英文是正式刊出摘要,已对照 MIT Press 页面与原文 PDF 逐字核对后引出;中文为对应全译。文中 Hochreiter (1991) 指第一作者的学位论文分析。

Learning to store information over extended time intervals by recurrent backpropagation takes a very long time, mostly because of insufficient, decaying error backflow. We briefly review Hochreiter’s (1991) analysis of this problem, then address it by introducing a novel, efficient, gradient-based method called long short-term memory (LSTM). Truncating the gradient where this does not do harm, LSTM can learn to bridge minimal time lags in excess of 1000 discrete-time steps by enforcing constant error flow through constant error carousels within special units. Multiplicative gate units learn to open and close access to the constant error flow. LSTM is local in space and time; its computational complexity per time step and weight is O(1). Our experiments with artificial data involve local, distributed, real-valued, and noisy pattern representations. In comparisons with real-time recurrent learning, back propagation through time, recurrent cascade correlation, Elman nets, and neural sequence chunking, LSTM leads to many more successful runs, and learns much faster. LSTM also solves complex, artificial long-time-lag tasks that have never been solved by previous recurrent network algorithms.

用循环反向传播学习在较长的时间间隔上存储信息,往往要花非常长的时间,主要是因为回流的误差不够、而且会衰减。我们简要回顾 Hochreiter(1991)对这一问题的分析,随后引入一种新的、高效的基于梯度的方法,称为长短期记忆(long short-term memory,LSTM)。在截断梯度不会造成损害的地方加以截断,LSTM 能通过在特殊单元内部的恒定误差旋转木马(constant error carousel)上强制保持恒定误差流,学会跨越超过 1000 个离散时间步的最小时滞。乘法门单元则学会打开和关闭通往这条恒定误差流的通路。LSTM 在空间和时间上都是局部的;其每个时间步、每个权重的计算复杂度为 O(1)。我们在人工数据上的实验涵盖局部的、分布式的、实值的以及带噪声的模式表征。与实时循环学习、沿时间反向传播、循环级联相关、Elman 网络以及神经序列分块相比,LSTM 成功的试验显著更多,学得也快得多。LSTM 还解决了此前循环网络算法从未解决过的、复杂的人工长时滞任务。

Background 背景

Recurrent networks can use feedback connections to store representations of recent input events in the form of activations—short-term memory, as opposed to long-term memory embodied by slowly changing weights. That is potentially useful for applications such as speech processing, non-Markovian control, and music composition. The most widely used algorithms for learning what to put in short-term memory, however, take too much time or do not work well when the minimal time lags between inputs and the corresponding teacher signals are long. Existing methods, the authors write, do not provide clear practical advantages over back-propagation in feedforward nets with limited time windows.

循环网络可以用反馈连接,把近期输入事件的表征保存在单元的激活里——作者把这称为短期记忆,以区别于由缓慢变化的权重所体现的长期记忆。这对语音处理、非马尔可夫控制和作曲一类应用是有吸引力的。可是,当相关输入与对应教师信号之间的最小时滞很长时,当时最常用的学习算法要么太慢,要么根本学不好。作者写道:现有方法虽然理论上很有吸引力,但相对「在有限时间窗口的前馈网上做反向传播」,并没有清楚的实际优势。

The difficulty is the scale of error flowing backward in time. With backpropagation through time (BPTT) or real-time recurrent learning (RTRL), those error signals tend to blow up or vanish; their temporal evolution depends exponentially on the size of the weights, as analysed by Hochreiter in 1991. Exploding errors may lead to oscillating weights; vanishing errors make learning to bridge long lags take a prohibitive amount of time, or fail altogether. For a logistic sigmoid, the maximal derivative is 0.25; when absolute weight values are below 4.0, |f′(net)·w| is typically less than 1, and the error tends to decay exponentially with the number of time steps. Larger initial weights or a larger learning rate do not change the ratio of long-range to short-range error flow: BPTT is too sensitive to recent distractions. A similar analysis was later presented by Bengio, Simard, and Frasconi (1994).

问题出在误差沿时间回传时的尺度。用沿时间反向传播(BPTT)或实时循环学习(RTRL)时,回传的误差信号往往会爆炸或消失,其时间演化对权重大小呈指数依赖——这是 Hochreiter 1991 年分析过的现象。误差爆炸可能导致权重振荡;误差消失则使跨越长时滞的学习耗时过长,甚至完全学不会。对 logistic sigmoid,导数的最大值是 0.25;当权重绝对值小于 4.0 时,|f′(net)·w| 通常小于 1,误差倾向于随时间步数指数衰减。加大初始权重或学习率并不能改变「长程误差流相对短程误差流」的比例:系统对近期干扰过于敏感。Bengio、Simard 与 Frasconi(1994)稍后也给出了相近的分析。

Section 2 reviews other contemporaneous approaches: nets with time constants or time delays, Ring’s method of adding higher-order units when error signals conflict, search and discrete error propagation in the work of Bengio and colleagues, Kalman-filter training, and multiplicative units in second-order nets. The authors also report that random weight guessing solved several tasks from earlier papers faster than the algorithms those papers proposed. That does not mean guessing is a good algorithm; it means those tasks were often too simple. More realistic tasks need many free parameters or high weight precision, which makes guessing infeasible. Schmidhuber’s hierarchical chunker systems can bridge arbitrary lags, but only if there is local predictability across the subsequences that cause the lags; performance deteriorates as noise rises and sequences become less compressible. LSTM is designed to keep error from vanishing or exploding over long intervals, without relying on such local regularities.

第 2 节回顾了当时的其他路线:带时间常数或时间延迟的网络、Ring 为冲突误差添加高阶单元的方法、Bengio 等人的搜索与离散误差传播、Kalman 滤波训练,以及二阶网络中的乘法单元。作者还指出,他们发现随机猜权重就能比不少先前论文里的算法更快解决那些论文中的若干任务——这并不说明猜权重是好算法,只说明那些任务往往太简单。更现实的任务需要很多自由参数或很高的权重精度,猜权重就不可行了。Schmidhuber 的层次分块系统可以跨越任意时滞,但前提是造成时滞的子序列具有局部可预测性;噪声升高、输入变得更不可压缩时,其表现会变差。LSTM 的设计目标,正是在不依赖这类局部规律的情况下,让误差在很长的时间里既不消失也不爆炸。

Method 方法

The authors first use a “naive” construction to show where the difficulty lies. Constant error flow through a single self-connected unit j requires f′j(netj(t))·wjj = 1. Taking the identity fj(x) = x and fixing wjj = 1.0 keeps the unit’s activation constant: yj(t + 1) = yj(t). This is the constant error carousel (CEC), the central feature of LSTM. Once that linear unit is also connected to other inputs and outputs, two weight conflicts appear. The same incoming weight must both store an input and later protect what has been stored; the same outgoing weight must both retrieve the cell’s content when needed and keep it from disturbing other units at other times. The longer the lag, the longer stored information and already-correct outputs must be protected, and the sharper the conflict. A bare CEC is therefore not enough.

作者先用一个「朴素」构造说明困难所在。若要使误差在单个自连接单元 j 上恒定流动,需要 f′j(netj(t))·wjj = 1。取恒等激活 fj(x) = x,并固定 wjj = 1.0,则该单元的激活保持不变:yj(t + 1) = yj(t)。这就是恒定误差旋转木马(constant error carousel,CEC),也是 LSTM 的核心。可是一旦这个线性单元还连向其他输入和输出,就会出现两类权重冲突:同一条输入权重既要负责「写入」又要负责「在此后保护已写入的内容」;同一条输出权重既要在需要时读出内容,又要在不需要时避免干扰其他单元。时滞越长,已存储的信息和已经正确的输出都要被保护得更久,冲突也越尖锐。朴素 CEC 因此不够用。

LSTM extends the CEC with two multiplicative gates, forming a memory cell. The jth memory cell is denoted cj. At its centre is a linear unit with a fixed self-connection of weight 1.0 and a one-step delay; it also receives a multiplicative input gate inj and a multiplicative output gate outj. At time t:

LSTM 的做法,是在 CEC 外面加上两个乘法门,组成记忆单元(memory cell)。记第 j 个记忆单元为 cj。它的中心是带固定自连接(权重 1.0、延迟一个时间步)的线性单元;此外还有输入门 inj 和输出门 outj。在时刻 t:

netinj(t) = Σu winju yu(t − 1),  yinj(t) = finj(netinj(t))

netinj(t) = Σu winju yu(t − 1),  yinj(t) = finj(netinj(t))

netoutj(t) = Σu woutju yu(t − 1),  youtj(t) = foutj(netoutj(t))

netoutj(t) = Σu woutju yu(t − 1),  youtj(t) = foutj(netoutj(t))

netcj(t) = Σu wcju yu(t − 1)

netcj(t) = Σu wcju yu(t − 1)

The internal state starts at scj(0) = 0, and for t > 0

内部状态从 scj(0) = 0 开始,对 t > 0 有

scj(t) = scj(t − 1) + yinj(t) · g(netcj(t))

scj(t) = scj(t − 1) + yinj(t) · g(netcj(t))

The cell output is

单元输出为

ycj(t) = youtj(t) · h(scj(t))

ycj(t) = youtj(t) · h(scj(t))

The differentiable function g squashes the cell’s net input; the differentiable function h scales the output computed from the internal state. In the experiments, gate units typically use a logistic sigmoid with range [0, 1]; h has range [−1, 1] and g has range [−2, 2]. The appendix gives the explicit forms f(x) = 1 / (1 + exp(−x)), h(x) = 2 / (1 + exp(−x)) − 1, and g(x) = 4 / (1 + exp(−x)) − 2. The summation index u may stand for input units, gate units, memory cells, or conventional hidden units—the topology is chosen by the user. Several memory cells may share the same input and output gates, forming a memory cell block.

可微函数 g 用来压缩记忆单元的净输入,可微函数 h 则从内部状态得到输出。实验里,门单元常用值域 [0, 1] 的 logistic sigmoid;h 的值域是 [−1, 1],g 的值域是 [−2, 2]。附录给出的具体形式是:f(x) = 1 / (1 + exp(−x)),h(x) = 2 / (1 + exp(−x)) − 1,g(x) = 4 / (1 + exp(−x)) − 2。求和指标 u 可以是输入单元、门单元、记忆单元,或普通隐藏单元——拓扑由使用者决定。若干记忆单元可以共享同一对输入门和输出门,形成记忆单元块(memory cell block)。

The input gate protects the memory stored in the CEC from perturbation by irrelevant inputs; the output gate protects other units from currently irrelevant memory contents. Learning uses a truncated gradient. Once an error signal arrives at a memory-cell output, it is scaled by the output-gate activation and by h′; it then lies inside the CEC, where it can flow back indefinitely without further scaling. When it leaves the cell through the input gate and g, it is scaled by the input-gate activation and by g′, serves to change the incoming weights, and is then truncated. Errors arriving at the memory cell’s net inputs (netcj, netinj, netoutj) are not propagated further back in time. Truncation prevents loops in which an error that left a cell on the input side could re-enter it on the output side, and thereby keeps the error flow through the CEC constant. The authors emphasise that this truncation does not affect long-term error flow.

输入门保护 CEC 里已存储的内容,使不相干的输入不容易把它改掉;输出门则保护其他单元,使当前不必读出的记忆内容不容易干扰它们。学习时采用截断的梯度:一旦误差到达记忆单元的输出,先按输出门激活和 h′ 缩放,然后进入 CEC,可以在内部状态上无限回传而不再被缩放;当它经输入门和 g 离开记忆单元时,再按输入门激活和 g′ 缩放,用来修改进入该单元的权重,随后即被截断。误差不会再从记忆单元的净输入(包括 netcj、netinj、netoutj)继续向更早的时间传播。截断避免了「误差从输入侧漏出后再从输出侧回来」的回路,从而保证 CEC 上的误差流保持恒定。作者强调,这种截断并不损害长程误差流。

Only derivatives such as ∂scj/∂w need to be stored and updated, so the update complexity is O(1) per time step and weight—the same as BPTT for fully recurrent nets, and much better than RTRL. Unlike full BPTT, LSTM is local in both space and time: there is no need to store activations from the whole sequence in a stack of potentially unlimited size.

算法只需存储和更新 ∂scj/∂w 这类导数,每个时间步、每个权重的更新复杂度是 O(1),与全循环网上的 BPTT 相当,远低于 RTRL。与完整 BPTT 不同的是,LSTM 在空间和时间上都是局部的:不必把整段序列的激活压进一个可能无限增长的栈。

The paper also treats two practical difficulties. One is “abuse”: early in learning, the net may use memory cells as bias cells, or store the same information in two cells, and may then take a long time to release them. Two remedies are offered: adding a memory cell and its gates when the error stops decreasing (sequential network construction), and giving each output gate a negative initial bias so that cell activations start near zero, with more negatively biased cells “allocated” later. The other is internal state drift: if a cell’s inputs are mostly positive or mostly negative, its state tends to drift, h′ becomes very small, and the gradient vanishes again. Their simple remedy is to initialise the input-gate bias toward zero. It is worth noting that the 1997 LSTM has only input and output gates; it does not yet include the forget gate familiar from later work.

文中还处理了两类实践问题。一是「滥用」:学习初期,网络可能把记忆单元当成偏置单元来用,或让两个单元存同一信息,很久才释放。作者给出两种对策:按需要逐步加入记忆单元(顺序构网);以及给输出门一个负的初始偏置,让单元激活一开始靠近零,偏置更负的单元更晚被「分配」。二是内部状态漂移:若记忆单元的输入长期偏正或偏负,状态会逐渐漂走,h′ 变得很小,梯度再次消失。他们采用的办法是把输入门的初始偏置设向零。需要说明:1997 年这篇里的 LSTM 只有输入门和输出门,还没有后来文献里常见的遗忘门。

Main experimental results 主要实验结果

Apart from Experiment 1, the tasks have no short-time-lag training exemplars to ease learning; the authors treat that as the mark of a genuine long-time-lag problem. Training is always online rather than batch, with logistic sigmoid activations. Initial weights are drawn from [−0.2, 0.2] in Experiments 1 and 2, and from [−0.1, 0.1] otherwise. Activations are reset after each input sequence. The figures below are only those the paper itself reports.

除实验 1 外,本文的任务都没有「很短时滞的训练样本」来给学习开路;作者认为这才是真正的长时滞问题。训练一律采用在线学习(而非批学习),激活函数为 logistic sigmoid。实验 1 和 2 的初始权重取自 [−0.2, 0.2],其余实验取自 [−0.1, 0.1]。处理完一条输入序列后,网络激活被重置。下面只写入原文实际报告的数字。

Experiment 1: embedded Reber grammar 实验 1:嵌入式 Reber 文法

This is not a long-time-lag task (minimal lags can be as short as nine steps). It is included because it was a popular recurrent-net benchmark, and because it shows the benefit of output gates: to predict the symbol before last, the net must remember the second symbol, without disturbing more easily learned local transitions. The net reads strings one symbol at a time and predicts the next symbol. The authors use a local representation with seven input and seven output units, 256 training strings, and 256 disjoint test strings. A trial is successful only if every symbol of every sequence in both sets is predicted correctly (the output unit or units for the possible next symbol or symbols are always the most active). Three randomly generated training/test splits, each with ten different initialisations, give the means of 30 trials in Table 1.

这不是长时滞任务(最小时滞可以短到 9 步),收入文中是因为它是当时常用的循环网络基准,也因为输出门在这里明显有用:要预测倒数第二个符号,网络必须记住序列开头的第二个符号,同时又不能干扰更容易学的局部转移。任务是逐符号读入字符串并预测下一个符号。作者使用 7 个输入单元和 7 个输出单元的局部表征,256 条训练串和 256 条不重叠的测试串。一次试验算成功,当且仅当训练集和测试集中所有序列的所有符号都被正确预测(对应可能的下一符号的输出单元始终最活跃)。三组随机划分的训练/测试集,每组 10 次不同初始权重,表 1 是 30 次试验的平均。

Compared with RTRL, Elman’s training procedure (ELM), and Fahlman’s recurrent cascade-correlation (RCC), LSTM almost always learns the task (only 2 failures in 150 trials) and learns faster. Selected figures (percentage of successful trials and sequence presentations until success) are as follows. RTRL, about 170 weights, learning rate 0.05: “some fraction” successful, after 173,000 presentations; RTRL, about 494 weights, learning rate 0.1: “some fraction,” 25,000; ELM, about 435 weights: 0% successful, still unsuccessful after more than 200,000; RCC, about 119–198 weights: 50%, 182,000. LSTM with four blocks of size 1, 264 weights, and learning rate 0.1: 100%, 39,740; three blocks of size 2, 276 weights, learning rate 0.1: 100%, 21,730; the same architecture at learning rate 0.2: 97%, 14,060; four blocks of size 1 at learning rate 0.5: 97%, 9,500; three blocks of size 2 at learning rate 0.5: 100%, 8,440 (the number of training examples on that last row varies between 3,800 and 24,100). Weight counts in the first rows are estimates, because the source papers do not give every technical detail. The authors also report that, without output gates, they did not achieve fast learning.

与 RTRL、Elman 的训练程序(ELM)以及 Fahlman 的循环级联相关(RCC)相比,LSTM 几乎总能学会(150 次试验里只有 2 次失败),而且更快。若干对照数字(成功百分比与达到成功所需的序列呈现次数)如下:RTRL,约 170 个权重、学习率 0.05,成功「某一部分」,约 173,000 次;RTRL,约 494 个权重、学习率 0.1,成功「某一部分」,约 25,000 次;ELM,约 435 个权重,成功率为 0,超过 200,000 次仍未成功;RCC,约 119–198 个权重,成功率 50%,约 182,000 次。LSTM 在 4 个大小为 1 的单元块、264 个权重、学习率 0.1 时成功率为 100%,约 39,740 次;3 个大小为 2 的单元块、276 个权重、学习率 0.1 时为 100%,约 21,730 次;同一结构、学习率 0.2 时为 97%,约 14,060 次;4 个大小为 1 的单元块、学习率 0.5 时为 97%,约 9,500 次;3 个大小为 2 的单元块、学习率 0.5 时为 100%,约 8,440 次(该行所需训练样本在 3,800 到 24,100 之间变化)。前几行的权重数目是作者根据原文未给全的细节所做的估计。作者还写明:没有输出门时,他们没有得到快速学习。

Experiment 2: noise-free and noisy sequences 实验 2:无噪声与带噪声的长序列

Task 2a uses only two very similar training sequences, (y, a1, …, ap−1, y) and (x, a1, …, ap−1, x), each chosen with probability 0.5; predicting the final symbol requires storing the first symbol for p steps. Success means that, after training, the maximal absolute error of all output units at sequence end stays below 0.25 on 10,000 successive randomly chosen sequences. Table 2 reports means of 18 trials. With a short lag p = 4, RTRL at learning rates 1.0, 4.0, and 10.0 succeeded in 78%, 56%, and 22% of trials, after about 1,043,000, 892,000, and 254,000 presentations respectively (the text also states that 7/9 of trials succeeded at p = 4). No trial succeeded at p = 10. At p = 100, RTRL and BPTT (about 10,404 weights) still had 0% success after more than 5,000,000 presentations; the two-net sequence chunker (CH, 10,506 weights) succeeded in 33% of trials, after about 32,400 presentations; LSTM (10,504 weights, learning rate 1.0) succeeded in 100%, after about 5,040. The authors note that a hierarchical chunker can also always solve this task quickly.

任务 2a 只有两条非常相似的训练序列 (y, a1, …, ap−1, y) 和 (x, a1, …, ap−1, x),各以 0.5 的概率出现;要预测最后一个符号,就必须把第一个符号保持 p 步。成功标准是:训练后在连续 10,000 条随机输入序列上,所有输出单元在序列末的最大绝对误差始终低于 0.25。表 2 是 18 次试验的平均。RTRL 在短时滞 p = 4 时,学习率 1.0、4.0、10.0 的成功率分别为 78%、56%、22%,成功时分别约需 1,043,000、892,000、254,000 次(正文也写到 p = 4 时 7/9 的试验成功);p = 10 时 0 次成功。p = 100 时,RTRL 与 BPTT(约 10,404 个权重)在超过 5,000,000 次呈现后仍为 0%;两网络序列分块器(CH,10,506 个权重)成功率为 33%,约 32,400 次;LSTM(10,504 个权重,学习率 1.0)成功率为 100%,约 5,040 次。作者同时注明:层次分块器也能始终较快地解决这一任务。

Task 2b replaces the deterministic subsequence with a random one, removing local compressibility. The chunker, BPTT, and RTRL all failed; LSTM was always successful. On average over 18 trials, success at p = 100 came after 5,680 sequence presentations. LSTM therefore does not need sequence regularities in order to work well.

任务 2b 把中间那段确定性子序列换成随机子序列,从而去掉局部可压缩规律。分块器、BPTT 和 RTRL 都失败了;LSTM 则始终成功。18 次试验的平均,在 p = 100 时约 5,680 次序列呈现后达到成功。这说明 LSTM 并不依赖序列的局部规律。

Task 2c is the hardest in this section: many random distractor symbols, a minimal lag of q + 1, and expected sequence length q + 14. The net must store the second symbol at least until a trigger symbol e appears. Success means that, on 10,000 successive random sequences, the prediction error of both output units for the final symbol stays below 0.2. Twenty trials were run for each tested pair (p, q). When the number of distractors p grows in proportion to the lag, the number of training sequences LSTM needs rises only slowly: about 30,000 for (q, p) = (50, 50) with 364 weights; 31,000 for (100, 100); 33,000 for (200, 200); 38,000 for (500, 500); and 49,000 for (1000, 1000) with 6,064 weights. If the minimal lag is held near 1,000 steps and the expected frequency of distractors q/p is increased, learning slows: about 49,000 presentations at p = 500, 75,000 at p = 200, 135,000 at p = 100, and 203,000 at p = 50. The authors say that BPTT and RTRL have no chance of solving nontrivial tasks with minimal lags of 1,000 steps, and already appear quite useless once lags exceed as few as 10 steps.

任务 2c 是本节最难的:大量随机干扰符号,最小时滞为 q + 1,期望序列长度为 q + 14。网络必须把第二个符号至少保持到触发符 e 出现。成功标准是:连续 10,000 条随机序列上,两个输出单元对最后符号的预测误差始终低于 0.2。每个 (p, q) 组合做 20 次试验。当干扰符号数 p 与时滞大致成比例增加时,LSTM 达到成功所需的训练序列数增加得很慢:例如 (q, p) = (50, 50) 约 30,000 次(364 个权重),(100, 100) 约 31,000 次,(200, 200) 约 33,000 次,(500, 500) 约 38,000 次,(1000, 1000) 约 49,000 次(6,064 个权重)。若固定最小时滞约 1000 步而增加干扰符号的出现频率 q/p,学习会变慢:p = 500 时约 49,000 次,p = 200 时约 75,000 次,p = 100 时约 135,000 次,p = 50 时约 203,000 次。作者认为 BPTT 和 RTRL 没有机会解决最小时滞达 1000 步的非平凡任务;时滞只要超过大约 10 步,它们就显得相当无用。

Experiment 3: noise and signal on the same channel 实验 3:信号与噪声在同一通道

Task 3a is Bengio et al.’s 1994 two-sequence classification problem: on a single input line, the first N real-valued elements carry the class information, and later elements are Gaussian noise with mean 0 and variance 0.2; sequence length is chosen randomly between T and T + T/10. Correct classification means absolute output error at the end of the sequence below 0.2. The authors state clearly that the problem is so simple that random weight guessing solves it faster than LSTM and any other method with published results; it is included to show that LSTM has no fundamental difficulty when signal and noise share the same input line. Table 4 reports means of 10 trials (102 weights). For T = 100, N = 3, stopping criterion ST1 (none of 256 test sequences misclassified) was reached after about 27,380 presentations, and ST2 (plus mean absolute error below 0.01) after about 39,850; the fraction misclassified on a further 2,560 test sequences was 0.000195. For T = 100, N = 1 the corresponding figures are about 58,370 / 64,330 and 0.000117; for T = 1000, N = 3, about 446,850 / 452,460 and 0.000078.

任务 3a 是 Bengio 等人 1994 年的两序列分类问题:一条输入线上,前 N 个实值元素携带类别信息,其后为均值为 0、方差为 0.2 的高斯噪声;序列长度在 T 与 T + T/10 之间随机选取。正确分类定义为序列末绝对输出误差低于 0.2。作者明确写道:这个问题很简单,随机猜权重比 LSTM 以及任何已发表结果的方法都更快;收入它是为了说明,信号与噪声混在同一输入线上时,LSTM 没有原则性障碍。表 4 为 10 次试验的平均(102 个权重)。例如 T = 100、N = 3 时,达到停止标准 ST1(256 条测试序列无一误分类)约需 27,380 次呈现,达到 ST2(再加上平均绝对误差低于 0.01)约需 39,850 次,随后在 2,560 条测试序列上的误分类比例为 0.000195;T = 100、N = 1 时约为 58,370 / 64,330,误分类比例 0.000117;T = 1000、N = 3 时约为 446,850 / 452,460,误分类比例 0.000078。

Task 3b adds the same Gaussian noise to the information-conveying elements as well. For T = 100, N = 3, ST1 / ST2 were about 41,740 / 43,250, with misclassification fraction 0.00828; for T = 100, N = 1, about 74,950 / 78,430 and 0.01500; for T = 1000, N = 1, about 481,060 / 485,080 and 0.01207 (all means of 10 trials).

任务 3b 把同样的高斯噪声也加在信息元素上。T = 100、N = 3 时,ST1 / ST2 约 41,740 / 43,250,误分类比例 0.00828;T = 100、N = 1 时约 74,950 / 78,430,比例 0.01500;T = 1000、N = 1 时约 481,060 / 485,080,比例 0.01207(均为 10 次平均)。

Task 3c changes the targets to 0.2 and 0.8 and adds Gaussian noise with mean 0 and variance 0.1 on the targets. The net must learn the conditional expectations of the targets given the inputs, which requires high weight precision, so the task cannot be solved quickly by random guessing. For T = 100, N = 3, training stopped after about 269,650 presentations, with misclassification fraction 0.00558 on 2,560 test sequences and an average difference of 0.014 between output and expected target; for T = 100, N = 1, about 565,640 presentations, 0.00441, and 0.012.

任务 3c 把目标改为 0.2 与 0.8,并在目标上加均值为 0、方差为 0.1 的高斯噪声。网络必须学习给定输入下目标的条件期望,因而需要较高的权重精度,不能再靠快速随机猜权重解决。T = 100、N = 3 时,约 269,650 次后停止,2,560 条测试序列上误分类比例 0.00558,输出与期望目标的平均差为 0.014;T = 100、N = 1 时约 565,640 次,比例 0.00441,平均差 0.012。

Experiment 4 and 5: adding and multiplication 实验 4 与 5:加法与乘法

The adding problem requires the net to store precise real values for a long time. Each input is a pair: the first component is drawn uniformly from [−1, 1], and the second is a marker (1.0, 0.0, or −1.0). Exactly two pairs in a sequence are marked with 1.0, and the target at the end is their first components summed and scaled into [0, 1]: 0.5 + (X1 + X2)/4.0. Sequence length lies between T and T + T/10; the minimal lag is T/2. A sequence is processed correctly if the absolute error is below 0.04. The net has 93 weights. On a test set of 2,560 random sequences, the average test error was always below 0.01, and there were never more than three incorrectly processed sequences. Table 7 (means of 10 trials) reports: for T = 100 (minimal lag 50), 1 error out of 2,560, success after about 74,000 presentations; for T = 500 (lag 250), 0 errors, about 209,000; for T = 1000 (lag 500), 1 error, about 853,000. For T = 1000, the number of required training examples varies between 370,000 and 2,020,000, exceeding 700,000 in only three cases. The authors conclude that LSTM can work with distributed, continuous-valued representations and can learn calculations involving continuous values, and that there is no significant, harmful internal state drift when continuous values are stored for minimal delays of T/2 steps.

加法问题要求网络在很长时间内保存精确的实值。每个输入是一对:第一个分量在 [−1, 1] 上均匀随机,第二个分量是标记(1.0、0.0 或 −1.0)。一条序列里恰好有两个被标记为 1.0 的对,序列末的目标是这两个第一分量之和经缩放后落在 [0, 1] 上:0.5 + (X1 + X2)/4.0。序列长度在 T 与 T + T/10 之间,最小时滞为 T/2。绝对误差低于 0.04 算处理正确。网络有 93 个权重。在由 2,560 条随机序列组成的测试集上,平均测试误差始终低于 0.01,错误处理的序列从来不超过 3 条。表 7(10 次试验平均)中:T = 100(最小时滞 50)时,2,560 条里错 1 条,约 74,000 次后达到停止标准;T = 500(时滞 250)时错 0 条,约 209,000 次;T = 1000(时滞 500)时错 1 条,约 853,000 次。T = 1000 时,所需训练样本在 370,000 到 2,020,000 之间,只有 3 次超过 700,000。作者据此认为:LSTM 能处理分布式、连续值表征,并能完成涉及连续值的计算;在最小时滞为 T/2 的条件下保存连续值时,没有出现严重有害的内部状态漂移。

The multiplication problem changes the target to the product X1 × X2 of the two marked inputs, to test whether LSTM can only exploit the CEC’s built-in integration. Here T = 100, the minimal lag is 50, and the net again has 93 weights. Two stopping criteria are used (fewer than nseq = 140 or 13 of the 2,000 most recent training sequences have error above 0.04). Table 8 gives means of 10 trials: at nseq = 140, 139 errors out of 2,560 test sequences, mean squared error 0.0223, after about 482,000 presentations; at nseq = 13, 14 errors, mean squared error 0.0139, after about 1,273,000. The text adds that, under these two criteria, the average test error was always below 0.026 and 0.013 respectively, and there were never more than 170 and 15 incorrectly processed sequences. The authors conclude that LSTM can also solve tasks that involve both continuous-valued representations and inherently non-integrative processing.

乘法问题把目标改成两个被标记输入的乘积 X1 × X2,用来检验 LSTM 是否只能做 CEC 天生擅长的积分式累加。T = 100、最小时滞 50、同样 93 个权重。用两种停止标准(最近 2,000 条训练序列中误差大于 0.04 的条数分别少于 nseq = 140 和 13),表 8 为 10 次试验平均:nseq = 140 时,2,560 条测试序列中错 139 条,均方误差 0.0223,约 482,000 次;nseq = 13 时错 14 条,均方误差 0.0139,约 1,273,000 次。正文还写:在这两种标准下,平均测试误差始终分别低于 0.026 和 0.013,错误序列分别从来不超过 170 和 15 条。作者的结论是:LSTM 也能解决既涉及连续值表征、又本质上不是积分式的任务。

Experiment 6: temporal order 实验 6:时间顺序

The task is to classify sequences according to the order of widely separated relevant symbols. Each sequence starts with E and ends with a trigger symbol B; most other symbols are drawn from {a, b, c, d}. In task 6a, an X or a Y is placed at t1 (between 10 and 20) and at t2 (between 50 and 60); sequence length is between 100 and 110, and there are four classes according to the pairs (X,X), (X,Y), (Y,X), and (Y,Y). Task 6b adds a third relevant position t3 (between 66 and 76) and eight classes. Error signals occur only at the end of a sequence; a sequence is classified correctly if the final absolute error of all output units is below 0.3. On a test set of 2,560 random sequences, the average test error was always below 0.1, and there were never more than three incorrectly classified sequences. Table 9 reports: task 6a (156 weights, means of 20 trials) had 1 error out of 2,560, with success after about 31,390 presentations; task 6b (308 weights, means of 10 trials) had 2 errors, after about 571,100. In task 6a, the delays between the first and second relevant inputs, and between the second relevant input and the end of the sequence, are at least 30 steps. LSTM, the authors conclude, can extract information conveyed by the temporal order of widely separated inputs.

任务是根据序列中相距很远的相关符号的出现顺序做分类。序列以 E 开头、以触发符 B 结尾,其余多为 {a, b, c, d} 中的随机符号。任务 6a 在位置 t1(10 到 20)和 t2(50 到 60)放置 X 或 Y,序列长度在 100 到 110 之间,按 (X,X)、(X,Y)、(Y,X)、(Y,Y) 分成四个类。任务 6b 再增加第三个相关位置 t3(66 到 76),分成八个类。误差只在序列末给出;所有输出单元的最终绝对误差都低于 0.3 才算分类正确。在 2,560 条随机测试序列上,平均测试误差始终低于 0.1,错误分类从来不超过 3 条。表 9:任务 6a(156 个权重,20 次试验平均)在 2,560 条中错 1 条,约 31,390 次后成功;任务 6b(308 个权重,10 次试验平均)错 2 条,约 571,100 次。任务 6a 中,第一个与第二个相关输入之间、以及第二个相关输入与序列末之间,时滞都至少为 30 步。作者以此说明:LSTM 能够提取由相距很远的输入的时间顺序所传递的信息。

Impact and later work 影响与后续工作

This 1997 paper turns “constant error flow inside a memory cell” into a trainable recurrent architecture: an input gate controls writing, an output gate controls reading, and the CEC carries error across very long lags. For recurrent learning at the time, it offered a practical route that did not depend on short-lag training exemplars or on local compressibility of the sequence. All of the experiments are artificial. In the conclusion the authors write that they intend to apply LSTM to real-world data, including time-series prediction, music composition, and speech processing, and that it would be interesting to combine it with sequence chunkers.

这篇 1997 年的论文把「让误差在记忆单元内部恒定流动」写成一套可训练的循环结构:输入门控制写入,输出门控制读出,CEC 负责跨越很长的时滞。就当时的循环网络学习而言,它给出了一种不必依赖短时滞样本、也不必依赖序列局部可压缩性的实用路线。文中的实验全部是人工任务;作者在结论里写道,下一步打算把它用到真实数据上,应用方向包括时间序列预测、作曲和语音处理,并设想与序列分块器结合。

Later developments lie outside the results of this article, but a few landmarks help in reading the classic. In 2000, Gers, Schmidhuber, and Cummins, in Learning to Forget: Continual Prediction with LSTM (Neural Computation), added a forget gate so that the internal state could also be reset by learning. The “three-gate LSTM” of later textbooks is that later form, not the 1997 original. LSTM was then used widely for sequence tasks such as speech recognition, handwriting recognition, and machine translation, and was one of the dominant sequence models in the mid-2010s. Architectures such as the Transformer later took its place in many language and multimodal tasks. The idea of gated memory, and the motive of a nearly constant path that keeps gradients from vanishing, remain a clear step in the history of deep learning. This paper itself does not report those later application figures, and none are added here.

后来的发展不在本文的结果范围之内,但读这篇经典时值得知道几条线索。2000 年,Gers、Schmidhuber 与 Cummins 在 Neural Computation 发表的 Learning to Forget: Continual Prediction with LSTM 为记忆单元增加了遗忘门,使内部状态也可以被学会重置——今天教科书里的「三门 LSTM」是那一步之后的形态,而不是 1997 年原文的形态。此后 LSTM 在语音识别、手写识别和机器翻译等序列任务上被广泛使用,在 2010 年代中期一度是序列建模的主流结构之一。再往后,Transformer 等架构在许多语言和多模态任务上取代了它的位置;但门控记忆这一想法,以及「用一条近乎恒定的通路避免梯度消失」这一动机,仍然是深度学习史里清楚的一环。本文本身没有报告这些后来的应用数字,这里也不另补。

Limitations 局限

Section 6.1 lists the limitations in the authors’ own terms. First, the efficient truncated-backpropagation version of LSTM will not easily solve problems similar to a strongly delayed XOR, where the goal is to compute the XOR of two widely separated inputs that occurred somewhere in a noisy sequence. Storing only one of the inputs does not reduce the expected error; the task is non-decomposable, in that the error cannot be reduced incrementally by first solving an easier subgoal. In theory the full gradient (perhaps with additional conventional hidden units that receive input from the memory cells) could circumvent this limitation, but the authors do not recommend it: the full gradient increases computational complexity; constant error flow through the CECs can be shown only for truncated LSTM; and in a few experiments with non-truncated LSTM they found no significant difference, precisely because outside the CECs error flow tends to vanish quickly.

第 6.1 节是作者自己列出的限制。第一,高效的截断反向传播版本不容易解决类似「强延迟异或」的问题:要计算先前在噪声序列中某处出现的两个相距很远的输入的异或。只存储其中之一并不能降低期望误差,任务无法通过先完成一个更易的子目标来逐步降误差。理论上可以用完整梯度(或许再加一些接收记忆单元输入的传统隐藏单元)绕过这一限制,但作者并不推荐:完整梯度会增加计算复杂度;只有截断 LSTM 才能被证明在 CEC 上具有恒定误差流;而且他们做的几次非截断实验与截断版本没有显著差异,正因为误差一旦离开 CEC 就往往会迅速消失。

Second, each memory cell block needs two additional units (an input gate and an output gate). Relative to standard recurrent nets, this does not increase the number of weights by more than a factor of 9: each conventional hidden unit is replaced by at most three units, so in the fully connected case the number of weights increases by a factor of 32. The experiments use quite comparable weight counts for LSTM and the competing approaches.

第二,每个记忆单元块需要额外的输入门和输出门。与标准循环网相比,权重数量的增加不超过 9 倍:每个传统隐藏单元至多被三个单元替换,全连接时权重数量变为原来的 32 倍。他们的实验在 LSTM 与对照方法之间使用了相当的权重数目。

Third, because of constant error flow through the CECs, LSTM generally runs into problems similar to those of a feedforward net that sees the entire input string at once. Some tasks can be solved quickly by random weight guessing but not by truncated LSTM with small initial weights; the paper cites the 500-step parity problem. LSTM typically behaves much like a feedforward net trained by back-propagation that sees the entire input—and that is also precisely why it so clearly outperforms previous approaches on many nontrivial tasks with significant search spaces.

第三,由于 CEC 上的误差流恒定,LSTM 会遇到与「一次看完整段输入的前馈网」类似的困难。例如,有些任务随机猜权重可以很快解决,但用小权重初始化的截断 LSTM 不行,文中举了 500 步奇偶问题。LSTM 的行为往往很像用反向传播训练、并且能看见全部输入的前馈网——而这也正是它在许多搜索空间较大的非平凡任务上明显优于先前方法的原因。

Fourth, LSTM has no problems with the notion of recency that go beyond those of other approaches, but all gradient-based methods suffer from a practical inability to count discrete time steps precisely. If it matters whether a signal occurred 99 or 100 steps ago, an additional counting mechanism seems necessary. Easier tasks, such as distinguishing 3 steps from 11, pose no problem: LSTM can give more weight to recent inputs through an appropriate negative connection from cell output to input, and can learn decays where necessary.

第四,LSTM 在「近因」概念上的问题并不比其他方法更严重;但所有基于梯度的方法都难以精确计数离散时间步。若 99 步前和 100 步前出现的信号必须被区分,就似乎需要额外的计数机制。较容易的任务,例如只需区分 3 步与 11 步,对 LSTM 不构成问题:它可以通过记忆单元输出到输入的负连接,给更近的输入更大权重,并在需要时学会衰减。

The experimental setting should also be kept in view: all tasks are artificially generated sequences, with no figures on real speech or text, and the 1997 architecture does not yet include a forget gate. These points are context for reading a classic, not a complaint about the original paper.

另外应记住实验语境:全部是人工生成的序列任务,没有给出真实语音或文本上的数字;1997 年的结构也还没有遗忘门。这些不是对原文的苛责,而是阅读时需要放在手里的上下文。

Key terms 关键词

  • Long short-term memory (LSTM) 长短期记忆:A recurrent architecture with memory cells and gates, designed to store information and preserve error flow across very long time intervals. 一种带记忆单元与门控的循环网络结构,用来在很长的时间间隔上保存信息并保持误差流。
  • Constant error carousel (CEC) 恒定误差旋转木马:The self-connection of weight 1 at the centre of a memory cell, which allows the internal state—and the error inside it—to be carried from one time step to the next without scaling. 记忆单元中心那条权重固定为 1 的自连接,使内部状态(及其中的误差)可以逐时间步原样传递。
  • Vanishing / exploding gradient 梯度消失 / 梯度爆炸:Error flowing backward in time decays or grows exponentially with the number of steps, making long lags hard to learn or making training unstable. 回传误差随时间步数指数衰减或指数放大,使长时滞难以学习或使训练不稳定。
  • Memory cell 记忆单元:A composite unit built around a CEC, with an input gate and an output gate that control writing and reading. 围绕 CEC 构建的复合单元,用输入门和输出门控制写入与读出。
  • Input gate 输入门:The multiplicative gate that controls whether new input is written into the internal state, and how error leaves the CEC on the input side. 控制新输入是否写入内部状态、以及误差如何经输入侧离开 CEC 的乘法门。
  • Output gate 输出门:The multiplicative gate that controls whether the internal state is read out, and how error enters the CEC. 控制内部状态是否被读出、以及误差如何进入 CEC 的乘法门。
  • Truncated backpropagation 截断反向传播:A gradient computation that stops error once it leaves a memory cell or gate unit, so that error flow through the CEC remains constant. 误差一旦离开记忆单元或门单元就不再继续沿时间回传,以保证 CEC 上的恒定误差流。
  • BPTT / RTRL 沿时间反向传播 / 实时循环学习:Two standard gradient methods for training recurrent nets at the time; both suffer badly from exponential error decay on genuine long-time-lag tasks. 当时训练循环网的两种标准梯度方法;在真正的长时滞任务上,二者都会受到指数误差衰减的严重打击。

Original paper 原文链接

DOI:https://doi.org/10.1162/neco.1997.9.8.1735
Neural Computation page 页面:https://direct.mit.edu/neco/article-abstract/9/8/1735/6109/Long-Short-Term-Memory

14 次浏览

发表回复