Try   HackMD

【論文】Dense Passage Retrieval for Open-Domain Question Answering 重點翻譯

tags: NLP 論文

HuggingFace Model Document

Abstract

開放領域QA需要有效率的文本抽取手段
Sparse vector space models : TF-IDF, BM25 (在QA表現不好)

  • TF-IDF :
    使用TF(詞頻)與IDF(逆向文件頻率)做綜合加權來判斷單詞對文件重要程度
  • BM-25:
    利用 1. query中每個單詞與文檔的相關性 2. 單詞與query之間的相似性 3. 每個單詞的權重 來計算query與目標文檔的相似度分數

在這篇論文中展示了使用dense vector的dual encoder架構在經過相對較少的訓練後,可以在open domain QA達到state of the art的水準。

Introduction

以往認為,dense vector的訓練需要花費較多資源,同時由於context encoder並沒有使用成對的問題與答案進行fine-tune,在表現上無法做到最好。

在這篇論文中,我們嘗試不做額外的預訓練,只使用成對的問題與文本作訓練。我們專注於使用相對較少的問題和段落對來開發正確的訓練方案。

ablation study: 通過比對不同方式對結果的貢獻來確定這個方案是否有效

Dense Passage Retriever (DPR)

在這個研究中,假設有大小為M的資料集,DPR的目標是改良open domain QA中的retrival單元,使其能夠在低維度且連續的空間中索引所有段落,以便提取top k的目標段落給reader。

要注意的是這邊的M很大(2100萬)而k通常很小(在20-100之間)。

Overview

DPR首先使用一個dense encoder將任意文章段落映射到一個d維的實數向量,並以此建立全部段落的索引。

執行時,DPR會使用另一個encoder將輸入的問題一樣映射到一個d維的向量。

將這兩個向量做內積,定義為段落與問題的相似度(similarity),目標就是提取相似度最高的k個段落。

儘管已經有許多知名的相似函數,但是經過我們的實驗比對發現,這些相似函數表現相當,因此決定使用最簡單的內積。

Encoder

Encoder的部分使用了兩個BERT(base, uncased)模型來建置,並使用 [CLS] token 的分類資訊作為輸出,因此 d=768 (CLS的預設長度)。

BERT種類簡介

Inference

在推測時,我們使用FAISS去讓passage encoder做索引。同時取得輸入問題的embedding,並取與問題embedding相似度最高的k個passage。

Training

訓練encoder的目標是讓相關的問題與段落mapping出來的vector有更小的距離(意即更高相似度)。

假設訓練集有m筆實例,每筆實例包括一個問題與一個相關的(positive)passage,還有n個不相關(negative)的passage。

Image Not Showing Possible Reasons
  • The image file may be corrupted
  • The server hosting the image is unavailable
  • The image path is incorrect
  • The image format is not supported
Learn More →

我們將Loss Function定義為positive passage的負似然函數(Negative Likelihood Funciton):

Image Not Showing Possible Reasons
  • The image file may be corrupted
  • The server hosting the image is unavailable
  • The image path is incorrect
  • The image format is not supported
Learn More →

负对数似然(negative log-likelihood)

Positive and negative passages

實作中,如何高效率的在passage pool中選出negative passages對於訓練出一個優秀的encoder非常重要。我們總共測試了三種方式:

  • 隨機挑選
  • BM25: 利用BM25挑選不包含答案的top passage
  • Gold: 挑選與其他問題配對的positive passage

經過我們的實驗,表現最好的model使用了相同mini-batch中的Gold passage和一個BM25 negative passage的組合。

特別是,重複使用同一個batch中的gold passage可以提高運算效率,同時實現出色的性能。

In-batch negatives

假設在mini-batch中有B個問題,將question矩陣(B x d)和passage矩陣(B x d)做內積後會得到B x B的相似分數矩陣。每個row代表一個問題,對應到B個passage的分數。每個batch總共有B個訓練實例,每個問題對應B-1個negative passage和1個positive passage。

In-batch negative是一種能有效訓練dual-encoder架構的策略。

Experimental Setup

  • Source Doc: 英文Wikipedia - 2020/12/20
    • 經過前處理後得到乾淨文本,以100字為一個大小建立passage做為基本提取單元
  • QA Dataset:
    • Natural Question (NQ)
    • TriviaQA
    • WebQuestion (WQ)
    • CuratedTREC (TREC)
    • SQuAD v1.1

Selection of positive passages

  • SQuAD / Natural Questions : 將Gold passage用passage pool中相應的段落取代。
  • TREC / WebQuestions / TriviaQA : 資料集只包含問題與相應答案,因此我們使用BM25在passage pool中提取最高分的段落做為positive passage,如果前100個提取出的段落沒有答案則捨棄該問題。

以下Train的資料數量前者為原始資料,後者為篩選過 :

Image Not Showing Possible Reasons
  • The image file may be corrupted
  • The server hosting the image is unavailable
  • The image path is incorrect
  • The image format is not supported
Learn More →

训练集、开发集、测试集(Train/Dev/Test sets)

Experiments: Passage Retrieval

主要實驗中,我們的DPR模型使用了in-batch negative設定做訓練,batch大小定為128,同時每個問題都額外加入了使用BM25挑選的negative passage。

在較大的資料集中(NQ, TriviaQA, SQuAD),question和passage的encoder訓練了40個epochs,而較小的資料集(TREC, WQ)則訓練了100個epochs。

超參數設定: Optimizer為Adam(learning rate:

105), 訓練使用linear scheduling,包含warm-up階段與dropout (rate 0.1)。

為了訓練出一個可以適應複數資料集的retriever,我們將除了SQuAD以外的所有資料集合併以訓練encoder。除此之外,我們也加入了傳統的BM25方法,我們將BM25和DPR提取出的前2000名passage做線性組合來驗證準確度。

