文本增強技術

參考資料熵簡科技-李漁博士的報告《文本增強技術的研究進展及應用實踐》

背景

  • 本質上是增加少類樣本(數量少或者類型單一)的數量
  • 具體場景包括
    • 少樣本場景(如文本標註耗時耗力很難獲取很多)
    • 分類任務中樣本不均衡(note:常見方法-欠採樣 ( undersampling ) 和過採樣 ( oversampling ) 會對模型帶來怎樣的影響?)
    • 半監督訓練(19年google半監督學習算法 UDA 可以看出[6],文本數據增強技術可以用在無標籤樣本上,以構造出半監督訓練所需的樣本對,以此讓模型從無標籤的數據中獲取到優化所需的梯度)
    • 提高模型robustness

典型方法

  • 1)回譯(Back translation)

    • 舉例如下

      【原始文本爲】文本數據增強技術在自然語言處理中屬於基礎性技術;
      【翻譯爲日語】テキストデータ拡張技術は、自然言語処理の基本的な技術です;
      【日語再翻譯爲英語】Text data extension technology is a basic technology of natural language processing;
      【英語再翻譯回中文】文本數據擴展技術是自然語言處理的基本技術。

    • 細節
      • 使用google、有道等翻譯工具,可以通過更換中間語種實現N倍數據擴充;使用訓練的翻譯模型則可通過decode時的random sampling或者beam search等策略獲取擴充數據;
      • 長文本一般先切分並分別回譯,然後合併
    • google半監督學習算法(UDA)[6]
  • 2)EDA(Easy data augmentation)

    • 四種操作:同義詞替換、隨機插入、隨機交換和隨機刪除

      【同義詞替換(SR)】從句子中隨機選擇非停止詞。用隨機選擇的同義詞替換這些單詞;
      【隨機插入(RI)】隨機的找出句中某個不屬於停用詞集的詞,並求出其隨機的同義詞,將該同義詞插入句子的一個隨機位置。重複n次;
      【隨機交換(Random Swap, RS)】隨機的選擇句中兩個單詞並交換它們的位置。重複n次;
      【隨機刪除(RD)】以概率p隨機刪除句子中每個單詞。

    • 舉例如下

      【 原始文本】今天天氣很好。
      【同義詞替換(SR)】今天天氣不錯。(好 替換爲 不錯)
      【隨機插入(RI)】今天不錯天氣很好。(插入 不錯)
      【隨機交換(RS)】今天很好天氣。(很好 和 天氣交換位置)
      【隨機刪除(RD)】今天天氣好。(刪除 很)

    • 一個問題:經過EDA操作之後,文本的類別標籤 ( label ) 是否還能保持不變,畢竟這是對文本進行隨機操作?

      • 下圖可以說明 基本上能保持不變(將原有的測試集和拓展出的語料輸入到模型A中,並對模型在最後線性層的輸出進行了比較(t-SNE降維)
        在這裏插入圖片描述
    • 效果
      在這裏插入圖片描述

    • 如何設置替換比例和增強的文本倍數,原文給出的建議如下[11],其中,α是替換刪除等的比例,比如同義詞替換中,替換的單詞數n=α∗L,L是句子長度,隨機插入、隨機替換類似;Naug 是使用EDA方法從每一個句子拓展出的句子數量
      在這裏插入圖片描述

  • 3)EDA改進:非核心詞替換

    • 目的:避免替換掉重要的詞,用詞典中不重要的詞去替換文本中一定比例的不重要詞,從而產生新的文本
    • 方法:TFIDF衡量詞的重要性
    • UDA[6]提到的重要性具體實現方式如下:在這裏插入圖片描述
    • 效果在這裏插入圖片描述
  • 4)基於上下文信息的文本增強

    • 原理:首先需要一個訓練好的語言模型 ( LM ),對於需要增強的原始文本,隨機去掉文中的一個詞或字 ( 這取決於語言模型支持字還是詞 )。接下來,將文本的剩餘部分輸入語言模型,選擇語言模型所預測的 top k 個詞去替換原文中被去掉的詞,以形成 k 條新的文本。
    • 一種實現(日本Preferred Networks 公司在2018年提出的基於雙向LM的上下文文本增強技術[12]),添加極性信息保證文本標籤不變在這裏插入圖片描述
    • 另一種實現:finetune的BERT替換雙向LM,同樣引入原始文本的標籤信息,實驗結果如下:在這裏插入圖片描述
  • 5)基於語言生成模型的文本增強–LAMBADA(IBM201911 GPT-based[2])

    • 原理:LAMBADA 首先在大量文本上進行了預訓練,使模型能夠捕獲語言的結構,從而能產生連貫的句子。然後在不同任務的少量數據集上對模型進行微調,並使用微調後的模型生成新的句子(generator)。最後在相同的小型數據集上訓練分類器(discriminator),並進行過濾,保證現有的小型數據集和新生成數據集有相近的分佈。(類似GAN生成圖片)
    • 實驗結果:BERT/SVM/LSTM表示測試模型在這裏插入圖片描述
    • 分析:
      • 沒有和回譯作對比;
      • 對於 ATIS 數據集,相對 baseline 的性能提升超過了 50%,原論文中給出的說法是,ATIS 數據具有明顯的分佈不均衡性,而 LAMBADA 技術可以有效彌補原數據集的不均衡性
      • 改進:LAMBADA 技術後續還有很多可以挖掘的地方,比如與前面提到的 UDA 框架結合,用實現少樣本下的半監督學習。或者像論文原作者提到的那樣,未來他們將嘗試將此技術用於 zero-shot learning;
  • 6)其他方法:基於文本風格遷移的數據增強

    • 待續,可參考[19,20]

