SlowGuess/NAACL_2022_OCR huggingface dataset:
Hanhao  $\mathbf{Q}\mathbf{u}^{1}$  Yu Cao $^{3}$  Jun Gao $^{1}$  Liang Ding $^{3,4}$  Ruifeng Xu $^{1,2*}$
$^{1}$ Harbin Institute of Technology, Shenzhen  $^{2}$ Peng Cheng Laboratory
{hhqu0917, jgao95}@stu.hit.edu.cn xuruifeng@hit.edu.cn
3The University of Sydney, Australia 4JD Explore Academy
{ycao8647,ldin3097}@uni.sydney.edu.au
We present IBR, an Iterative Backward Reasoning model to solve the proof generation tasks on rule-based Question Answering (QA), where models are required to reason over a series of textual rules and facts to find out the related proof path and derive the final answer. We handle the limitations of existed works in two folds: 1) enhance the interpretability of reasoning procedures with detailed tracking, by predicting nodes and edges in the proof path iteratively backward from the question; 2) promote the efficiency and accuracy via reasoning on the elaborate representations of nodes and history paths, without any intermediate texts that may introduce external noise during proof generation. There are three main modules in IBR, QA and proof strategy prediction to obtain the answer and offer guidance for the following procedure; parent node prediction to determine a node in the existing proof that a new child node will link to; child node prediction to find out which new node will be added to the proof. Experiments on both synthetic and paraphrased datasets demonstrate that IBR has better in-domain performance as well as cross-domain transferability than several strong baselines. Our code and models are available at https://github.com/find-knowledge/IBR.
Endowing machines with reasoning capabilities is a longstanding problem (Newell and Simon, 1956) in the field of AI. Though existing tasks such as multi-hop QA (Yang et al., 2018; Welbl et al., 2018) or logical-reasoning QA (Yu et al., 2020; Dua et al., 2019) impose a higher requirement on the reasoning capabilities, they usually just request for an answer without the reasoning procedure that would make it interpretable. Recently, Clark et al. (2020) proposed new datasets and tasks for interpretable
Facts:
$\mathbf{F}_1$  : Anne is blue.
$\mathbf{F}_2$  : Anne is rough.
$\mathbf{F}_{9}$ : Fiona is rough.
$\mathbf{F}_{10}$ : Harry is blue.
$\mathbf{R}_1$  : All rough, blue people are cold.
$\mathbf{R}_2$  : All cold people are round.
$\mathbf{R}_6$  : If Harry is blue then Harry is rough.
$\mathbf{R}_7$  : Quiet people are round.
$\mathbf{R_8}$  : If someone is round and not cold then they are quiet.
$\mathbf{Q}_1$  : Harry is round.
$\mathbf{A}_1$  : True
$\mathbf{Q}_2$  : Fiona is not cold.
A: True
Figure 1: Illustration of generating proof iteratively. Regarding the proof path as a graph, and using the question as the initial node, other nodes and edges will be added step by step. (The gold proof is the obtained path in a reverse order exclude the question). The main challenges are wrong (cannot derive the answer) or redundant (can derive the answer, but the path is longer than the optimal one) branches may be involved.
reasoning. Given a question, coupling with a set of facts (plain statements) and rules (implication relationships) that are expressed in natural language, there are two tasks: 1) predicting the binary answer; 2) generating the proof path behind this answer. Large-scale pretrained models have shown strong performance on the first subtask in the early work (Liu et al., 2019), but there still remain challenges for the second one. These proof paths are usually more complicated than those involved in multi-hop QA tasks, as there are more nodes and branches rather than a single-directed chain.
Several approaches have been proposed to simultaneously address the two subtasks. PROVER (Saha et al., 2020) and PROBR (Sun et al., 2021) try to construct the reasoning path at once, where two classifiers are used to determine whether each node or edge is involved in the proof path respectively based on corresponding encoded
Human Language Technologies, pages 2968 - 2981
representations. But they lack interpretability on tracking the detailed reason for selecting each step. To make proof generation more interpretable, Proofwriter (Tafjord et al., 2021) and EVR (Liang et al., 2021) decompose complex reasoning over the question into multiple simple procedures, resulting in iterative and interpretable processes with the help of intermediate texts. Nevertheless, both of them suffer from efficiency and external errors issues. The reason is that they both require a large searching space, as they perform on the whole inferable texts and ignore the structure information from the history path that has been obtained. Moreover, the generation of intermediate text is costly and may introduce extra noise propagation.
Inspired by the top-down AMR parsing (Cai and Lam, 2019), where a sentence is divided into sub-meanings iteratively, we present Iterative Backward Reasoning (IBR) for better proof generation. It generates a proof path iteratively starting from the core component for QA, i.e. the question, making the process interpretable with trackable intermediate states. Regarding a higher efficiency and accuracy, and two challenges mentioned in Figure 1, the proof generation module of IBR simplifies the intermediate process of reasoning as well as avoids the unnecessary search for a possible unsuitable branch. To add a new node and edge to the path, there are two steps in IBR for each iteration: 1) finding out the next parent node, i.e. one existing rule or fact in the parsed history path that a new node will become its child; 2) determine which rule or fact that will be the new child node and added to the path. Equipped with question-aware representations from a pre-trained encoder, along with structure-aware node and path features, our model can choose the optimal endpoint. It accomplishes reasoning with the highest possibility to obtain a correct subsequent proof path based on relevant features, getting rid of intermediate texts while avoiding redundancy on all possible texts than previous iterative works.
In addition, to make IBR applicable for samples with incomplete proof paths, which are abandoned in the former backward iterative model EVR (Liang et al., 2021), we employ a proof strategy predictor to output a proof type. This prediction is then integrated into the later proof generation actions, making the process more controllable under different conditions.
We validate our approach on several datasets that are widely used in previous studies (i.e. DU0-DU5, Birds-Electricity, and ParaRules) spanning different settings (i.e. fully-supervised, fewer training data, and out-of-domain). Experimental results show that, compared to existing strong baselines including both non-iterative and iterative ones, IBR can achieve the best overall performance of proof generation and comparable answer prediction accuracy, along with noticeable generalization capability. Extensive analyses show that 1) the improvements come from our elaborately designed iterative and simplified proof generation modules, and 2) both the reasoning ability and latency could be significantly improved compared to former iterative models, making a better trade-off considering its reasonable interpretability.
Question answering and reasoning. Endowing machines to do reasoning over explicit knowledge is a primitive task (Newell and Simon, 1956). Early works tried to solve it by converting texts into logic forms (Newell and Simon, 1956; Musen and Lei, 1988). But such kinds of approaches can be affected by the error propagation caused by semantic parsing (Zettlemoyer and Collins, 2012; Berant et al., 2013; Berant and Liang, 2014).
Lately, question answering (QA) is employed as an important task for machine reasoning. Numerous datasets were proposed, including synthesized data (Weston et al., 2016), comprehension on natural texts (Rajpurkar et al., 2016; Joshi et al., 2017; Fisch et al., 2019) or more complex relationship reasoning (Tafjord et al., 2019; Lin et al., 2019). There are also multi-hop QA tasks like HotpotQA (Yang et al., 2018) or QAngaroo (Welbl et al., 2018), and logical QA datasets such as ReClor (Yu et al., 2020) and LogiQA (Liu et al., 2020), in which textual rules need to be inferred implicitly from a long supporting context. Plenty of studies try to solve these problems via neural networks and achieve remarkable performance (Joshi et al., 2020; Yu et al., 2018; Shao et al., 2020). Nevertheless, nearly all of them only focus on the prediction of final answers and neglect the acquisition of interpretable proofs. Although some datasets provide proof paths for better interpretability, these paths are only short chains with very few entities and cannot teach models to generate complex proofs.
Proof generation. NLProlog (Weber et al., 2019) first employs logic programming to search for a proof and then predicts the answer in multi-hop QA. Recently, Clark et al. (2020) propose new rule-based QA datasets for this line of research that include more complex proof paths, and present RuleTaker to answer questions. Saha et al. (2020) argue that producing answer proofs makes models more reliable and propose PROVER, a transformer-based model that enumerates all possible nodes and edges of a proof path and predicts whether each one exists at once based on their embeddings. PROBR (Sun et al., 2021) further improves this framework using the probabilistic graph to model more variables. There has been also an increasing interest in solving proof generation iteratively. EVR (Liang et al., 2021) splits the question into sub-questions, using generated intermediate texts to guide proof generation step by step. ProofWriter (Tajord et al., 2021) shares a similar idea but uses intermediate textual conclusions instead and a more powerful T5-11B model (Raffel et al., 2020) for generation, which makes it hard to reproduce. IBR is also an iterative model, being more interpretable than at-onc models. Despite getting rid of intermediate texts and directly using various representations to finish each step, it improves efficiency and effectiveness.
We first formulate the proof generation task as follows. Given a tuple  $(C, Q, A, P)$ , where  $C = \{RF_i\}$  is the contexts containing several textual rules and facts  $RF, Q$  is the question,  $A \in \{\text{True}, \text{False}\}$  is the answer, and  $P$  indicates the proof path for the detailed reasoning procedure to derive  $A$ , our goal is twofold: 1) predicting the answer  $A$ , and 2) generating the proof path  $P$ . Taking  $\mathbf{DU0}$ - $\mathbf{DU5}$  (Clark et al., 2020) dataset as example,  $P$  is a single-directed acyclic graph having the shortest path to derive  $A$ .  $P$  can start from one or multiple nodes but must end in one node that directly entails or contradicts  $Q$ . A node in  $P$  can be a fact, a rule, or a special NAF (Negation As Failure) node<sup>1</sup>. Edges between nodes indicate that the start nodes can be used to prove the end nodes during reasoning. Proofs in the dataset can be roughly classified
Facts:  $\mathbf{F}_1$ : Anne is blue. ...  $\mathbf{F}_{10}$ : Harry is furry.
Rules:  
...  
 $\mathbf{R}_3$  : All quiet, round people are rough.  