Main Results

Image Not Showing Possible Reasons
  • The image file may be corrupted
  • The server hosting the image is unavailable
  • The image path is incorrect
  • The image format is not supported
Learn More →

Ablation Study on Model Training

Sample efficiency

Image Not Showing Possible Reasons
  • The image file may be corrupted
  • The server hosting the image is unavailable
  • The image path is incorrect
  • The image format is not supported
Learn More →

我們探究了需要多少訓練資料來達到較好的段落提取效果,上圖展示了不同訓練資料數量下top-k的提取準確度,使用Natural Question資料集與development set做驗證。

可以發現,僅僅使用了1000個訓練資料的DPR已經打敗了BM25,這代表一般的PLM也可以使用較少的Question-Passage pair訓練出高品質的DPR。
增加訓練資料數量也能有效提高提取的準確度。

In-batch negative training

Image Not Showing Possible Reasons
  • The image file may be corrupted
  • The server hosting the image is unavailable
  • The image path is incorrect
  • The image format is not supported
Learn More →

上表顯示了我們嘗試的各種in batch negative的訓練策略。第一個分區使用的是標準的1 of N訓練設定,batch中每個問題都會與一個positive passage和n個negative passage組成的set做配對。我們發現,不論使用哪種負採樣方式(BM25, random, Gold)都對k小於20的top-k準確度沒有太大的影響。

中間的分區使用了in-batch negative訓練設定。我們發現,使用相似的設定下(7個Gold negative passage),in-batch negative訓練明顯提高了正確率。其中關鍵的差異是negative passage來自同一個batch或是整個訓練資料集。實際上,in-batch negative training是個簡單且高效的方式,可以重複利用同個batch內的負樣本。同時它也產生更多的QP對,可能有助於提高模型性能。隨著batch size的增加,準確性也不斷提高。

最後,我們探究了in-batch negative加上額外BM25 hard negative passage的效果。這些段落在給定問題時有高BM25分數,但不包含答案的字串。我們將這些段落作為同個batch中所有問題的額外negative passage。我們發現,增加一個額外的這種passage可以大幅提升結果準確率,但增加第二個則不會有更多幫助。

Impact of gold passages

Image Not Showing Possible Reasons
  • The image file may be corrupted
  • The server hosting the image is unavailable
  • The image path is incorrect
  • The image format is not supported
Learn More →

我們使用原本資料集中符合gold contexts的段落做為正樣本。在Natural Questions的實驗中,我們發現若是將正樣本換成使用BM25挑選高分且包含答案的passage,top-k的準確率只會降低1點,影響不大

Similarity and loss

Image Not Showing Possible Reasons
  • The image file may be corrupted
  • The server hosting the image is unavailable
  • The image path is incorrect
  • The image format is not supported
Learn More →

經過我們的測試,L2歐氏距離表現與內積相當,而兩者的表現都優於餘弦。同樣的,除了負對數似然的損失函數之外,我們也測試了triplet loss,結果表明其對準確率影響不大。

Cross-dataset generalization

為了瞭解DPR在不同資料集上的通用性,我們只使用Natural Questions資料集做訓練,不經過任何微調直接在較小的WebQuestions和CuratedTREC資料集做測試。我們發現,DPR的表現相當不錯,相比於表現最好的微調模型僅有3到5點的準確率損失(69.9/86.3 vs. 75.0/89.1 for WebQuestions and TREC, respectively),同時仍然大大優於BM25(55.0/70.9)。

Qualitative Analysis

儘管 DPR 總體上比 BM25 表現更好,但這兩種方法檢索的段落在品質上存在差異。 像 BM25 這樣的術語匹配方法對高頻關鍵字和短語很敏感,而 DPR 可以更好地捕捉詞彙變化或語義關係。

Run-time Efficiency

我們需要提取單元的主要原因是為了減少reader單元需要考慮的候選段落數量,進而減少實時回答問題所需的時間。We profiled the passage retrieval speed on a server with Intel Xeon CPU E5-2698 v4 @ 2.20GHz and 512GB memory. With the help of FAISS in-memory index for real-valued vectors, DPR can be made incredibly efficient, processing 995.0 questions per second, returning top 100 passages per question. In contrast, BM25/Lucene (implemented in Java, using file index) processes 23.7 questions per second per CPU thread.

另一方面,訓練並索引dence vectors需要花費較多時間,不過可以輕鬆的平行化運算。

Experiments: Question Answering

End-to-end QA System

除了retriever之外,端對端的QA系統還包含了一個neural reader。retriever提取出k個passage,reader分別給予每個passage一個選擇分數。此外,reader會在passage中抽取answer span並給予span分數,其中分數最高的span會作為最終答案。

一段passage中每個token作為answer span的開頭與結尾的機率與該passage被選取的機率都會透過可訓練的權重vector做學習。

訓練時,我們利用提取系統(BM25 or DPR)採樣一個正面樣本與m - 1個負面樣本。m是可調超參數,這邊的實驗設定為24。訓練目標是要最大化正向樣本中正確答案的邊際概似,並與選出的正向樣本似然結果做合併。

在較大的資料集(NQ, TriviaQA, SQuAD)中,我們設定batch size為16,而在較小的資料集(TREC, WQ)中設定為4,並且在開發集中調整k(passage數量)的值。

Results

從結果來看,較高的提取準確度通常能讓最終的QA結果表現更好,而DPR的表現顯然好過BM25。

對於較大的資料集,使用多資料集進行訓練的模型表現與單資料集進行訓練的模型表現相似。相反的,對於較小的資料集,使用多資料集進行訓練的模型表現顯然更好。