SlowGuess/NAACL_2021_OCR huggingface dataset:
Tiancheng Zhao $^{1}$ , Xiaopeng Lu $^{2*}$  and Kyusong Lee $^{1}$   
SOCO Inc.
1{tianchez,kyusongl}@soco.ai
$^{2}$ xiaopen2@andrew.cmu.edu
We introduce SPARTA, a novel neural retrieval method that shows great promise in performance, generalization, and interpretability for open-domain question answering. Unlike many neural ranking methods that use dense vector nearest neighbor search, SPARTA learns a sparse representation that can be efficiently implemented as an Inverted Index. The resulting representation enables scalable neural retrieval that does not require expensive approximate vector search and leads to better performance than its dense counterpart. We validated our approaches on 4 open-domain question answering (OpenQA) tasks and 11 retrieval question answering (ReQA) tasks. SPARTA achieves new state-of-the-art results across a variety of open-domain question answering tasks in both English and Chinese datasets, including open SQuAD, CMRC and etc. Analysis also confirms that the proposed method creates human interpretable representation and allows flexible control over the trade-off between performance and efficiency.
Open-domain Question Answering (OpenQA) is the task of answering a question based on a knowledge source. One promising approach to solve OpenQA is Machine Reading at Scale (MRS) (Chen et al., 2017). MRS leverages an information retrieval (IR) system to narrow down to a list of relevant passages and then uses a machine reading comprehension reader to extract the final answer span. This approach, however, is bounded by its pipeline nature since the first stage retriever is not trainable and may return no passage that contains the correct answer.
To address this problem, prior work has focused on replacing the first stage retriever with a trainable ranker (Chidambaram et al., 2018; Lee et al., 2018; Wang et al., 2018). End-to-end systems
have also been proposed to combine passage retrieval and machine reading by directly retrieving answer span (Seo et al., 2019; Lee et al., 2019). Despite of their differences, the above approaches are all built on top of the dual-encoder architecture, where query and answer are encoded into fixed-size dense vectors, and their relevance score is computed via dot products. Approximate nearest neighbor (ANN) search is then used to enable real-time retrieval for large dataset (Shrivastava and Li, 2014).
In this paper, we argue that the dual-encoder structure is far from ideal for open-domain QA retrieval. Recent research shows its limitations and suggests the importance of modeling complex queries to answer interactions for strong QA performance. Seo et al. (2019) shows that their best performing system underperforms the state-of-the-art due to query-agnostic answer encoding and its over-simplified matching function. Humeau et al. (2019) shows the trade-off between performance and speed when moving from expressive crossattention in BERT (Devlin et al., 2018) to simple inner product interaction for dialog response retrieval. Therefore, our key research goal is to develop a method that can simultaneously achieve expressive query to answer interaction and fast inference for ranking.
We introduce SPARTA (Sparse Transformer Matching), a novel neural ranking model. Unlike existing work that relies on a sequence-level inner product, SPARTA uses token-level interaction between every query and answer token pair, leading to superior retrieval performance. Concretely, SPARTA learns sparse answer representations that model the potential interaction between every query term with the answer. The learned sparse answer representation can be efficiently saved in an Inverted Index, e.g., Lucene (McCandless et al., 2010), so that one can query a SPARTA index with almost the same speed as a standard search engine
* This work was done during an internship at SOCO
Proceedings of the 2021 Conference of the North American Chapter of the Association for Computational Linguistics: Human Language Technologies, pages 565-575 June 6-11, 2021. ©2021 Association for Computational Linguistics
and enjoy the more reliable ranking performance without depending on GPU or ANN search.
Experiments are conducted on two settings: OpenQA (Chen et al., 2017) that requires phrase-level answers and retrieval QA (ReQA) that requires sentence-level answers (Ahmad et al., 2019). Our proposed SpartaQA system achieves new state-of-the-art results across 15 different domains and 2 languages with significant performance gain, including OpenSQuAD, OpenCMRC and etc.
Moreover, model analysis shows that SPARTA exhibits several desirable properties. First SPARTA shows strong domain generalization ability and achieves the best performance compared to both classic IR method and other learning methods in low-resources domains. Second, SPARTA is simple and efficient and achieves better performance than many more sophisticated methods. Lastly, it provides a human-readable representation that is easy to interpret. In short, the contributions of this work include:
- A novel ranking model SPARTA that offers token-level query-to-answer interaction and enables efficient large-scale ranking.
- New state-of-the-art experiment results on 11 ReQA tasks and 4 OpenQA tasks in 2 languages.
- Detailed analyses that reveal insights about the proposed methods, including generalization and computation efficiency.
The classical approach for OpenQA depends on knowledge bases (KB)s that are manually or automatically curated, e.g., Freebase KB (Bollacker et al., 2008), NELL (Fader et al., 2014) etc. Semantic parsing is used to understand the query and computes the final answer (Berant et al., 2013; Berant and Liang, 2014). However, KB-based systems are often limited due to incompleteness in the KB and inflexibility to changes in schema (Ferrucci et al., 2010).
A more recent approach is to use text data directly as a knowledge base. Dr.QA uses a search engine to filter to relevant documents and then applies machine readers to extract the final answer (Chen et al., 2017). It needs two stages because all existing machine readers, for example, BERT-based models (Devlin et al., 2018), are prohibitively slow
(BERT only processes a few thousands of words per second with GPU acceleration). Many attempts have been made to improve the first-stage retrieval performance (Chidambaram et al., 2018; Seo et al., 2019; Henderson et al., 2019; Karpukhin et al., 2020; Chang et al., 2020). The information retrieval community has shown that word embedding matching do not perform well for ad-hoc document search compared to classic methods (Guo et al., 2016; Xiong et al., 2017; Hui et al., 2017).
To increase the expressiveness of dual encoders, Xiong et al. (2017) develops kernel function to learn soft matching score at token-level instead of sequence-level. Humeau et al. (2019) proposes Poly-Encoders to enable more complex interactions between the query and the answer by letting one encoder output multiple vectors instead of one vector. Dhingra et al. (2020) incorporates entity vectors and multi-hop reasoning to teach systems to answer more complex questions. (Lee et al., 2020) augments the dense answer representation with learned n-gram sparse feature from contextualized word embeddings, achieving significant improvement compared to the dense-only baseline. Chang et al. (2020) explores various unsupervised pretraining objectives to improve dual-encoders' QA performance in the low-resources setting.
Unlike existing work based-on dual-encoders, we focus on learning sparse representation and emphasizing token-level interaction. This is perhaps the most related to the sparse index from DenSPI (Lee et al., 2020) and DeepCT (Dai and Callan, 2020). Our approach is different because our proposed model is architecturally simpler and is generative so that it will understand words that not appear in the answer document, whereas the one developed at (Lee et al., 2020) only models n-grams appear in the document. MacAvaney et al. (2020) also explores retrieval with sparse representations. Our work is different from theirs in that we decide not to model the query order information, which enables the model to do full ranking. Section 3.4 shows that our system can be easily deployed via inverted index under modern search engines, such as Lucene (McCandless et al., 2010).
First, we formally define the problem of answer ranking for question answering. Let  $q$  be the input question, and  $A = \{(a,c)\}$  be a set of candidate
(a) Rank score between answer and query via SPARTA
(b) SPARTA Inverted Index
Figure 1: SPARTA Neural Ranker computes token-level matching score via dot product. Each query terms' contribution is first obtained via max-pooling and then pass through ReLU and log. The final score is the summation of each query term contribution.
answers. Each candidate answer is a tuple  $(a, c)$  where  $a$  is the answer text and  $c$  is context information about  $a$ . The objective is to find model parameter  $\theta$  that rank the correct answer as high as possible, i.e:
$$
\theta = \underset {\theta \in \Theta} {\operatorname {a r g m a x}} \mathbb {E} \left[ p _ {\theta} \left(\left(a ^ {*}, c ^ {*}\right) | q\right) \right] \tag {1}
$$
This formulation is general and can cover many tasks. For example, typical passage-level retrieval systems sets the  $a$  to be the passage and leaves  $c$  empty (Chen et al., 2017; Yang et al., 2019a). The sentence-level retrieval task proposed at sets  $a$  to be each sentence in a text knowledge base and  $c$  to be the surrounding text (Ahmad et al., 2019). Lastly, the phrase-level QA system sets  $a$  to be all valid phrases from a corpus and  $c$  to be the surrounding text (Seo et al., 2019). This work focuses on the same sentence-level retrieval task (Ahmad et al., 2019) since it provides a good balance between precision and memory footprint. Yet note that our methods can be easily applied to the other two settings.
3.2 SPARTA Neural Ranker
In order to achieve both high accuracy and efficiency (scale to millions of candidate answers with real-time response), the proposed SPARTA index is built on top of two high-level intuitions.
- Accuracy: retrieve answer with expressive embedding interaction between the query and answer, i.e., token-level contextual interaction.
- Efficiency: create query agnostic answer representation so that they can be pre-computed at indexing time. Since it is an offline operation, we can use the most powerful model for
indexing and simplify the computation needed at inference.
As shown in Figure 1, a query is represented as a sequence of tokens  $q = [t_1, \dots, t_{|q|}]$  and each answer is also a sequence of tokens  $(a, c) = [c_1, \dots, c_1, \dots, c_{|a|}, c_{a+1}, \dots, c_{|c|}]$ . We use a non-contextualized embedding to encode the query tokens to  $e_i$ , and a contextualized transformer model to encode the answer and obtain contextualized token-level embedding  $s_j$ :
$$
\mathcal {E} (q) = \left[ e _ {1}, \dots e _ {| q |} \right] \quad \text {Q u e r y E m b e d d i n g} \tag {2}
$$
$$
\mathcal {H} (a, c) = \left[ s _ {1}, \dots s _ {| c |} \right] \quad \text {A n s w e r E m b e d d i n g} \tag {3}
$$
Then the matching score  $f$  between a query and an answer is computed by:
$$
y _ {i} = \max  _ {j \in [ 1, | c | ]} \left(e _ {i} ^ {T} s _ {j}\right) \quad \text {T e r m M a t c h i n g}
$$
$$
\phi \left(y _ {i}\right) = \operatorname {R e L U} \left(y _ {i} + b\right) \quad \text {S p a r s e F e a t u r e} \tag {5}
$$
$$
f (q, (a, c)) = \sum_ {i = 0} ^ {| q |} \log \left(\phi \left(y _ {i}\right) + 1\right) \quad \text {F i n a l S c o r e} \tag {6}
$$
where  $b$  is a trainable bias. The final score between the query and answer is the summation of all individual scores between each query token and the answer. The logarithm operations normalize each individual score and weaken the overwhelmingly large term score. Additionally, there are two key design choices worth of elaboration.
Token-level Interaction SPARTA scoring uses token-level interaction between the query and the answer. Motivated by bidirectional-attention
flow (Seo et al., 2016), relevance between every query and answer token pair is computed via dot product and max pooling in Eq. 4. Whereas in a typical dual-encoder approach, only sequence-level interaction is computed via dot product. Results in our experiment section show that fine-grained interaction is crucial to obtain significant accuracy improvement. Additionally,  $s_j$  is obtained from powerful bidirectional transformer encoders, e.g. BERT and only needs to be computed at the indexing time. On the other hand, the query embedding is non-contextual, a trade-off needed to enable real-time inference, which is explained in Section 3.4
Sparsity Control Another key feature to enable efficient inference and memory foot print is sparsity. This is achieved via the combination of log, ReLU and  $b$  in Eq. 5. The bias term is used as a threshold for  $y_{i}$ . The ReLU layer forces that only query terms with  $y_{i} > 0$  have impact to the final score, achieving sparse activation. The log operation is proven to be useful via experiments for regularizing individual term scores and leads to better performance and more generalized representation.
Implementation In terms of implementation, we use a pretrained 12-layer, 768 hidden size bert-base-uncased as the answer encoder to encode the answer and their context (Devlin et al., 2018). To encode the difference between the answer sequence and its surrounding context, we utilized the segment embedding from BERT, i.e. the answer tokens have segment_id = 1 and the context tokens have segment_id = 0. Moreover, the query tokens are embedded via the word embedding from the bert-base-uncased with dimension 768.
3.3 Learning to Rank
The training of SPARTA uses cross entropy learning-to-rank loss and maximizes Eq. 7. The objective tries to distinguish between the true relevant answer  $(a^{+}, c^{+})$  and irrelevant/random answers  $K^{-}$  for each training query  $q$ :
$$
J = f (q, \left(a ^ {+}, c ^ {+}\right)) - \log \sum_ {k \in K ^ {-}} e ^ {f \left(q, \left(a _ {k}, c _ {k}\right)\right)} \tag {7}
$$
The choice of negative samples  $K^{-}$  are crucial for effective learning. Our study uses two types of negative samples: 50% of the negative samples are randomly chosen from the entire answer candidate set, and the rest 50% are chosen from sentences that are nearby to the ground truth answer  $a$ . The second case requires the model to learn the fine-grained
difference between each sentence candidate instead of only rely on the context information. The parameters to learn include both the query encoder  $\mathcal{E}$  and the answer encoder  $\mathcal{H}$ . Parameters are optimized using back propagation (BP) through the neural network.
3.4 Indexing and Inference
One major novelty of SPARTA is how one can use it for real-time inference. That is for a testing query  $q = [t_0, \dots, t_{|q|}]$ , the ranking score between  $q$  and an answer is:
$$
\operatorname {L O O K U P} (t, (a, c)) = \log (\text {E q .} 5) \quad t \in V \tag {8}
$$
$$
f (q, (a, c)) = \sum_ {i = 1} ^ {| q |} \operatorname {L O O K U P} \left(t _ {i}, (a, c)\right) \tag {9}
$$
Since the query term embedding is non-contextual, we can compute the rank feature  $\phi(t, (a, c))$  for every possible term  $t$  in the vocabulary  $V$  with every answer candidate. The result score is cached in the indexing time as shown in Eq. 8. At inference time, the final ranking score can be computed via O(1) look up plus a simple summation as shown in Eq. 9.
More importantly, the above computation can be efficiently implemented via a Inverted Index (Manning et al., 2008), which is the underlying data structure for modern search engines, e.g. Lucene (McCandless et al., 2010) as shown in Figure 1(b). This property makes it easy to apply SPARTA to real-world applications.
3.5 Relation to Classic IR and Generative Models
It is not hard to see the relationship between SPARTA and classic BM25 based methods. In the classic IR method, only the tokens that appeared in the answer are saved to the Inverted Index. Each term's score is a combination of Term Frequency and Inverted Document Frequency via heuristics (Manning et al., 2008). On the other hand, SPARTA learns which term in the vocabulary should be inserted into the index, and predicts the ranking score directly rather than heuristic calculation. This enables the system to find relevant answers, even when none of the query words appeared in the answer text. For example, if the answer sentence is "Bill Gates founded Microsoft", a SPARTA index will not only contain the tokens in the answer, but also include relevant terms, e.g. who, founder, entrepreneur and etc.
SPARTA is also related to generative QA. The scoring between  $(a, c)$  and every word in the vocabulary  $V$  can be understood as the un-normalized probability of  $\log p(q|a) = \sum_{i}^{|q|}\log p(t_{i}|a)$  with term independence assumption. Past work such as Lewis and Fan (2018); Nogueira et al. (2019) trains a question generator to score the answer via likelihood. However, both approaches focus on auto-regressive models and the quality of question generation and do not provide an end-to-end solution that enables stand-alone answer retrieval.
4 OpenQA Experiments
We consider an Open-domain Question Answering (OpenQA) task to evaluate the performance of SPARTA ranker. Following previous work on OpenQA (Chen et al., 2017; Wang et al., 2019; Xie et al., 2020), we experiment with two English datasets: SQuAD (Rajpurkar et al., 2016), Natural Questions (NQ) (Kwiatkowski et al., 2019); and two Chinese datasets: CMRC (Cui et al., 2018), DRCD (Shao et al., 2018). For each dataset, we used the version of Wikipedia where the data was collected from. Preliminary results show that it is crucial to use the right version of Wikipedia to reproduce the results from baselines. We compare the results with previous best models.
System-wise we follow the 2-stage ranker-reader structure used in (Chen et al., 2017).
Ranker: We split all documents into sentences. Each sentence is treated as a candidate answer  $a$ . We keep the surrounding context words of each candidate answer as its context  $c$ . We encode at most 512 word piece tokens and truncate the context surrounding the answer sentence with equal window size. For model training, bert-base-uncased is used as the answer encoder for English, and chinesebert-wwm is used for Chinese. We reuse the word embedding from corresponding BERT model as the term embedding. Adam (Kingma and Ba, 2014) is used as the optimizer for fine-tuning with a learning rate 3e-5. The model is fine-tuned for at most 10K steps and the best model is picked based on validation performance.
Reader: We deploy a machine reading comprehension (MRC) reader to extract phrase-level answers from the top-K retrieved contexts. For English tasks, we fine-tune on span-bert (Joshi et al., 2020). For Chinese tasks, we fine-tune on chinesebert-wwm (Cui et al., 2020). Two additional proven techniques are used to improve performance. First,
we use global normalization (Clark and Gardner, 2017) to normalize span scores among multiple passages and make them comparable among each other. Second, distant supervision is used. Concretely, we first use the ranker to find top-10 passages for all training data from Wikipedia corpus. Then every mention of the oracle answers in these contexts are treated as training examples. This can ensure the MRC reader to adapt to the ranker and make the training distribution closer to the test distribution (Xie et al., 2020).
Lastly, evaluation metrics include the standard MRC metric: EM and F1-score.
- Exact Match (EM): if the top-1 answer span matches with the ground truth exactly.
- F1 Score: we compute word overlapping between the returned span and the ground truth answer at token level.
4.1 OpenQA Results
OpenSQuAD
Model	F1	EM
Dr.QA(Chen et al., 2017)	-	29.8
R3(Wang et al., 2018)	37.5	29.1
Par. ranker (Lee et al., 2018)	-	30.2
MINIMAL (Min et al., 2018)	42.5	32.7
DenSPI-hybrid (Seo et al., 2019)	44.4	36.2
BERTserini (Yang et al., 2019a)	46.1	38.6
RE3(Hu et al., 2019)	50.2	41.9
Multi-passage (Wang et al., 2019)	60.9	53.0
Graph-retriever (Asai et al., 2019)	63.8	56.5
SPARTA	66.5	59.3
OpenNQ	EM
Model	Dev	Test
BERT + BM25 (Lee et al., 2018)	24.8	26.5
Hard EM (Min et al., 2019)	28.8	28.1
ORQA(Lee et al., 2019)	31.3	33.3
Graph-retriever (Asai et al., 2019)	31.7	32.6
DPR (Karpukhin et al., 2020)	41.5	-
DAG (Lewis et al., 2020)	44.5	-
SPARTA	36.8	37.5
Table 1: Results on English Open SQuAD and NQ
Table 1 and 2 shows the SPARTA performance in OpenQA settings, tested in both English and Chinese datasets. Experimental results show that SPARTA retriever outperforms all existing models and obtains new state-of-the-art results on all four datasets. For OpenSQuAD and OpenNQ, SPARTA
OpenCMRC
Model	F1	EM
BERTserini(Xie et al., 2020)	60.9	44.5
BERTserini+DS (Xie et al., 2020)	64.6	48.6
SPARTA	80.2	63.1
OpenDRCD
Model	F1	EM
BERTserini (Xie et al., 2020)	65.0	50.7
BERTserini+DS (Xie et al., 2020)	67.7	55.4
SPARTA	74.6	63.1
outperforms the previous best system (Asai et al., 2019) by 2.7 absolute F1 points and 5.1 absolute EM points respectively. For OpenCMRC and OpenDRCD, SPARTA achieves a 15.3 and 6.7 absolute F1 points improvement over the previous best system (Xie et al., 2020).
Notably, the previous best system on OpenSQuAD and OpenNQ depends on sophisticated graph reasoning (Asai et al., 2019), whereas the proposed SPARTA system only uses single-hop ranker and require much less computation power. This suggests that for tasks that requires only single-hop reasoning, there is still big improvement room for better ranker-reader QA systems.
5 Retrieval QA Experiments
We also consider Retrieval QA (ReQA), a sentence-level question answering task (Ahmad et al., 2019). The candidate answer set contains every possible sentence from a text corpus and the system is expected to return a ranking of sentences given a query. The original ReQA only contains SQuAD and NQ. In this study, we extend ReQA to 11 different domains adapted from (Fisch et al., 2019) to evaluate both in-domain performance and out-of-domain generalization. The details of the 11 ReQA domains are in Table 3 and Appendix.
The in-domain scenarios look at domains that have enough training data (see Table 3). The models are trained on the training data and the evaluation is done on the test data. On the other hand, the out-of-domain scenarios evaluate systems' performance on test data from domains not included in the training, making it a zero-shot learning problem. There are two out-of-domain settings: (1) training data only contain SQuAD (2) training data contain only SQuAD and NQ. Evaluation is carried on all the domains to test systems' ability to generalize
to unseen data distribution.
Table 2: Results on Chinese Open CMRC and DRCD
Domain	Data Source
Has training data
SQuAD (Rajpurkar et al., 2016)	Wikipedia
News (Trischler et al., 2016)	News
Trivia (Joshi et al., 2017)	Web
NQ (Kwiatkowski et al., 2019)	Google Search
Hotpot (Yang et al., 2018)	Wikipedia
Has no training data
BioASQ (Tsatsaronis et al., 2015)	PubMed Documents
DROP (Dua et al., 2019)	Wikipedia
DuoRC (Saha et al., 2018)	Wikipedia+IMDB
RACE (Lai et al., 2017)	English Exam
RE (Levy et al., 2017)	Wikipedia
Textbook (Kembhavi et al., 2017)	K12 Textbook
Table 3: 11 corpora included in MultiReQA and their document sources. The top 5 domains contain training data and the bottom 6 domains only have test sets.
For evaluation metrics, we use Mean Reciprocal Rank (MRR) as the criteria. The competing baselines include:
BM25: a strong classic IR baseline that is difficult to beat (Robertson et al., 2009).
USE-QA<sup>1</sup>: universal sentence encoder trained for QA task by Google (Yang et al., 2019b). USEQA uses the dual-encoder architecture and it is trained on more than 900 million mined question-answer pairs with 16 different languages.
Poly-Encoder (Poly-Enc): Poly Encoders improves the expressiveness of dual-encoders with two-level interaction (Humeau et al., 2019). We adapted the original dialog model for QA retrieval: two bert-base-uncased models are used as the question and answer encoders. The answer encoder has 4 vector outputs.