又是一篇很久之前用到的模型,今天回來整理,發現分類的模型都好簡單啊,然後看到模型基於GRU,總覺得有點不想看,因爲帶時間序列的訓練起來太慢了,最進沒怎麼關注分類的新模型,不過我覺得CNN和transformer結構(self attention)的搭配應該是分類問題的趨勢,不過這篇文章後面的attention效果可視化還是不錯的~
文章目錄
該模型就是基於分類問題提出來的,所以背景什麼的也就不說了,很簡單,直接切入模型正題。
博主標記版論文地址
1.模型概述
對於一個document含有這樣的層次結構,document由sentences組成,sentence由words組成。words和sentences都是高度上下文依賴的,同一個詞或sentence在不同的上下文中,其表現的重要性會有差別。因此,這篇論文中使用了兩個attention機制,來表示結合了上下文信息的詞或句子的重要程度。(這裏結合的上下文的詞或句子,就是經過RNN處理後的隱藏狀態)。
層級“注意力”網絡的網絡結構如圖1所示,網絡可以被看作爲兩部分,第一部分爲詞“注意”部分,另一部分爲句“注意”部分。整個網絡通過將一個句子分割爲幾部分(例如可以用“,”講一句話分爲幾個小句子),對於每部分,都使用雙向RNN結合“注意力”機制將小句子映射爲一個向量,然後對於映射得到的一組序列向量,我們再通過一層雙向RNN結合“注意力”機制實現對文本的分類。
2.模型詳情
論文裏面竟然用了不小的篇幅在說gru,瞬間就覺得有灌水的嫌疑,不過這也不像cmu的作風啊,可能早期文章還是比較偏底層,比較簡單吧~
這裏關於gru在我早期的文章裏面有提及過,這裏就不說了
2.1.Word Encoder
其中:
- sentence in the document, and means the tth word in the sentence.
- 這裏的應該表達的就是word lookup的過程,paper中說的不清楚,但是在所有我看到的實現裏面都是直接lookup
2.2.Word Attention layer
Not all words contribute equally to the representation of the sentence meaning. Hence, we introduce attention mechanism to extract such words that are important to the meaning of the sentence and aggregate the representation of those informative words to form a sentence vector.
Attention機制說到底就是給予sentence中每個結合了上下文信息的詞一個權重。關鍵在於這個權重怎麼確定?
這裏首先是將 通過**一個全連接層得到 hidden representation ,然後計算 與 的相似性。**並通過softmax歸一化得到每個詞與 相似的概率。越相似的話,這個詞所佔比重越大,對整個sentence的向量表示影響越大。
這裏我覺得這裏的attention就是“self attention”,只不過沒有transformer正式提出來,也沒有那個複雜,沒有那個正式,不過總還是有self attention的影子。
2.3.Sentence Encoder
summarizes the neighbor sentences around sentence i but still focus on sentence i.
2.4.Sentence Attention
同樣的 表示: a sentence level context vector
2.5.Document Classification
The document vector v is a high level representation of the document and can be used as features for document classification:
2.6.延伸閱讀
在查相關資料的時候發現了這個,以後再研究吧~
Multilingual Hierarchical Attention Networks for Document Classification
2.7.源碼
一份比較簡潔的代碼:tf-hierarchical-rnn