Language Modeling with Gated Convolutional Networks/paper/zh
| Research Paper | |
|---|---|
| Authors | Yann N. Dauphin; Angela Fan; Michael Auli; David Grangier |
| Year | 2016 |
| Topic area | NLP |
| Difficulty | Research |
| arXiv | 1612.08083 |
| Download PDF | |
Language Modeling with Gated Convolutional Networks
Yann N. Dauphin Angela Fan Michael Auli David Grangier
Language Modeling with Gated Convolutional Networks
Yann N. Dauphin Angela Fan Michael Auli David Grangier
摘要
迄今为止,语言建模的主流方法以循环神经网络为基础。其在该任务上的成功通常被归因于捕捉无界上下文的能力。在本文中,我们通过堆叠卷积发展了一种有限上下文方法,由于允许在序列 token 上并行化,因此可能更高效。我们提出了一种新的简化门控机制,其性能优于 Oord 等人 (2016b),并研究了关键架构决策的影响。所提方法在 WikiText-103 基准上取得了 state-of-the-art 的成绩——尽管该基准具有长期依赖——并在 Google Billion Words 基准上获得了具有竞争力的结果。相比循环基线,我们的模型将给一句话评分的延迟降低了一个数量级。据我们所知,这是非循环方法首次在这些大规模语言任务上与强大的循环模型竞争。
卷积神经网络,循环网络,语言建模
1 引言
统计语言模型通过对给定前文条件下下一个词的概率进行建模,来估计词序列的概率分布,即
| $ {\textstyle {{P\hspace{0pt}{(w_{0},\ldots,w_{N})}} = {P\hspace{0pt}{(w_{0})}\hspace{0pt}{\prod\limits_{i = 1}^{N}{P\hspace{0pt}{(\left. w_{i} \middle| {w_{0},\ldots,w_{i - 1}} \right.)}}}}},} $ |
其中 $ {\textstyle w_{i}} $ 是词表中离散的词索引。语言模型是语音识别 (Yu & Deng, 2014) 与机器翻译 (Koehn, 2010) 系统中的关键组成部分。
近来,神经网络 (Bengio et al., 2003; Mikolov et al., 2010; Jozefowicz et al., 2016) 已被证明优于经典的 n-gram 语言模型 (Kneser & Ney, 1995; Chen & Goodman, 1996)。这些经典模型受数据稀疏性影响,难以表示大上下文以及长程依赖。神经语言模型通过将词嵌入到连续空间,并在其上应用神经网络来解决这一问题。当前语言建模的 state-of-the-art 基于 long short term memory networks (LSTM; Hochreiter et al., 1997),理论上可以建模任意长的依赖。
在本文中,我们提出了新的门控卷积网络(gated convolutional networks)并将其用于语言建模。卷积网络可以通过堆叠来表示较大的上下文规模,并在不断扩大的上下文上提取更抽象的层次化特征 (LeCun & Bengio, 1995)。这使其能够通过在大小为 $ {\textstyle N} $ 的上下文上应用 $ {\textstyle \mathcal{O}\hspace{0pt}{(\frac{N}{k})}} $ 次操作(其中 $ {\textstyle k} $ 为核宽度)来建模长程依赖。相比之下,循环网络将输入视为链式结构,因此需要线性数量 $ {\textstyle \mathcal{O}\hspace{0pt}{(N)}} $ 的操作。
对输入进行层次化分析与经典的语法形式主义具有相似之处——后者会构建粒度逐步细化的句法树结构,例如句子由名词短语和动词短语组成,各自又具有进一步的内部结构 (Manning & Schütze, 1999; Steedman, 2002)。层次化结构也使学习更容易,因为相对于链式结构,给定上下文大小所需的非线性数量更少,从而缓解了 vanishing gradient 问题 (Glorot & Bengio, 2010)。
现代硬件非常适合高度可并行化的模型。在循环网络中,下一个输出依赖于上一个隐状态,无法在序列元素之间并行化。然而,卷积网络非常适合这种计算范式,因为对所有输入词的计算可以同时进行 (§2)。
门控已被证明对循环神经网络达到 state-of-the-art 性能至关重要 (Jozefowicz et al., 2016)。我们的 gated linear units 通过为梯度提供一条线性路径,同时保留非线性能力,缓解了深层架构中的 vanishing gradient 问题 (§5.2)。
我们表明,门控卷积网络在 Google Billion Word 基准 (Chelba et al., 2013) 上的表现优于近期发表的其他语言模型,例如在类似设置下训练的 LSTM。我们还在 WikiText-103 基准上评估了模型处理长程依赖的能力——该基准上模型以整段而非单句为条件——并在该数据集上取得了新的 state-of-the-art (Merity et al., 2016)。最后,我们表明 gated linear units 比 Oord 等人 (2016; §4, §5) 的 LSTM 风格门控具有更高的准确率与更快的收敛速度。
2 方法
在本文中,我们引入一种新的神经语言模型,使用门控的时间卷积替代循环网络中常用的循环连接。神经语言模型 (Bengio et al., 2003) 为每个词 $ {\textstyle w_{0},\ldots,w_{N}} $ 生成上下文表示 $ {\textstyle \mathbf{H} = {\lbrack\mathbf{h}_{0},\ldots,\mathbf{h}_{N}\rbrack}} $,以预测下一个词 $ {\textstyle P\hspace{0pt}{(\left. w_{i} \middle| \mathbf{h}_{i} \right.)}} $。循环神经网络 $ {\textstyle f} $ 通过递推函数 $ {\textstyle \mathbf{h}_{i} = {f\hspace{0pt}{(\mathbf{h}_{i - 1},w_{i - 1})}}} $ 计算 $ {\textstyle \mathbf{H}} $,这本质上是一个顺序过程,无法在 $ {\textstyle i} $ 维度上并行化。111并行化通常改在多个序列之间进行。
我们提出的方法用一个函数 $ {\textstyle f} $ 对输入做卷积,得到 $ {\textstyle \mathbf{H} = {f \ast w}} $,因此没有时间维度上的依赖,便于在一句话的各个词上并行化。该过程将每个上下文计算为若干前序词的函数。与循环网络相比,上下文大小是有限的,但我们将证明:无限上下文并非必需,且我们的模型能够表示足够大的上下文以在实践中表现良好 (§5)。
图 1 展示了模型架构。词由存储于查找表 $ {\textstyle \mathbf{D}^{{|\mathcal{V}|} \times e}} $ 中的向量嵌入表示,其中 $ {\textstyle |\mathcal{V}|} $ 为词表大小,$ {\textstyle e} $ 为嵌入维度。模型的输入是词序列 $ {\textstyle w_{0},\ldots,w_{N}} $,由词嵌入 $ {\textstyle \mathbf{E} = {\lbrack\mathbf{D}_{w_{0}},\ldots,\mathbf{D}_{w_{N}}\rbrack}} $ 表示。隐藏层 $ {\textstyle h_{0},\ldots,h_{L}} $ 计算如下:
| $ {\textstyle {h_{l}\hspace{0pt}{(\mathbf{X})}} = {{{({{\mathbf{X} \ast \mathbf{W}} + \mathbf{b}})} \otimes \sigma}\hspace{0pt}{({{\mathbf{X} \ast \mathbf{V}} + \mathbf{c}})}}} $ | (1) |
其中 $ {\textstyle m,n} $ 分别为输入和输出特征图的数量,$ {\textstyle k} $ 是 patch 大小,$ {\textstyle \mathbf{X} \in {\mathbb{R}}^{N \times m}} $ 是 $ {\textstyle h_{l}} $ 层的输入(词嵌入或前层的输出),$ {\textstyle \mathbf{W} \in {\mathbb{R}}^{k \times m \times n}} $、$ {\textstyle \mathbf{b} \in {\mathbb{R}}^{n}} $、$ {\textstyle \mathbf{V} \in {\mathbb{R}}^{k \times m \times n}} $、$ {\textstyle \mathbf{c} \in {\mathbb{R}}^{n}} $ 是可学习参数,$ {\textstyle \sigma} $ 为 sigmoid 函数,$ {\textstyle \otimes} $ 为矩阵之间的逐元素乘积。
在对输入做卷积时,我们要确保 $ {\textstyle \mathbf{h}_{i}} $ 不包含未来词的信息。我们通过移位卷积输入,使核看不到未来上下文来实现这一点 (Oord et al., 2016a)。具体来说,我们在序列开头零填充 $ {\textstyle k - 1} $ 个元素,假设第一个输入元素是句首标记(不被预测),其中 $ {\textstyle k} $ 为核宽度。
每一层的输出是由门 $ {\textstyle \sigma\hspace{0pt}{({{\mathbf{X} \ast \mathbf{V}} + \mathbf{c}})}} $ 调制的线性投影 $ {\textstyle {\mathbf{X} \ast \mathbf{W}} + \mathbf{b}} $。类似 LSTM,这些门对矩阵 $ {\textstyle {\mathbf{X} \ast \mathbf{W}} + \mathbf{b}} $ 的每个元素做乘法,控制在层级结构中传递的信息。我们将该门控机制称为 Gated Linear Units (GLU)。在输入 $ {\textstyle \mathbf{E}} $ 上堆叠多层,可得到每个词的上下文表示 $ {\textstyle \mathbf{H} = {{h_{L} \circ \ldots \circ h_{0}}\hspace{0pt}{(\mathbf{E})}}} $。我们将卷积与 gated linear unit 包裹在一个预激活残差块中,该块将输入加到输出上 (He et al., 2015a)。出于计算效率考虑,这些块采用 bottleneck 结构,每个块最多 5 层。
获取模型预测最简单的方法是使用 softmax 层,但对于大词表来说这通常计算效率低下,因此更倾向于使用像 noise contrastive estimation (Gutmann & Hyvärinen, ) 或 hierarchical softmax (Morin & Bengio, 2005) 这样的近似方法。我们选择后者的改进版——adaptive softmax,它为高频词分配更大容量,为低频词分配较小容量 (Grave et al., 2016a)。这降低了内存需求,并在训练与测试时都加快了计算。
3 门控机制
门控机制控制着网络中信息流经的路径,已被证明对循环神经网络非常有用 (Hochreiter & Schmidhuber, 1997)。LSTM 通过一个单独的细胞、由 input 与 forget 门控制,实现长程记忆。这使得信息可以在可能跨越许多时间步的过程中无阻地流动。如果没有这些门,信息很容易在每一步的变换中消失。相比之下,卷积网络不会遭受同样的 vanishing gradient 问题;我们在实验中也发现它们不需要 forget 门。
因此,我们考虑只具有输出门的模型,让网络控制哪些信息应该在层级结构中向上传播。我们表明该机制对语言建模有用,因为它允许模型选择对预测下一个词最相关的词或特征。与我们的工作并行,Oord 等人 (2016b) 展示了 LSTM 风格机制 $ {\textstyle {{\text{tanh}\hspace{0pt}{({{\mathbf{X} \ast \mathbf{W}} + \mathbf{b}})}} \otimes \sigma}\hspace{0pt}{({{\mathbf{X} \ast \mathbf{V}} + \mathbf{c}})}} $ 在卷积式图像建模中的有效性。随后,Kalchbrenner 等人 (2016) 通过添加额外门控将该机制扩展到翻译以及字符级语言建模中。
Gated linear units 是一种简化的门控机制,基于 Dauphin & Grangier (2015) 关于非确定性门的工作,它通过将线性单元与门耦合来缓解 vanishing gradient 问题。这在保留该层非线性能力的同时,让梯度可以无缩放地通过线性单元传播。我们将 LSTM 风格门控(称为 gated tanh unit, GTU)的梯度记作
| $ {\textstyle {\nabla{\lbrack{{{\text{tanh}\hspace{0pt}{(\mathbf{X})}} \otimes \sigma}\hspace{0pt}{(\mathbf{X})}}\rbrack}} = {\text{tanh}^{\prime}\hspace{0pt}{(\mathbf{X})}\hspace{0pt}{\nabla{\mathbf{X} \otimes \sigma}}\hspace{0pt}{(\mathbf{X})}}} $ | |||
| $ {\textstyle {+ {\sigma^{\prime}\hspace{0pt}{(\mathbf{X})}\hspace{0pt}{\nabla{\mathbf{X} \otimes \text{tanh}}}\hspace{0pt}{(\mathbf{X})}}}.} $ | (2) |
注意,由于缩放因子 $ {\textstyle \text{tanh}^{\prime}\hspace{0pt}{(\mathbf{X})}} $ 与 $ {\textstyle \sigma^{\prime}\hspace{0pt}{(\mathbf{X})}} $ 的存在,随着层数堆叠,该梯度会逐渐消失。相比之下,gated linear unit 的梯度
| $ {\textstyle {\nabla{\lbrack{{\mathbf{X} \otimes \sigma}\hspace{0pt}{(\mathbf{X})}}\rbrack}} = {{{\nabla{\mathbf{X} \otimes \sigma}}\hspace{0pt}{(\mathbf{X})}} + {{\mathbf{X} \otimes \sigma^{\prime}}\hspace{0pt}{(\mathbf{X})}\hspace{0pt}{\nabla\mathbf{X}}}}} $ | (3) |
对 $ {\textstyle \sigma\hspace{0pt}{(\mathbf{X})}} $ 中处于激活状态的门控单元而言,存在一条无缩放的路径 $ {\textstyle {\nabla{\mathbf{X} \otimes \sigma}}\hspace{0pt}{(\mathbf{X})}} $。这可以被理解为一种乘性 skip connection,有助于梯度在层间流动。我们在第 §5.2 节通过实验比较了不同的门控方案,发现 gated linear units 能更快地收敛到更优的 perplexity。
4 实验设置
4.1 数据集
我们在两个公开的大规模语言建模数据集上报告结果。首先,Google Billion Word 数据集 (Chelba et al., 2013) 被认为是最大的语言建模数据集之一,包含近十亿个 token,词表超过 80 万词。在该数据集中,出现少于 3 次的词被替换为一个特殊的未知符号。数据基于英文语料 $ {\textstyle 30,301,028} $ 句,顺序已被打乱。其次,WikiText-103 是一个较小的数据集,包含超过 1 亿 token,词表约 20 万词 (Merity et al., 2016)。与 GBW 不同,其句子是连续的,使模型可以以比单句更大的上下文为条件。对两个数据集,我们都在每行开头加上句首标记 <S >,在每行末尾加上句尾标记 </S>。在 Google Billion Word 语料中,每个序列是一个句子;而在 WikiText-103 中,序列是整段。模型将 <S> 与 </S > 作为输入,但只预测句尾标记 </S>。我们通过在每个数据集标准的留出测试集上计算 perplexity $ {\textstyle \text{e}^{{\frac{1}{N}\hspace{0pt}\sum_{i}^{N}} - {{\log p}\hspace{0pt}{({w_{i}|{\ldots,w_{i - 1}}})}}}} $ 来评估模型。
| Name | GCNN-13 | GCNN-14B | GCNN-9 | GCNN-8B | GCNN-8 | GCNN-14 |
|---|---|---|---|---|---|---|
| Dataset | Google Billion Word | wikitext-103 | ||||
| Lookup | 128 | 280 | ||||
| Conv1 | $ {\textstyle \lbrack 4,1268\rbrack \times 1} $ | $ {\textstyle \lbrack 5,512\rbrack \times 1} $ | $ {\textstyle \lbrack 4,807\rbrack \times 1} $ | $ {\textstyle \lbrack 1,512\rbrack \times 1} $ | $ {\textstyle \lbrack 4,900\rbrack \times 1} $ | $ {\textstyle \lbrack 6,850\rbrack \times 3} $ |
| Conv2.x | $ {\textstyle \begin{bmatrix} {4,1268} \\ {4,1268} \end{bmatrix} \times 12} $ | $ {\textstyle \begin{bmatrix} {1,128} \\ {5,128} \\ {1,512} \end{bmatrix} \times 3} $ | $ {\textstyle \begin{bmatrix} {4,807} \\ {4,807} \end{bmatrix} \times 4} $ | $ {\textstyle \begin{bmatrix} {1,128} \\ {5,128} \\ {1,512} \end{bmatrix} \times 3} $ | $ {\textstyle \lbrack 4,900\rbrack \times 7} $ | $ {\textstyle \lbrack 1,850\rbrack \times 1} $ |
| Conv3.x | $ {\textstyle \begin{bmatrix} {1,512} \\ {5,512} \\ {1,1024} \end{bmatrix} \times 3} $ | $ {\textstyle \begin{bmatrix} {1,256} \\ {5,256} \\ {1,512} \end{bmatrix} \times 3} $ | $ {\textstyle \lbrack 5,850\rbrack \times 4} $ | |||
| Conv4.x | $ {\textstyle \begin{bmatrix} {1,1024} \\ {5,1024} \\ {1,2048} \end{bmatrix} \times 6} $ | $ {\textstyle \begin{bmatrix} {1,1024} \\ {1,1024} \\ {1,2048} \end{bmatrix} \times 1} $ | $ {\textstyle \lbrack 1,850\rbrack \times 1} $ | |||
| Conv5.x | $ {\textstyle \begin{bmatrix} {1,1024} \\ {5,1024} \\ {1,4096} \end{bmatrix} \times 1} $ | $ {\textstyle \lbrack 4,850\rbrack \times 3} $ | ||||
| Conv6.x | $ {\textstyle \lbrack 4,1024\rbrack \times 1} $ | |||||
| Conv7.x | $ {\textstyle \lbrack 4,2048\rbrack \times 1} $ | |||||
| AdaSoftmax | 10k,40k,200k | 4k,40k,200k | 2k,10k,50k | 10k,20k,200k | ||
| Model | Test PPL | Hardware |
| Sigmoid-RNN-2048 (Ji et al., 2015) | 68.3 | 1 CPU |
| Interpolated KN 5-Gram (Chelba et al., 2013) | 67.6 | 100 CPUs |
| Sparse Non-Negative Matrix LM (Shazeer et al., 2014) | 52.9 | - |
| RNN-1024 + MaxEnt 9 Gram Features (Chelba et al., 2013) | 51.3 | 24 GPUs |
| LSTM-2048-512 (Jozefowicz et al., 2016) | 43.7 | 32 GPUs |
| 2-layer LSTM-8192-1024 (Jozefowicz et al., 2016) | 30.6 | 32 GPUs |
| BIG GLSTM-G4 (Kuchaiev & Ginsburg, 2017) | 23.311footnotemark: 1 | 8 GPUs |
| LSTM-2048 (Grave et al., 2016a) | 43.9 | 1 GPU |
| 2-layer LSTM-2048 (Grave et al., 2016a) | 39.8 | 1 GPU |
| GCNN-13 | 38.1 | 1 GPU |
| GCNN-14 Bottleneck | 31.9 | 8 GPUs |
4.2 训练
我们在 Torch (Collobert et al., 2011) 中实现模型,并在 Tesla M40 GPU 上训练。我们的大多数模型在单 GPU 上训练,因为我们专注于发现具有良好泛化能力和高效测试时计算的紧凑架构。对较大的模型,我们使用 8 GPU 的设置进行训练:将模型复制到每张 GPU,并将 batch 划分,使每个 worker 计算 1/8 的梯度。然后使用 Nvidia NCCL 对梯度求和。多 GPU 设置使我们能够训练具有更大隐藏单元的模型。
我们使用 Nesterov 动量进行训练 (Sutskever et al., 2013)。虽然其内存代价是再多存储一份与参数同样大小的向量,但相对标准的 SGD,它仅以极少的额外计算就显著提升了收敛速度。我们还通过 gradient clipping (Pascanu et al., 2013) 与 weight normalization (Salimans & Kingma, 2016) 进一步加快了收敛。
Pascanu 等人 (2013) 主张使用 gradient clipping,因为它可以防止 RNN 中典型的梯度爆炸问题。然而,gradient clipping 并不局限于 RNN,因为它可以从一般的信赖域方法概念中导出。Gradient clipping 通过球形信赖域得到
| $ {\textstyle \Delta\hspace{0pt}\theta^{\ast}} $ | $ {\textstyle = {{{\operatorname{argmin}\limits_{\substack{{\text{s. t.}\hspace{0pt}{\|{\Delta\hspace{0pt}\theta}\|}} \leq \epsilon}}f}\hspace{0pt}{(\theta)}} + {\nabla{f^{T}\hspace{0pt}\Delta\hspace{0pt}\theta}}}} $ | |||
| $ {\textstyle {= {- {{\max{({\|{\nabla f}\|},\epsilon)}}\hspace{0pt}\frac{\nabla f}{\|{\nabla f}\|}}}}.} $ | (4) |
经验上,即使我们没有使用循环架构,使用 gradient clipping 也能使实验显著更快地收敛。
综合起来,这些方法在相对较大的学习率(如 $ {\textstyle 1} $)下实现了稳定而快速的收敛。
4.3 超参数
我们通过在验证集上的随机搜索做交叉验证,找到良好的超参数配置。对模型架构,我们在 $ {\textstyle \{ 1,\ldots,10\}} $ 中选择残差块的数量,在 $ {\textstyle \{ 128,\ldots,256\}} $ 中选择嵌入维度,在 $ {\textstyle \{ 128,\ldots,2048\}} $ 中选择隐藏单元数,在 $ {\textstyle \{ 3,\ldots,5\}} $ 中选择核宽度。总体而言,找到一个好的架构相当简单,经验法则是模型越大,性能越好。在优化方面,我们使用 Kaiming 初始化 (He et al., 2015b) 初始化模型各层,在区间 $ {\textstyle \lbrack 1.,2.\rbrack} $ 上均匀采样学习率,动量设为 $ {\textstyle 0.99} $,clipping 设为 $ {\textstyle 0.1} $。优化器的良好超参数相当容易确定,且最佳值在不同数据集间变化不大。
5 结果
LSTM 与循环网络能够捕捉长程依赖,并正快速成为自然语言处理的基石。在本节中,我们在两个数据集上将文献中强有力的 LSTM 与 RNN 模型与我们提出的门控卷积方法进行比较。
我们发现,GCNN 在 Google Billion Word 上优于可比的 LSTM 结果。为了精确比较这些方法,我们控制了相同的 GPU 数量与 adaptive softmax 输出模型 (Grave et al., 2016a),因为这些变量对性能有显著影响。在此设置下,GCNN 达到 $ {\textstyle 38.1} $ 的测试 perplexity,而可比的 LSTM 为 $ {\textstyle 39.8} $ perplexity (表 2)。
此外,GCNN 在显著更高的计算效率下也获得了强劲的性能。图 2 显示,我们的方法弥合了过去使用完整 softmax 的模型与使用通常精度较低的 hierarchical softmax 的模型之间的显著差距。得益于 adaptive softmax,GCNN 只需一小部分操作即可达到相同的 perplexity 值。GCNN 超越了其他单模型的 state-of-the-art 方法,仅次于 Jozefowicz 等人 (2016) 大得多的 LSTM——该模型需要更多 GPU 与计算开销大得多的完整 softmax。相比之下,我们训练过的最大模型达到 $ {\textstyle 31.9} $ 测试 perplexity,而上述方法为 $ {\textstyle 30.6} $,但我们仅需在 8 GPU 上训练 2 周,而对方需要在 32 GPU 上训练 3 周。值得注意的是,这些结果可以通过 mixtures of experts (Shazeer et al., 2017) 或对这些模型集成来进一步提升。
| Model | Test PPL | Hardware |
|---|---|---|
| LSTM-1024 (Grave et al., 2016b) | 48.7 | 1 GPU |
| GCNN-8 | 44.9 | 1 GPU |
| GCNN-14 | 37.2 | 4 GPUs |
**footnotetext: 提交后才出现 另一个相关问题是 GCNN 固定的上下文大小是否能够充分建模长序列。在 Google Billion Word 上,平均句子长度相当短——只有 20 个词。我们在 WikiText-103 上进行评估,以判断模型在拥有更大可用上下文的数据集上是否表现良好。在 WikiText-103 上,输入序列是整篇 Wikipedia 文章而非单个句子——平均长度增加到 4000 词。然而,GCNN 在这一问题上也优于 LSTM (表 3)。GCNN-8 模型有 8 层,每层 $ {\textstyle 800} $ 个单元,而 LSTM 有 $ {\textstyle 1024} $ 个单元。这些结果表明,GCNN 能够建模足够的上下文以取得强劲的结果。
我们按照 Chen 等人 (2016) 的做法在 Gigaword 数据集上进行评估,与全连接模型比较。我们发现全连接网络与卷积网络分别达到 55.6 与 29.4 perplexity。我们也在规模小得多的 Penn Treebank 数据集上做了初步实验。当对句子独立评分时,GCNN 与 LSTM 的测试 perplexity 相近,分别为 108.7 与 109.3。不过,通过以前文句子为条件可以获得更好的结果。与 LSTM 不同,我们发现 GCNN 在这个相当小的数据集上过拟合,因此该模型更适合大规模问题。
5.1 计算效率
| Throughput | Responsiveness | ||
|---|---|---|---|
| (CPU) | (GPU) | (GPU) | |
| LSTM-2048 | 169 | 45,622 | 2,282 |
| GCNN-9 | 121 | 29,116 | 29,116 |
| GCNN-8 Bottleneck | 179 | 45,878 | 45,878 |
计算成本是语言模型的重要考量。根据应用场景,需要考虑多个指标。我们将一个模型的 throughput 定义为每秒可处理的 token 数。Throughput 可以通过并行处理多句来摊销顺序操作,从而最大化。相比之下,responsiveness 是顺序处理输入(一次一个 token)的速度。Throughput 重要是因为它表示处理整段文本所需的时间,而 responsiveness 表示完成处理一个句子所需的时间。通过批处理同时评估多个句子,模型可以做到 responsiveness 低但 throughput 高。这种情况下,模型完成单个句子的处理较慢,但能以良好速率处理大量句子。
我们对在 Google Billion Word 基准上达到约 $ {\textstyle 43.9} $ perplexity 的模型评估 throughput 与 responsiveness。我们考虑表 2 中具有 $ {\textstyle 2048} $ 单元的 LSTM、一个具有 7 个按 (He et al., 2015a) 描述的 bottleneck 结构的 ResNet 块的 GCNN-8Bottleneck,以及没有 bottleneck 的 GCNN-8。Bottleneck 块在两个 $ {\textstyle k = 1} $ 层之间夹一个 $ {\textstyle k > 1} $ 的卷积。这种设计通过 $ {\textstyle k = 1} $ 层降维与升维,使卷积在更低维空间中运算,从而降低计算成本。我们的结果表明,使用 bottleneck 块对维持计算效率非常重要。
LSTM 的 throughput 通过使用一个由 $ {\textstyle 750} $ 条长度为 $ {\textstyle 20} $ 的序列组成的大 batch 来测量,每 batch 共 $ {\textstyle 15,000} $ 个 token。Responsiveness 是处理 $ {\textstyle 15,000} $ 个连续 token 的平均速度。表 4 显示 LSTM 与 GCNN 的 throughput 相近。LSTM 在 GPU 上表现非常好,因为 $ {\textstyle 750} $ 的大 batch 在不同句子之间提供了高度并行化。这是由于 LSTM 实现已被彻底优化并使用了 cuDNN,而 cuDNN 中的卷积实现并未针对我们模型所用的 1-D 卷积进行优化。我们相信通过更高效的 1-D cuDNN 卷积可以获得更好的性能。与 LSTM 不同,GCNN 可以同时在序列之间以及每个序列的 token 之间并行化,从而具有 20× 的 responsiveness。
5.2 门控机制
在本节中,我们将 gated linear unit 与其他机制以及没有门控的模型进行比较。我们考虑 (Oord et al., 2016b) 提出的 LSTM 风格门控机制 (GTU) $ {\textstyle {{\text{tanh}\hspace{0pt}{({{\mathbf{X} \ast \mathbf{W}} + \mathbf{b}})}} \otimes \sigma}\hspace{0pt}{({{\mathbf{X} \ast \mathbf{V}} + \mathbf{c}})}} $,以及使用普通 ReLU 或 Tanh 激活的网络。门控单元会增加参数,因此为公平比较,我们仔细对参数量相近的模型做交叉验证。图 3(左)显示,在 WikiText-103 上 GLU 网络收敛到的 perplexity 比其他方法更低。与 gated linear units 类似,ReLU 也具有一条线性路径,使梯度容易通过激活单元。这使得 ReLU 与 GLU 的收敛速度都快得多。另一方面,Tanh 与 GTU 都没有这种线性路径,因此都遭受 vanishing gradient 问题。在 GTU 中,输入与门控单元在单元饱和时都可能切断梯度。
比较 GTU 与 Tanh 模型让我们能够衡量门控的效果,因为 Tanh 模型可以看作去除了 sigmoid 门控单元的 GTU 网络。结果(图 3,左)表明门控单元带来了巨大的差异,提供了有用的建模能力——GTU 与 Tanh 单元之间存在显著的性能差距。类似地,虽然 ReLU 单元并非 GLU 中门控单元的精确消融,但它可以被视作一种简化形式 $ {\textstyle {\text{ReLU}\hspace{0pt}{(\mathbf{X})}} = {\mathbf{X} \otimes {({\mathbf{X} > 0})}}} $,其中门是否激活取决于输入的符号。即便如此,GLU 单元仍带来更低的 perplexity。
在图 3(右)中,我们在更大的 Google Billion Words 数据集上重复同一实验。考虑到该任务所需训练时间较长,我们采用 $ {\textstyle 100} $ 小时的固定时间预算。与 WikiText-103 类似,gated linear units 在此问题上取得了最佳结果。GLU 与 ReLU 之间约有 5 个 perplexity 点的差距,与 (Jozefowicz et al., 2016) 在同一数据集上测得的 LSTM 与 RNN 模型之间的差距相近。
5.3 非线性建模
迄今为止的实验表明,与其他非线性相比,gated linear unit 受益于其所提供的线性路径。接下来,我们将带 GLU 的网络与纯线性网络以及带双线性层的网络进行比较,以衡量 GLU 中门控所提供的非线性路径的影响。该实验的一个动机是线性模型在许多自然语言处理任务上的成功 (Manning & Schütze, 1999)。我们考虑深层 linear 卷积网络,其中各层没有 GLU 的门控单元,形式为 $ {\textstyle {h_{l}\hspace{0pt}{(\mathbf{X})}} = {{\mathbf{X} \ast \mathbf{W}} + \mathbf{b}}} $。多层堆叠不过是模型的一种分解,在 softmax 之前都保持线性,在 softmax 处变为对数线性。GLU 的另一种变体是双线性层 (Mnih & Hinton, 2007),其形式为 $ {\textstyle {h_{l}\hspace{0pt}{(\mathbf{X})}} = {{({{\mathbf{X} \ast \mathbf{W}} + \mathbf{b}})} \otimes {({{\mathbf{X} \ast \mathbf{V}} + \mathbf{c}})}}} $。
图 5 显示 GLU 表现最佳,其次是双线性层,然后是线性层。双线性层比线性层提升了超过 $ {\textstyle 40} $ 个 perplexity 点,而 GLU 又比双线性模型提升了 $ {\textstyle 20} $ 个 perplexity 点。线性模型表现很差,perplexity 为 $ {\textstyle 115} $,甚至差于 Kneser-Ney 5-gram 模型的 $ {\textstyle 67.6} $,尽管前者可以访问更多上下文。令人意外的是,仅引入双线性单元就足以在 Google Billion Word 上达到 $ {\textstyle 61} $ perplexity,这超过了 Kneser-Ney 5-gram 模型以及 (Ji et al., 2015) 的非线性神经模型。
5.4 上下文大小
图 4 显示了上下文大小对门控 CNN 的影响。我们对每个上下文大小尝试了不同的网络深度与核宽度组合,并为每个大小选择表现最佳者。一般而言,更大的上下文可以提升准确率,但当窗口超过 40 个词时收益会迅速递减——即便在 WikiText-103 上,我们可以以整篇 Wikipedia 文章为条件,情况也是如此。这意味着循环模型所提供的无界上下文对于语言建模而言并非严格必要。此外,这一发现也与“通过 truncated backpropagation through time 在仅 40 个时间步后截断梯度即可获得良好的循环网络性能”的事实一致。图 4 还显示,WikiText-103 比 Google Billion Word 从更大的上下文中获益更多,因为在较小上下文下其性能下降更明显。WikiText-103 提供的上下文远多于 Google Billion Word(后者句子平均长度为 20)。不过,虽然文档平均长度接近 4000 token,我们发现仅 30 个 token 的上下文即可获得很强的性能。
5.5 训练
在本节中,我们对 weight normalization 与 gradient clipping 的影响进行消融研究。我们对每种配置分别进行超参数交叉验证以保证公平比较。由于每个实验代价较高,我们仅在训练数据上做一次迭代。图 6 显示,这两种方法都显著加快了收敛。其中,weight normalization 将速度提升了两倍多。这种加速部分得益于能够使用比原本大得多的学习率($ {\textstyle 1} $ 而非 $ {\textstyle 0.01} $)。Clipping 与 weight normalization 都会带来计算开销,但相对于收敛速度的大幅提升而言开销较小。
6 结论
我们为语言建模引入了一种带新型门控机制的卷积神经网络。与循环神经网络相比,我们的方法构建了输入词的层次化表示,使其更容易捕捉长程依赖,这与语言学语法形式主义中树状结构分析的精神相通。同样的性质也使学习更容易,因为特征经过固定数量的层与非线性变换,而循环网络中的处理步数则取决于词在输入中的位置。结果显示,我们的门控卷积网络在 WikiText-103 上取得了新的 state-of-the-art。在 Google Billion Word 基准上,我们表明可以用显著更少的资源获得有竞争力的结果。
致谢
我们要感谢 Ben Graham、Jonas Gehring、Edouard Grave、Armand Joulin 与 Ronan Collobert 的有益讨论。
参考文献
- Bengio et al. (2003) Bengio, Yoshua, Ducharme, Réjean, Vincent, Pascal, and Jauvin, Christian. A neural probabilistic language model. journal of machine learning research, 3(Feb):1137–1155, 2003.
- Chelba et al. (2013) Chelba, Ciprian, Mikolov, Tomas, Schuster, Mike, Ge, Qi, Brants, Thorsten, Koehn, Phillipp, and Robinson, Tony. One billion word benchmark for measuring progress in statistical language modeling. arXiv preprint arXiv:1312.3005, 2013.
- Chen & Goodman (1996) Chen, Stanley F and Goodman, Joshua. An empirical study of smoothing techniques for language modeling. In Proceedings of the 34th annual meeting on Association for Computational Linguistics, pp. 310–318. Association for Computational Linguistics, 1996.
- Chen et al. (2016) Chen, Wenlin, Grangier, David, and Auli, Michael. Strategies for training large vocabulary neural language models. CoRR, abs/1512.04906, 2016.
- Collobert et al. (2011) Collobert, Ronan, Kavukcuoglu, Koray, and Farabet, Clement. Torch7: A Matlab-like Environment for Machine Learning. In BigLearn, NIPS Workshop, 2011. URL http://torch.ch.
- Dauphin & Grangier (2015) Dauphin, Yann N and Grangier, David. Predicting distributions with linearizing belief networks. arXiv preprint arXiv:1511.05622, 2015.
- Glorot & Bengio (2010) Glorot, Xavier and Bengio, Yoshua. Understanding the difficulty of training deep feedforward neural networks. The handbook of brain theory and neural networks, 2010.
- Grave et al. (2016a) Grave, E., Joulin, A., Cissé, M., Grangier, D., and Jégou, H. Efficient softmax approximation for GPUs. ArXiv e-prints, September 2016a.
- Grave et al. (2016b) Grave, E., Joulin, A., and Usunier, N. Improving Neural Language Models with a Continuous Cache. ArXiv e-prints, December 2016b.
- (10) Gutmann, Michael and Hyvärinen, Aapo. Noise-contrastive estimation: A new estimation principle for unnormalized statistical models.
- He et al. (2015a) He, Kaiming, Zhang, Xiangyu, Ren, Shaoqing, and Sun, Jian. Deep residual learning for image recognition. arXiv preprint arXiv:1512.03385, 2015a.
- He et al. (2015b) He, Kaiming, Zhang, Xiangyu, Ren, Shaoqing, and Sun, Jian. Delving deep into rectifiers: Surpassing human-level performance on imagenet classification. In Proceedings of the IEEE International Conference on Computer Vision, pp. 1026–1034, 2015b.
- Hochreiter & Schmidhuber (1997) Hochreiter, Sepp and Schmidhuber, Jürgen. Long short-term memory. Neural computation, 9(8):1735–1780, 1997.
- Ji et al. (2015) Ji, Shihao, Vishwanathan, SVN, Satish, Nadathur, Anderson, Michael J, and Dubey, Pradeep. Blackout: Speeding up recurrent neural network language models with very large vocabularies. arXiv preprint arXiv:1511.06909, 2015.
- Jozefowicz et al. (2016) Jozefowicz, Rafal, Vinyals, Oriol, Schuster, Mike, Shazeer, Noam, and Wu, Yonghui. Exploring the limits of language modeling. arXiv preprint arXiv:1602.02410, 2016.
- Kalchbrenner et al. (2016) Kalchbrenner, Nal, Espeholt, Lasse, Simonyan, Karen, van den Oord, Aaron, Graves, Alex, and Kavukcuoglu, Koray. Neural Machine Translation in Linear Time. arXiv, 2016.
- Kneser & Ney (1995) Kneser, Reinhard and Ney, Hermann. Improved backing-off for m-gram language modeling. In Acoustics, Speech, and Signal Processing, 1995. ICASSP-95., 1995 International Conference on, volume 1, pp. 181–184. IEEE, 1995.
- Koehn (2010) Koehn, Philipp. Statistical Machine Translation. Cambridge University Press, New York, NY, USA, 1st edition, 2010. ISBN 0521874157, 9780521874151.
- Kuchaiev & Ginsburg (2017) Kuchaiev, Oleksii and Ginsburg, Boris. Factorization tricks for LSTM networks. CoRR, abs/1703.10722, 2017. URL http://arxiv.org/abs/1703.10722.
- LeCun & Bengio (1995) LeCun, Yann and Bengio, Yoshua. Convolutional networks for images, speech, and time series. The handbook of brain theory and neural networks, 3361(10):1995, 1995.
- Manning & Schütze (1999) Manning, Christopher D and Schütze, Hinrich. Foundations of statistical natural language processing, 1999.
- Merity et al. (2016) Merity, S., Xiong, C., Bradbury, J., and Socher, R. Pointer Sentinel Mixture Models. ArXiv e-prints, September 2016.
- Mikolov et al. (2010) Mikolov, Tomáš, Martin, Karafiát, Burget, Lukáš, Cernocký, Jan, and Khudanpur, Sanjeev. Recurrent Neural Network based Language Model. In Proc. of INTERSPEECH, pp. 1045–1048, 2010.
- Mnih & Hinton (2007) Mnih, Andriy and Hinton, Geoffrey. Three new graphical models for statistical language modelling. In Proceedings of the 24th international conference on Machine learning, pp. 641–648. ACM, 2007.
- Morin & Bengio (2005) Morin, Frederic and Bengio, Yoshua. Hierarchical probabilistic neural network language model. In Aistats, volume 5, pp. 246–252. Citeseer, 2005.
- Oord et al. (2016a) Oord, Aaron van den, Kalchbrenner, Nal, and Kavukcuoglu, Koray. Pixel recurrent neural networks. arXiv preprint arXiv:1601.06759, 2016a.
- Oord et al. (2016b) Oord, Aaron van den, Kalchbrenner, Nal, Vinyals, Oriol, Espeholt, Lasse, Graves, Alex, and Kavukcuoglu, Koray. Conditional image generation with pixelcnn decoders. arXiv preprint arXiv:1606.05328, 2016b.
- Pascanu et al. (2013) Pascanu, Razvan, Mikolov, Tomas, and Bengio, Yoshua. On the difficulty of training recurrent neural networks. In Proceedings of The 30th International Conference on Machine Learning, pp. 1310–1318, 2013.
- Salimans & Kingma (2016) Salimans, Tim and Kingma, Diederik P. Weight normalization: A simple reparameterization to accelerate training of deep neural networks. arXiv preprint arXiv:1602.07868, 2016.
- Shazeer et al. (2014) Shazeer, Noam, Pelemans, Joris, and Chelba, Ciprian. Skip-gram language modeling using sparse non-negative matrix probability estimation. arXiv preprint arXiv:1412.1454, 2014.
- Shazeer et al. (2017) Shazeer, Noam, Mirhoseini, Azalia, Maziarz, Krzysztof, Davis, Andy, Le, Quoc V., Hinton, Geoffrey E., and Dean, Jeff. Outrageously large neural networks: The sparsely-gated mixture-of-experts layer. CoRR, abs/1701.06538, 2017. URL http://arxiv.org/abs/1701.06538.
- Steedman (2002) Steedman, Mark. The syntactic process. 2002.
- Sutskever et al. (2013) Sutskever, Ilya, Martens, James, Dahl, George E, and Hinton, Geoffrey E. On the importance of initialization and momentum in deep learning. 2013.
- Wang et al. (2015) Wang, Mingxuan, Lu, Zhengdong, Li, Hang, Jiang, Wenbin, and Liu, Qun. gencnn: A convolutional architecture for word sequence prediction. CoRR, abs/1503.05034, 2015. URL http://arxiv.org/abs/1503.05034.
- Yu & Deng (2014) Yu, Dong and Deng, Li. Automatic Speech Recognition: A Deep Learning Approach. Springer Publishing Company, Incorporated, 2014. ISBN 1447157788, 9781447157786.