總結

  • 從機器學習的角度看待文本增強技術的有效性在這裏插入圖片描述

參考文獻

[1] Wei, Jason W., and Kai Zou. 「Eda: Easy data augmentation techniques for boosting performance on text classification tasks.」 arXiv preprint arXiv:1901.11196 (2019). [2] Anaby-Tavor, Ateret, et al. 「Not Enough Data? Deep Learning to the Rescue!.」 arXiv preprint arXiv:1911.03118 (2019). [3] Hu, Zhiting, et al. 「Learning Data Manipulation for Augmentation and Weighting.」 Advances in Neural Information Processing Systems. 2019. [4] Wang, William Yang, and Diyi Yang. 「That’s so annoying!!!: A lexical and frame-semantic embedding based data augmentation approach to automatic categorization of annoying behaviors using# petpeeve tweets.」 Proceedings of the 2015 Conference on Empirical Methods in Natural Language Processing. 2015. [5] Chawla, Nitesh V., et al. 「SMOTE: synthetic minority over-sampling technique.」 Journal of artificial intelligence research16 (2002): 321-357. [6] Xie, Qizhe, et al. 「Unsupervised data augmentation.」 arXiv preprint arXiv:1904.12848 (2019). [7] Goodfellow, Ian, Yoshua Bengio, and Aaron Courville. Deep learning. MIT press, 2016. [8] Sennrich, Rico, Barry Haddow, and Alexandra Birch. 「Improving neural machine translation models with monolingual data.」 arXiv preprint arXiv:1511.06709 (2015). [9] Edunov, Sergey, et al. 「Understanding back-translation at scale.」 arXiv preprint arXiv:1808.09381 (2018). [10] Yu, Adams Wei, et al. 「Qanet: Combining local convolution with global self-attention for reading comprehension.」 arXiv preprint arXiv:1804.09541 (2018). [11] Wei, Jason W., and Kai Zou. 「Eda: Easy data augmentation techniques for boosting performance on text classification tasks.」 arXiv preprint arXiv:1901.11196 (2019). [12] Kobayashi, Sosuke. 「Contextual augmentation: Data augmentation by words with paradigmatic relations.」 arXiv preprint arXiv:1805.06201 (2018). [13] Wu, Xing, et al. 「Conditional BERT contextual augmentation.」 International Conference on Computational Science. Springer, Cham, 2019. [14] Liu, Ting, et al. 「Generating and exploiting large-scale pseudo training data for zero pronoun resolution.」 arXiv preprint arXiv:1606.01603 (2016). [15] Hou, Yutai, et al. 「Sequence-to-sequence data augmentation for dialogue language understanding.」 arXiv preprint arXiv:1807.01554 (2018). [16] Dong, Li, et al. 「Learning to paraphrase for question answering.」 arXiv preprint arXiv:1708.06022 (2017). [17] Radford, Alec, et al. 「Improving language understanding by generative pre-training.」(2018). https://s3-us-west-2.amazonaws.com/openai-assets/research-covers/language-unsupervised/language_understanding_paper.pdf [18] Radford, Alec, et al. 「Language models are unsupervised multitask learners.」 OpenAI Blog 1.8 (2019): 9. [19] Hu, Zhiting, et al. 「Toward controlled generation of text.」 Proceedings of the 34th International Conference on Machine Learning-Volume 70. JMLR. org, 2017. [20] Guu, Kelvin, et al. 「Generating sentences by editing prototypes.」 Transactions of the Association for Computational Linguistics 6 (2018): 437-450.