SlowGuess/NAACL_2021_OCR huggingface dataset:
Luyu Gao, Zhuyun Dai, Jamie Callan
{luyug, zhuyund, callan}@cs.cmu.edu
Classical information retrieval systems such as BM25 rely on exact lexical match and carry out search efficiently with inverted list index. Recent neural IR models shifts towards soft semantic matching all query document terms, but they lose the computation efficiency of exact match systems. This paper presents COIL, a contextualized exact match retrieval architecture that brings semantic lexical matching. COIL scoring is based on overlapping query document tokens' contextualized representations. The new architecture stores contextualized token representations in inverted lists, bringing together the efficiency of exact match and the representation power of deep language models. Our experimental results show COIL outperforms classical lexical retrievers and state-of-the-art deep LM retrievers with similar or smaller latency. $^1$
Widely used, bag-of-words (BOW) information retrieval (IR) systems such as BM25 rely on exact lexical match  ${}^{2}$  between query and document terms. Recent study in neural IR takes a different approach and compute soft matching between all query and document terms to model complex matching.
The shift to soft matching in neural IR models attempts to address vocabulary mismatch problems, that query and the relevant documents use different terms, e.g. cat v.s. kitty, for the same concept (Huang et al., 2013; Guo et al., 2016; Xiong et al., 2017). Later introduction of contextualized representations (Peters et al., 2018) from deep language models (LM) further address semantic mismatch, that the same term can refer to different concepts, e.g., bank of river vs. bank in finance. Fine-tuned deep LM rerankers produce token representations based on context and achieve state-of
the-art in text ranking with huge performance leap (Nogueira and Cho, 2019; Dai and Callan, 2019b).
Though the idea of soft matching all tokens is carried through the development of neural IR models, seeing the success brought by deep LMs, we take a step back and ask: how much gain can we get if we introduce contextualized representations back to lexical exact match systems? In other words, can we build a system that still performs exact query-document token matching but compute matching signals with contextualized token representations instead of heuristics? This may seem a constraint on the model, but exact lexical match produce more explainable and controlled patterns than soft matching. It also allows search to focus on only the subset of documents that have overlapping terms with query, which can be done efficiently with inverted list index. Meanwhile, using dense contextualized token representations enables the model to handle semantic mismatch, which has been a long-standing problem in classic lexical systems.
To answer the question, we propose a new lexical matching scheme that uses vector similarities between query-document overlapping term contextualized representations to replace heuristic scoring used in classical systems. We present CoContextualized Inverted List (COIL), a new exact lexical match retrieval architecture armed with deep LM representations. COIL processes documents with deep LM offline and produces representations for each document token. The representations are grouped by their surface tokens into inverted lists. At search time, we build representation vectors for query tokens and perform contextualized exact match: use each query token to look up its own inverted list and compute vector similarity with document vectors stored in the inverted list as matching scores. COIL enables efficient search with rich-in-semantic matching between query and document.
Our contributions include 1) introduce a novel
1Our code is available at https://github.com/ luyug/COIL.
$^{2}$ Exact match up to morphological changes.
Proceedings of the 2021 Conference of the North American Chapter of the Association for Computational Linguistics: Human Language Technologies, pages 3030-3042 June 6-11, 2021. ©2021 Association for Computational Linguistics
retrieval architecture, contextualized inverted lists (COIL) that brings semantic matching into lexical IR systems, 2) show matching signals induced from exact lexical match can capture complicated matching patterns, 3) demonstrate COIL significantly outperform classical and deep LM augmented lexical retrievers as well as state-of-the-art dense retrievers on two retrieval tasks.
Lexical Retriever Classical IR systems rely on exact lexical match retrievers such as Boolean Retrieval, BM25 (Robertson and Walker, 1994) and statistical language models (Lafferty and Zhai, 2001). This type of retrieval model can process queries very quickly by organizing the documents into inverted index, where each distinct term has an inverted list that stores information about documents it appears in. Nowadays, they are still widely used in production systems. However, these retrieval models fall short of matching related terms (vocabulary mismatch) or modeling context of the terms (semantic mismatch). Much early effort was put into improving exact lexical match retrievers, such as matching n-grams (Metzler and Croft, 2005) or expanding queries with terms from related documents (Lavrenko and Croft, 2001). However, these methods still use BOW framework and have limited capability of modeling human languages.
Neural Ranker In order to deal with vocabulary mismatch, neural retrievers that rely on soft matching between numerical text representations are introduced. Early attempts compute similarity between pre-trained word embedding such as word2vec (Mikolov et al., 2013) and GLoVe (Pennington et al., 2014) to produce matching score (Ganguly et al., 2015; Diaz et al., 2016). One more recent approach encodes query and document each into a vector and computes vector similarity (Huang et al., 2013). Later researches realized the limited capacity of a single vector to encode fine-grained information and introduced full interaction models to perform soft matching between all term vectors (Guo et al., 2016; Xiong et al., 2017). In these approaches, scoring is based on learned neural networks and the hugely increased computation cost limited their use to reranking a top candidate list generated by a lexical retriever.
Deep LM Based Ranker and Retriever Deep LM made a huge impact on neural IR. Finetuned Transformer (Vaswani et al., 2017) LM BERT (Devlin et al., 2019) achieved state-of-the-art reranking performance for passages and documents (Nogueira and Cho, 2019; Dai and Callan, 2019b). As illustrated in Figure 1a, the common approach is to feed the concatenated query document text through BERT and use BERT's [CLS] output token to produce a relevance score. The deep LM rerankers addressed both vocabulary and semantic mismatch by computing full cross attention between contextualized token representations. Lighter deep LM rankers are developed (MacAvaney et al., 2020; Gao et al., 2020), but their cross attention operations are still too expensive for full-collection retrieval.
Later research therefore resorted to augmenting lexical retrieval with deep LMs by expanding the document surface form to narrow the vocabulary gap, e.g., DocT5Query (Nogueira and Lin, 2019), or altering term weights to emphasize important terms, e.g., DeepCT (Dai and Callan, 2019a). Smartly combining deep LM retriever and reranker can offer additive gain for end performance (Gao et al., 2021a). These retrievers however still suffer from vocabulary and semantic mismatch as traditional lexical retrievers.
Another line of research continues the work on single vector representation and build dense retrievers, as illustrated in Figure 1b. They store document vectors in a dense index and retrieve them through Nearest Neighbours search. Using deep LMs, dense retrievers have achieved promising results on several retrieval tasks (Karpukhin et al., 2020). Later researches show that dense retrieval systems can be further improved by better training (Xiong et al., 2020; Gao et al., 2021b).
Single vector systems have also been extended to multi-vector representation systems. Polyencoder (Humeau et al., 2020) encodes queries into a set of vectors. Similarly, Me-BERT (Luan et al., 2020) represents documents with a set of vectors. A concurrent work ColBERT (Figure 1c) use multiple vectors to encode both queries and documents (Khattab and Zaharia, 2020). In particular, it represents a document with all its terms' vectors and a query with an expanded set of term vectors. It then computes all-to-all (Cartesian) soft match between the tokens. ColBERT performs interaction as dot product followed pooling operations, which
(a) Cross-Attention Model (e.g., BERT reranker)
(c) ColBERT: All-to-All Match
(b) Dense Retrievers (e.g., DPR)
(d) COIL: Contextualized Exact Match
Figure 1: An illustration of reranking/retrieval mechanisms with deep LM, including our proposed model, COIL.
Figure 2: An illustration of traditional inverted lists. The inverted list maps a term to the list of documents where the term occurs. Retriever looks up query terms' inverted lists and scores those documents with stored statistics such as term frequency (tf).
allows it to also leverage a dense index to do full corpus retrieval. However, since ColBERT encodes a document with all tokens, it adds another order of magnitude of index complexity to all aforementioned methods: document tokens in the collection need to be stored in a single huge index and considered at query time. Consequently, ColBERT is engineering and hardware demanding.
In this section, we first provide some preliminaries on exact lexical match systems. Then we discuss COIL's contextualized exact match design and how its search index is organized. We also give a comparison between COIL and other popular retrievers.
Figure 3: COIL's index and retrieval architecture. COIL-tok relies on the exact token matching (lower). COIL-full includes in addition CLS matching (upper).
Classic lexical retrieval system relies on overlapping query document terms under morphological generalization like stemming, in other words, exact lexical match, to score query document pair. A scoring function is defined as a sum of matched term scores. The scores are usually based on statistics like term frequency (tf). Generally, we can write,
$$
s = \sum_ {t \in q \cap d} \sigma_ {t} \left(h _ {q} (q, t), h _ {d} (d, t)\right) \tag {1}
$$
where for each overlapping term  $t$  between query  $q$  and document  $d$ , functions  $h_q$  and  $h_d$  extract term
information and a term scoring function  $\sigma_t$  combines them. A popular example is BM25, which computes,
$$
s _ {\mathrm {B M} 2 5} = \sum_ {t \in q \cap d} i d f (t) h _ {q} ^ {\mathrm {B M} 2 5} (q, t) h _ {d} ^ {\mathrm {B M} 2 5} (d, t)
$$
$$
h _ {q} ^ {\mathrm {B M 2 5}} (q, t) = \frac {t f _ {t , q} \left(1 + k _ {2}\right)}{t f _ {t , q} + k _ {2}} \tag {2}
$$
$$
h _ {d} ^ {\mathrm {B M 2 5}} (d, t) = \frac {t f _ {t , d} (1 + k _ {1})}{t f _ {t , d} + k _ {1} (1 - b + b \frac {| d |}{\mathrm {a v g d l}})}
$$
where  $t f_{t,d}$  refers to term frequency of term  $t$  in document  $d$ ,  $t f_{t,q}$  refers to the term frequency in query,  $idf(t)$  is inverse document frequency, and  $b$ ,  $k_1$ ,  $k_2$  are hyper-parameters.
One key advantage of exact lexical match systems lies in efficiency. With summation over exact matches, scoring of each query term only goes to documents that contain matching terms. This can be done efficiently using inverted list indexing (Figure 2). The inverted list maps back from a term to a list of documents where the term occurs. To compute Equation 1, the retriever only needs to traverse the subset of documents in query terms' inverted lists instead of going over the entire document collection.
While recent neural IR research mainly focuses on breaking the exact match bottleneck with soft matching of text, we hypothesize that exact match itself can be improved by replacing semantic independent frequency-based scoring with semantic rich scoring. In the rest of this section, we show how to modify the exact lexical match framework with contextualized term representations to build effective and efficient retrieval systems.
3.2 Contextualized Exact Lexical Match
Instead of term frequency, we desire to encode the semantics of terms to facilitate more effective matching. Inspired by recent advancements in deep LM, we encode both query and document tokens into contextualized vector representations and carry out matching between exact lexical matched tokens. Figure 1d illustrates the scoring model of COIL.
In this work, we use a Transformer language model $^3$  as the contextualization function. We encode a query  $q$  with the language model (LM) and represent its  $i$ -th token by projecting the corresponding output:
$$
\boldsymbol {v} _ {i} ^ {q} = \boldsymbol {W} _ {\text {t o k}} \mathrm {L M} (q, i) + \boldsymbol {b} _ {\text {t o k}} \tag {3}
$$
where  $W_{tok}^{n_t\times n_{lm}}$  is a matrix that maps the LM's  $n_{lm}$  dimension output into a vector of lower dimension  $n_t$ . We down project the vectors as we hypothesize that it suffices to use lower dimension token vectors. We confirm this in section 5. Similarly, we encode a document  $d$ 's  $j$ -th token  $d_j$  with:
$$
\boldsymbol {v} _ {j} ^ {d} = \boldsymbol {W} _ {t o k} \mathrm {L M} (d, j) + \boldsymbol {b} _ {t o k} \tag {4}
$$
We then define the contextualized exact lexical match scoring function between query document based on vector similarities between exact matched query document token pairs:
$$
s _ {\mathrm {t o k}} (q, d) = \sum_ {q _ {i} \in q \cap d} \max  _ {d _ {j} = q _ {i}} \left(\boldsymbol {v} _ {i} ^ {q \top} \boldsymbol {v} _ {j} ^ {d}\right) \tag {5}
$$
Note that, importantly, the summation goes through only overlapping terms,  $q_{i} \in q \cap d$ . For each query token  $q_{i}$ , we find all same tokens  $d_{j}$  in the document, computes their similarity with  $q_{i}$  using the contextualized token vectors. The maximum similarities are picked for query token  $q_{i}$ . Max operator is adopted to capture the most important signal (Kim, 2014). This fits in the general lexical match formulation, with  $h_{q}$  giving representation for  $q_{i}$ ,  $h_{t}$  giving representations for all  $d_{j} = q_{i}$ , and  $\sigma_{t}$  compute dot similarities between query vector with document vectors and max pool the scores.
As with classic lexical systems,  $s_{tok}$  defined in Equation 5 does not take into account similarities between lexical-different terms, thus faces vocabulary mismatch. Many popular LMs (Devlin et al., 2019; Yang et al., 2019; Liu et al., 2019) use a special CLS token to aggregate sequence representation. We project the CLS vectors with  $W_{cls}^{n_c \times n_{lm}}$  to represent the entire query or document,
$$
\boldsymbol {v} _ {c l s} ^ {q} = \boldsymbol {W} _ {c l s} \operatorname {L M} (q, \operatorname {C L S}) + \boldsymbol {b} _ {c l s} \tag {6}
$$
$$
\pmb {v} _ {c l s} ^ {d} = \pmb {W} _ {c l s} \mathrm {L M} (d, \mathrm {C L S}) + \pmb {b} _ {c l s}
$$
The similarity between  $\pmb{v}_{cls}^{q}$  and  $\pmb{v}_{cls}^{d}$  provides high-level semantic matching and mitigates the issue of vocabulary mismatch. The full form of COIL is:
$$
s _ {\text {f u l l}} (q, d) = s _ {\text {t o k}} (q, d) + \boldsymbol {v} _ {c l s} ^ {q} ^ {\top} \boldsymbol {v} _ {c l s} ^ {d} \tag {7}
$$
In the rest of the paper, we refer to systems with CLS matching COIL-full and without COIL-tok.
COIL's scoring model (Figure 1d) is fully differentiable. Following earlier work (Karpukhin et al., 2020), we train COIL with negative log likelihood defined over query  $q$ , a positive document  $d^{+}$  and a
<sup>3</sup>We used the base, uncased variant of BERT.
set of negative documents  $\{d_1^-, d_2^-,..d_l^-..\}$  as loss.
$$
\mathcal {L} = - \log \frac {\exp (s (q , d ^ {+}))}{\exp (s (q , d ^ {+})) + \sum_ {l} \exp (s (q , d _ {l} ^ {-}))} \tag {8}
$$
Following Karpukhin et al. (2020), we use in batch negatives and hard negatives generated by BM25. Details are discussed in implementation, section 4.
3.3 Index and Retrieval with COIL
COIL pre-computes the document representations and builds up a search index, which is illustrated in Figure 3. Documents in the collection are encoded offline into token and CLS vectors. Formally, for a unique token  $t$  in the vocabulary  $V$ , we collect its contextualized vectors from all of its mentions from documents in collection  $C$ , building token  $t$ 's contextualized inverted list:
$$
I ^ {t} = \left\{\boldsymbol {v} _ {j} ^ {d} \mid d _ {j} = t, d \in C \right\}, \tag {9}
$$
where  $\pmb{v}_{j}^{d}$  is the BERT-based token encoding defined in Equation 4. We define search index to store inverted lists for all tokens in vocabulary,  $\mathbb{I} = \{I^t\mid t\in V\}$ . For COIL-full, we also build an index for the CLS token  $I^{cls} = \{\pmb{v}_{cls}^{d}\mid d\in C\}$ .
As shown in Figure 3, in this work we implement COIL's by stacking vectors in each inverted list  $I^t$  into a matrix  $M^{n_t \times |I^k|}$ , so that similarity computation that traverses an inverted list and computes vector dot product can be done efficiently as one matrix-vector product with optimized BLAS (Blackford et al., 2002) routines on CPU or GPU. All  $\boldsymbol{v}_{cls}^d$  vectors can also be organized in a similar fashion into matrix  $M_{cls}$  and queried with matrix product. The matrix implementation here is an exhaustive approach that involves all vectors in an inverted list. As a collection of dense vectors, it is also possible to organize each inverted list as an approximate search index (Johnson et al., 2017; Guo et al., 2019) to further speed up search.
When a query  $q$  comes in, we encode every of its token into vectors  $\pmb{v}_i^q$ . The vectors are sent to the subset of COIL inverted lists that corresponds query tokens  $\mathbb{J} = \{I^t \mid t \in q\}$ . where the matrix product described above is carried out. This is efficient as  $|\mathbb{J}| << |\mathbb{I}|$ , having only a small subset of all inverted lists to be involved in search. For COIL-full, we also use encoded CLS vectors  $\pmb{v}_{cls}^q$  to query the CLS index to get the CLS matching scores. The scoring over different inverted lists can
serve in parallel. The scores are then combined by Equation 5 to rank the documents.
Readers can find detailed illustration figures in the Appendix A, for index building and querying, Figure 4 and Figure 5, respectively.
3.4 Connection to Other Retrievers
Deep LM based Lexical Index Models like DeepCT (Dai and Callan, 2019a, 2020) and DocT5Query (Nogueira and Lin, 2019) alter  $t f_{t,d}$  in documents with deep LM BERT or T5. This is similar to a COIL-tok with token dimension  $n_t = 1$ . A single degree of freedom however measures more of a term importance than semantic agreement.
Dense Retriever Dense retrievers (Figure 1b) are equivalent to COIL-full's CLS matching. COIL makes up for the lost token-level interactions in dense retriever with exact matching signals.
ColBERT ColBERT (Figure 1c) computes relevance by soft matching all query and document term's contextualized vectors.
$$
s (q, d) = \sum_ {q _ {i} \in [ c l s; q; e x p ]} \max  _ {d _ {j} \in [ c l s; d ]} \left(\boldsymbol {v} _ {i} ^ {q \top} \boldsymbol {v} _ {j} ^ {d}\right) \tag {10}
$$
where interactions happen among query  $q$ , document  $d$ ,  $cls$  and set of query expansion tokens  $exp$ . The all-to-all match contrasts COIL that only uses exact match. It requires a dense retrieval over all document tokens' representations as opposed to COIL which only considers query's overlapping tokens, and are therefore much more computationally expensive than COIL.
4 Experiment Methodologies
Datasets We experiment with two large scale ad hoc retrieval benchmarks from the TREC 2019 Deep Learning (DL) shared task: MSMARCO passage (8M English passages of average length around 60 tokens) and MSMARCO document (3M English documents of average length around 900 tokens) $^4$ . For each, we train models with the MSMARCO Train queries, and record results on MSMARCO Dev queries and TREC DL 2019 test queries. We report mainly full-corpus retrieval results but also include the rerank task on MSMARCO Dev queries where we use neural scores to reorder BM25 retrieval results provided by MSMARO organizers. Official metrics include
4Both datasets can be downloaded from https:// microsoft.github.io/msmarco/
MRR@1K and NDCG@10 on test and MRR@10 on MSMARCO Dev. We also report recall for the dev queries following prior work (Dai and Callan, 2019a; Nogueira and Lin, 2019).
Compared Systems Baselines include 1) traditional exact match system BM25, 2) deep LM augmented BM25 systems DeepCT (Dai and Callan, 2019a) and DocT5Query (Nogueira and Lin, 2019), 3) dense retrievers, and 4) soft all-to-all retriever ColBERT. For DeepCT and DocT5Query, we use the rankings provided by the authors. For dense retrievers, we report two dense retrievers trained with BM25 negatives or with mixed BM25 and random negatives, published in Xiong et al. (2020). However since these systems use a robust version of BERT, RoBERTa (Liu et al., 2019) as the LM and train document retriever also on MSMARCO passage set, we in addition reproduce a third dense retriever, that uses the exact same training setup as COIL. All dense retrievers use 768 dimension embedding. For ColBERT, we report its published results (available only on passage collection). BERT reranker is added in the rerank task.
We include 2 COIL systems: 1) COIL-tok, the exact token match only system, and 2) COLL-full, the model with both token match and CLS match.
Implementation We build our models with Pytorch (Paszke et al., 2019) based on huggingface transformers (Wolf et al., 2019). COIL's LM is based on BERT's base variant. COIL systems use token dimension  $n_t = 32$  and COIL-full use CLS dimension  $n_c = 768$  as default, leading to 110M parameters. We add a Layer Normalization to CLS vector when useful. All models are trained for 5 epochs with AdamW optimizer, a learning rate of 3e-6, 0.1 warm-up ratio, and linear learning rate decay, which takes around 12 hours. Hard negatives are sampled from top 1000 BM25 results. Each query uses 1 positive and 7 hard negatives; each batch uses 8 queries on MSMARCO passage and 4 on MSMARCO document. Documents are truncated to the first 512 tokens to fit in BERT. We conduct validation on randomly selected 512 queries from corresponding train set. Latency numbers are measured on dual Xeon E5-2630 v3 for CPU and RTX 2080 ti for GPU. We implement COIL's inverted lists as matrices as described in subsection 3.3, using NumPy (Harris et al., 2020) on CPU and Pytorch on GPU. We perform a set of matrix products to compute token similarities
over contextualized inverted lists, b) scatter to map token scores back to documents, and c) sort to rank the documents. Illustration can be found in the appendix, Figure 5.
This section studies the effectiveness of COIL and how vector dimension in COIL affects the effectiveness-efficiency tradeoff. We also provide qualitative analysis on contextualized exact match.
Table 1 reports various systems' performance on the MARCO passage collection. COIL-tok exact lexical match only system significantly outperforms all previous lexical retrieval systems. With contextualized term similarities, COIL-tok achieves a MRR of 0.34 compared to BM25's MRR 0.18. DeepCT and DocT5Query, which also use deep LMs like BERT and T5, are able to break the limit of heuristic term frequencies but are still limited by semantic mismatch issues. We see COILtok outperforms both systems by a large margin.
COIL-tok also ranks top of the candidate list better than dense retrievals. It prevails in MRR and NDCG while performs on par in recall with the best dense system, indicating that COIL's token level interaction can improve precision. With the CLS matching added, COIL-full gains the ability to handle mismatched vocabulary and enjoys another performance leap, outperforming all dense retrievers.