...  
 $\mathbf{R}_5$  : Furry people are quiet.  
...  
 $\mathbf{R}_7$  : Quiet people are round.
Q4: Harry is not rough. A: False Proof type: Proof
Figure 2: Examples of Proof and Fail-proof strategies.
$\mathbf{Q}_2$  : Erin is round. A: False Proof type: Fail-proof
into two types according to their strategies  $S$  to prove the question: (1) Proof: the question can be directly proven to be True or False using the given  $C$  and NAF; (2) Fail-Proof: the question cannot be explicitly deduced barely using  $C$  and NAF as some key information is missed, hence a positive statement is judged as False while a negative statement as True in such cases (Figure 2).
The proposed Iterative Backward Reasoning (IBR) model takes  $Q$  as the initial node and produce a proof path  $P$  backward, from the end node to the start node. Two actions are included at each iteration: (1) Predicting the new parent node, i.e., a node in the derived proof path where a child node will be added (except the first step that only  $Q$  exists); (2) Predicting the child node, i.e., the fact or rule in  $C$  that will be the child for the selected parent node. After each iteration, a new node and an associated edge are added. After obtaining the whole reasoning path, we remove  $Q$  and reverse all edges to get the final proof  $P$ .
The Figure 3 illustrates our IBR model, which can be divided into three modules, (1) QA and Strategy Prediction, (2) Parent Node Prediction, and (3) Child Node Prediction. In order to make the question  $Q$  can fully interact with context  $C$  (facts and rules) and obtain better representations, IBR uses pretrained RoBERTa (Liu et al., 2019) as the backbone network. The input of RoBERTa is the concatenation of the question  $Q$  and the context  $C = \{RF_{i}\}$ , separated by special [SEP] token, denoted as [CLS]  $Q$  [SEP] [SEP] [SEP].
IBR only uses the QA prediction and strategy prediction modules once at first to predict the answer  $A$  and the strategy of the proof (refer to §3.1, where the latter one will result in different proof
<sup>1</sup>A start node when the negation condition in the next node has no corresponding fact nor rule node, and the negation will be considered as true. E.g., there is no item in  $C$  related to "Anne is big", its negation "Anne is not big" will be considered as true.
Figure 3: The model architecture of IBR. 1) is only used once at the start, then 2) and 3) are applied iteratively to generate the whole proof. It also illustrates the detailed state when adding  $\mathrm{F}_{10}$  into the proof (F: facts, R: rules).
generation procedures. In order to improve the reasoning efficiency as well as accuracy, instead of using generated intermediate texts (Liang et al., 2021; Tafjord et al., 2021), all possible nodes (rules and facts) are represented by node embeddings in IBR. The initial state of the proof is only the representation of the question  $h_{Q}$ , then the rest of the reasoning path will be constructed based on it.
Samples with Fail-Proof strategy differs from ones with Proof, because their proofs are usually short without sub-branches, and only consist of rules due to lacking essential supporting facts. To take the advantage of such a property distinction and extend the applicability compared to former models (Liang et al., 2021) that cannot generate proofs for Fail-Proof samples, we apply different actions in modules (2) and (3) depending on the output from strategy prediction.
3.3 QA and Strategy Prediction Module
This module aims to predict the answer  $A$  of the question  $Q$  and the corresponding strategy  $S$  of proof  $P$ . Since the representation of [CLS] token from pretrained models is proven to have the capability of modeling the whole input, we use it as the input feature for both predictions as they condition the global information. The encoded [CLS] by RoBERTa,  $h_{[CLS]}$  is passed to a linear layer and the softmax function  $\sigma$  for answer and strategy classification respectively,
$$
P _ {Q A} = \sigma (f _ {Q A} (h _ {[ C L S ]})),
$$
$$
P _ {S t r a t e g y} = \sigma \left(f _ {S t r a t e g y} \left(h _ {[ C L S ]}\right)\right).
$$
Here,  $f_{QA}$  and  $f_{Strategy}$  indicate the linear layer for QA classification and strategy classification, respectively.  $P_{QA}$  and  $P_{Strategy}$  are binary-class probability values, the former one is for values of  $A \in \{True, False\}$  while the later one is for values of  $S \in \{Proof, Fail-proof\}$ .
3.4 Parent Node Prediction Module
This module determines which node in the current reasoning path is going to be the next parent node that a new child node will link to. To better represent the sequential information of each possible node (fact or rule), an LSTM (Hochreiter and Schmidhuber, 1997) is used to further encode the token-level embedding from RoBERTa. The hidden state in the last step is used as the textual representation  $h_{gi}$  of a possible parent node  $RF_{i}$ .
In addition, selecting a node from the existing proof path also needs global and structural modeling on the history path. To make this procedure a more convenient representation that involves the order of reasoning, the path is regarded as a tree structure and nodes are reordered by level traversal from top to down. Since  $Q$  is always the root node of the tree, e.g., if  $Q$  have two children  $RF_{1}$  and  $RF_{3}$ , and  $RF_{1}$  has a child  $RF_{2}$ , the reordered representation sequence is  $[h_{Q}, h_{g1}, h_{g3}, h_{g2}]$ . We then utilize another LSTM model to encode the
reordered representation sequence of the current reasoning path obtained before, extracting the overall state of the path, which is the hidden state  $h_{g}$  at the last time step in this LSTM.
A parent node attention based on the Transformer attention (Vaswani et al., 2017) is used to obtain the weights of all possible parents nodes. It takes  $h_{g}$  and the representation sequence of the current path  $\mathbf{H}_p = [h_Q, h_{g1} \dots h_{gt}]$  as input, i.e.
$$
\mathrm {A t t} (h _ {g}, \mathbf {H} _ {p}) = \sigma (f _ {Q} (h _ {g}) (f _ {K} (\mathbf {H} _ {p})) ^ {T} / \sqrt {d}), (1)
$$
where  $f_{Q}$  and  $f_{K}$  indicate linear layers,  $\sigma$  is a softmax function, and  $d$  is the dimension of  $h_{g}$ . As we discussed in §3.2, different operations are employed for corresponding strategy types of proofs. 1) If the predicted proof strategy is Proof, we select the node with the highest weight as the parent node  $RF_{p}$ . 2) If the predicted proof strategy is Fail-proof, we use the last node in the current path, i.e.  $h_{gt}$  in  $\mathbf{H}_P$ , as the parent node  $RF_{p}$ , because no sub-branch is included in such proof paths.
3.5 Child Node Prediction Module
This module decides which node will be added to the proof path and linked to the parent node  $RF_{p}$  we have obtained before. To derive the representations of candidate child nodes, similar to §3.4, we apply another LSTM model to the encoded RoBERTa embeddings and get  $h_{n_i}$  for  $RF_{i}$ . Since we discussed a special NAF node in §3.1 which may contain information from the whole context, we utilize a linear layer  $f_{NAF}$  to transform the [CLS] token embedding  $h_{[CLS]}$  into its representation  $h_{NAF}$ . Moreover, we initialize a representation  $h_{END}$  for the special END node, indicating that the proof generation process will finish here.
During selecting the new child node, we need to consider not only the knowledge of the history path, but also the state of the parent node. To better model such relationships, we propose a Path Focus Selection module to generate relevant features before predicting the child node. A 2-layer Transformer model along with a LSTM model is introduced. It first encodes the representations of node sequence  $\mathbf{H}_p$  from Parent Node Prediction respectively, then fuses their hidden state via a linear layer  $f_U$ ,
$$
h _ {F} = f _ {U} ([ \mathrm {T r a n s} (h _ {g p}, \mathbf {H} _ {p}, \mathbf {H} _ {p}); \mathrm {L S T M} (\mathbf {H} _ {p}) ]). \tag {2}
$$
Here,  $h_{gp}$  is the representation of the selected parent node in §3.4,  $f_U$  is the linear layer for feature fusing, while  $[\cdot; \cdot]$  stands for concatenation.  $q, k, v$  in  $\mathrm{Trans}(q, k, v)$  indicate the inputs corresponding to Query, Key, and Value in a transformer model, and only the hidden state in the last time step is remained in both Trans and LSTM. It is worth noting that the LSTM used here is a supplementary knowledge source for a better representation according to our empirical study. Such an operation results in a feature  $h_F$  that is aware of both the history proof path and the parent node that a child will link to.
This feature  $h_F$  will then be used in the Child Node Attention to calculate the attention weights on all possible child nodes. Particularly, an attention model same as Eq. 1 is applied on  $h_F$  and a series of child node representations obtained before  $\mathbf{H}_c = [h_{n1} \ldots h_{nk}, h_{NAF}, h_{END}]$ , and the attention weights are defined as  $\mathrm{Att}(h_F, \mathbf{H}_c)$ . It contains all facts and rules in the context, and the special NAF node as well as END node.
Similar to §3.4, we also apply different actions according to our predicted proof strategies before.
(1) If the strategy is Proof, we select the child node with the highest attention weight from all candidates as the new node in the proof path.
(2) If the strategy is Fail-proof, since  $RF_{p}$  is the last node during reasoning and this procedure is a first-order logical under such a situation, there is no need to make complex modeling on the derived path. Therefore, we directly use its parent node representation  $h_{gp}$  rather than encoded state from Transformer in Eq. 2 to get  $h_{F}$ . But LSTM is remained to maintain some basic modeling capability on the path. In child node attention, we mask all fact nodes and select the one with the highest weight among the remaining nodes, because this kind of proof usually only contains rules and such masking can avoid extra errors.
3.6 Training and Inference
The whole model is trained via binary cross-entropy losses from all three above modules jointly,
$$
L = L _ {Q A} + L _ {P a r e n t} + L _ {C h i l d} + \alpha * L _ {S t r a t e g y}.
$$
$L_{QA}$  and  $L_{Strategy}$  correspond to the loss of QA prediction and strategy prediction, respectively.  $\alpha$  is a hyperparameter to reweigh the influence of [CLS] token.  $L_{Parent}$  is the loss for parent node prediction, where the cross-entropy is calculated between the attention weight vector and a one-hot
vector indicating the gold parent node.  $L_{Child}$  is in a similar way on child node prediction. Note that samples labeled as Fail-proof strategy are not involved in the training of parent node prediction. As all their proof paths are chains and the new parent node is always the last node added to the path, so learning about these data may introduce model bias. To determine the gold reasoning order used as the target for training, we set a higher priority of fact nodes than rule nodes, as the clearer subject information is involved in facts. E.g., for a parent node with multiple children, the gold reasoning order of child node prediction is NAF nodes first, then fact nodes, and finally rule nodes. If there are more than one fact or rule nodes, IBR randomly swaps their order within each type at different training epochs.
During inference, IBR first makes predictions on the answer  $A$  and strategy  $S$ , then generate the parent node and child node iteratively, until the special END node is predicted as the new child node. IBR uses beam search to keep the top-K best proof paths at each proof generation step and select the best one as the final prediction, where the beam size is set as 8.
Following former studies (Saha et al., 2020; Sun et al., 2021), we evaluate our  $\mathrm{IBR}^2$  on three datasets and four settings including fully-supervised training, training using fewer samples, testing on out-of-domain samples, and generalization to more complex proofs or language.
Datasets. Experiments are conducted on three datasets raised by Clark et al.  $(2020)^{3}$ , where we use the same test split as previous works for fair comparison:
- DU0-DU5: Five synthesized datasets created by translating hand-crafted rules and formal language to natural language. It is divided by the highest depth of proof, where DU stands for "Depth Upto" (DU=0,1,2,3,5). Data in higher DU values also contain samples with lower depth. Note that proofs in DU0 only have one supporting or opposing fact. All related results are reported on DU5 test split.
- Bird-Electricity: It is a test-only dataset that contains samples about birds and electric circuits.
It is generated in the same way as DU0-DU5, but is in different domains from DU0-DU5.
- ParaRules: This dataset consists of 40k questions expressed in paraphrased natural language based on synthetic data, which is created by crowdsourcing. Multiple facts get together in one statement here rather than separated in DU0-DU5.