具自注意力之深層結構性序列生成之研究
Deep Hierarchical Sequence Generation with Self-Attention
摘要
近年來深層生成模型提供學習未標記資料的希望與合成現實資料迅速發展於影像、語言和文本處理。流行的方法如變分自動編碼器 (VAE)、生成對抗網路 (GAN) 以及自迴歸神經網路 (autoregressive neural network) 在各種應用中取得顯著的表現。其中最具吸引力的是基於變分自動編碼器的潛在變數模型,它由推理模型(編碼器)和生成模型(解碼器)組成。編碼器將輸入資料壓縮成潛在表徵,同時解碼器從潛在空間生成合成樣本。變分自動編碼器可以透過優化訓練資料的對數似然的變分下界 (variational lower bound) 來學習編碼器和解碼器。
儘管變分自動編碼器取得巨大的成功,但關鍵的問題是難以學習複雜的潛在變數結構,特別是在大比例影像或高度結構化時序性資料的情況下。給予複雜的自然影像用於訓練,變分自動編碼器在預測時傾向生成模糊的影像。另一方面,序列生成中的變分編碼器由兩個循環神經網路 (RNN) 的編碼器和解碼器組成。一般而言,循環神經網路解碼器由 teacher forcing 訓練,模型在訓練期間接收真實的輸出作為下次的輸入。然而這導致訓練問題,其中 Kullback-Leibler 散度的潛在損失函數消失,因此潛在變數未真正被使用。這種現象被稱為 posterior collapse,它也廣泛存在於隨機性循環神經網路中,其中引入額外的潛在變數來表示循環神經網路的隱藏狀態 (hidden state)。
為了避免 posterior collapse 的問題,最近循環神經網路透過卷積神經網路 (CNN) 的變種實現於順序性資料表徵,其中解碼器被削弱以鼓勵利用潛在變數進行複雜的資料建模。本篇研究提出一種新的變異和結構性潛在變數模型用於序列生成。基本上序列性資料在學習表徵上比非時序性更複雜,使用簡單的變分自動編碼器潛在變數模型可能是不夠的。我們在基於序列到序列學習中的結構性潛在變數模型增強編碼器的能力而不是聚焦在卷積神經網路的實現。這個模型由兩個編碼器和兩個具有意義的潛在變數組成。潛在變數的全局和局部依賴性被發現並且用於複雜的序列生成模型。長短期記憶 (LSTM) 和金字塔雙向長短期記憶 (pBLSTM) 合併為兩個編碼器以抓取互補特徵用於解碼時序性輸出。使用該框架可以緩解 posterior collapse 的問題。
傳統上序列到序列模型循環神經網路編碼器對輸入序列進行編碼,並用另一個循環神經網路解碼器生成可變長度輸出序列。我們提出一種自注意力模型透過自注意力作為基於循環神經網路的編碼器和解碼器之間的接口進一步增強推理模型和生成模型之間的相互作用。然而在這種情況下發展注意力機制具有挑戰性,因為我們想從潛在空間生成新樣本,所以在生成過程中編碼器會被忽略。在這篇論文中,我們使用隨機性循環神經網路作為解碼器,其中額外的潛在變數允許我們在每個時間點對上下文向量 (context vector) 建模。上下文向量計算為注意力資訊,它是訓練期間編碼器的隱藏狀態的加權總和。在測試階段,我們可以從解碼器的先驗 (prior) 採樣重建上下文向量以補償注意力資訊的丟失。以這種方式,此框架可以依據編碼器和解碼器的潛在變數在推理時生成序列性資料。
在實驗中,我們使用兩個流行的自然語言處理資料集 Penn Treebank 和 Yelp 2013 來評估我們提出的模型。實驗結果顯示我們的模型改善生成表現的困惑度 (perplexity) 和避免 posterior collapse 的問題。此外結構性模型能透過全局和局部潛在變數學習不同意義的潛在表徵。在自注意力模型中,我們視覺化注意力權重來探討注意力機制如何運作。我們發現自注意力模型可以檢索有用的資訊幫助生成。
儘管變分自動編碼器取得巨大的成功,但關鍵的問題是難以學習複雜的潛在變數結構,特別是在大比例影像或高度結構化時序性資料的情況下。給予複雜的自然影像用於訓練,變分自動編碼器在預測時傾向生成模糊的影像。另一方面,序列生成中的變分編碼器由兩個循環神經網路 (RNN) 的編碼器和解碼器組成。一般而言,循環神經網路解碼器由 teacher forcing 訓練,模型在訓練期間接收真實的輸出作為下次的輸入。然而這導致訓練問題,其中 Kullback-Leibler 散度的潛在損失函數消失,因此潛在變數未真正被使用。這種現象被稱為 posterior collapse,它也廣泛存在於隨機性循環神經網路中,其中引入額外的潛在變數來表示循環神經網路的隱藏狀態 (hidden state)。
為了避免 posterior collapse 的問題,最近循環神經網路透過卷積神經網路 (CNN) 的變種實現於順序性資料表徵,其中解碼器被削弱以鼓勵利用潛在變數進行複雜的資料建模。本篇研究提出一種新的變異和結構性潛在變數模型用於序列生成。基本上序列性資料在學習表徵上比非時序性更複雜,使用簡單的變分自動編碼器潛在變數模型可能是不夠的。我們在基於序列到序列學習中的結構性潛在變數模型增強編碼器的能力而不是聚焦在卷積神經網路的實現。這個模型由兩個編碼器和兩個具有意義的潛在變數組成。潛在變數的全局和局部依賴性被發現並且用於複雜的序列生成模型。長短期記憶 (LSTM) 和金字塔雙向長短期記憶 (pBLSTM) 合併為兩個編碼器以抓取互補特徵用於解碼時序性輸出。使用該框架可以緩解 posterior collapse 的問題。
傳統上序列到序列模型循環神經網路編碼器對輸入序列進行編碼,並用另一個循環神經網路解碼器生成可變長度輸出序列。我們提出一種自注意力模型透過自注意力作為基於循環神經網路的編碼器和解碼器之間的接口進一步增強推理模型和生成模型之間的相互作用。然而在這種情況下發展注意力機制具有挑戰性,因為我們想從潛在空間生成新樣本,所以在生成過程中編碼器會被忽略。在這篇論文中,我們使用隨機性循環神經網路作為解碼器,其中額外的潛在變數允許我們在每個時間點對上下文向量 (context vector) 建模。上下文向量計算為注意力資訊,它是訓練期間編碼器的隱藏狀態的加權總和。在測試階段,我們可以從解碼器的先驗 (prior) 採樣重建上下文向量以補償注意力資訊的丟失。以這種方式,此框架可以依據編碼器和解碼器的潛在變數在推理時生成序列性資料。
在實驗中,我們使用兩個流行的自然語言處理資料集 Penn Treebank 和 Yelp 2013 來評估我們提出的模型。實驗結果顯示我們的模型改善生成表現的困惑度 (perplexity) 和避免 posterior collapse 的問題。此外結構性模型能透過全局和局部潛在變數學習不同意義的潛在表徵。在自注意力模型中,我們視覺化注意力權重來探討注意力機制如何運作。我們發現自注意力模型可以檢索有用的資訊幫助生成。
In recent years, deep generative models offering the promise of learning based on unlabeled data and synthesizing realistic data have been rapidly developing for image, speech, and text processing. The popular approaches, such as the variational autoencoder (VAE), generative adversarial network (GAN) and autoregressive neural network, have achieved remarkable performance in variety of applications. One of the most attractive solutions is the latent variable model based on VAE, which consists of an inference model (encoder) and a generative model (decoder). The encoder compresses the input data into a latent representation while the decoder generates synthesized samples from the latent space. VAE can learn both the encoder and decoder by optimizing a variational lower bound of log-likelihood from a set of training data.
Despite a great success in VAE, a crucial issue is the difficulty in learning the complicated latent variable structure especially in presence of a large-scale set of images or with the highly structured sequential data. Given the complicated natural images for training, VAE tends to generate the blurry images in prediction. On the other hand, VAE in sequence generation is composed of two recurrent neural networks (RNNs) for both the encoder and decoder. In general, the RNN decoder is trained by teacher forcing where the model receives the ground truth output as input at next time during training. However, this leads to an issue in training where a latent loss function as a Kullback-Leibler divergence vanishes so that the latent variables are not really used. This phenomenon is known as posterior collapse which also widely exists in stochastic RNN where additional latent variables are introduced to represent the hidden states of RNN.
To avoid the issue of posterior collapse, recently, RNN is implemented by a variant of convolutional neural network (CNN) for sequential data representation where the decoder is weakened to encourage the utilization of latent variables for complex data modeling. This study presents a new variational and hierarchical latent variable model for sequence generation. Basically, sequential data is more complex than non-temporal data in learning representation. Using a simple latent variable model for VAE in sequence learning may be insufficient. Instead of the CNN implementation, we strengthen the capability of encoder in a sequence-to-sequence model based on a hierarchical latent variable model. This model consists of two encoders with two meaningful latent variables. The global and local dependencies of latent variables are discovered and involved in a sophisticated model for sequence generation. The long short-term memory (LSTM) and the pyramid bidirectional LSTM (pBLSTM) are merged as two encoders to capture complimentary features for decoding of sequential outputs. The issue of posterior collapse is accordingly alleviated by using this framework.
Traditionally, the sequence-to-sequence model encodes the input sequence with an RNN encoder and generates a variable-length output sequence with another RNN decoder. We present a self-attention model which further enhances the interaction between the inference model and generative model by incorporating the self-attention scheme as an interface between RNN-based encoder and decoder. However, developing an attention method under this setting is challenging because the encoder is disregarded in the generative process where we want to generate new samples from the latent space. In this thesis, we take the advantage of stochastic RNNs as the decoder which of additional latent variables allow us to model the context vector at each time step. The context vector is computed as the attention information which is the weighted sum of hidden states of the encoder during training. During test phase, we can sample from the prior of the decoder to reconstruct the context vector to compensate the missing of the attention information. In this way, such a framework can generate sequential data depending on latent variables of the encoder as well as decoder in inference time.
In the experiments, the proposed models are evaluated by using two popular natural language processing (NLP) datasets, Penn Treebank and Yelp 2013. Experimental results show that our models improve the performance in terms of perplexity for the generation and avoid the issue of the posterior collapse. In addition, the hierarchical model is able to learn different meaningful latent representations through the global and local dependencies of latent variables. As for the self-attention model, we visualize the attention weights to investigate how the attention mechanism works. We found that the self-attention model can retrieve useful information to help generation
Despite a great success in VAE, a crucial issue is the difficulty in learning the complicated latent variable structure especially in presence of a large-scale set of images or with the highly structured sequential data. Given the complicated natural images for training, VAE tends to generate the blurry images in prediction. On the other hand, VAE in sequence generation is composed of two recurrent neural networks (RNNs) for both the encoder and decoder. In general, the RNN decoder is trained by teacher forcing where the model receives the ground truth output as input at next time during training. However, this leads to an issue in training where a latent loss function as a Kullback-Leibler divergence vanishes so that the latent variables are not really used. This phenomenon is known as posterior collapse which also widely exists in stochastic RNN where additional latent variables are introduced to represent the hidden states of RNN.
To avoid the issue of posterior collapse, recently, RNN is implemented by a variant of convolutional neural network (CNN) for sequential data representation where the decoder is weakened to encourage the utilization of latent variables for complex data modeling. This study presents a new variational and hierarchical latent variable model for sequence generation. Basically, sequential data is more complex than non-temporal data in learning representation. Using a simple latent variable model for VAE in sequence learning may be insufficient. Instead of the CNN implementation, we strengthen the capability of encoder in a sequence-to-sequence model based on a hierarchical latent variable model. This model consists of two encoders with two meaningful latent variables. The global and local dependencies of latent variables are discovered and involved in a sophisticated model for sequence generation. The long short-term memory (LSTM) and the pyramid bidirectional LSTM (pBLSTM) are merged as two encoders to capture complimentary features for decoding of sequential outputs. The issue of posterior collapse is accordingly alleviated by using this framework.
Traditionally, the sequence-to-sequence model encodes the input sequence with an RNN encoder and generates a variable-length output sequence with another RNN decoder. We present a self-attention model which further enhances the interaction between the inference model and generative model by incorporating the self-attention scheme as an interface between RNN-based encoder and decoder. However, developing an attention method under this setting is challenging because the encoder is disregarded in the generative process where we want to generate new samples from the latent space. In this thesis, we take the advantage of stochastic RNNs as the decoder which of additional latent variables allow us to model the context vector at each time step. The context vector is computed as the attention information which is the weighted sum of hidden states of the encoder during training. During test phase, we can sample from the prior of the decoder to reconstruct the context vector to compensate the missing of the attention information. In this way, such a framework can generate sequential data depending on latent variables of the encoder as well as decoder in inference time.
In the experiments, the proposed models are evaluated by using two popular natural language processing (NLP) datasets, Penn Treebank and Yelp 2013. Experimental results show that our models improve the performance in terms of perplexity for the generation and avoid the issue of the posterior collapse. In addition, the hierarchical model is able to learn different meaningful latent representations through the global and local dependencies of latent variables. As for the self-attention model, we visualize the attention weights to investigate how the attention mechanism works. We found that the self-attention model can retrieve useful information to help generation