Teaching Probabilistic Logical Reasoning to Transformers (2024)

Abstract: In this paper, we evaluate the capability of transformer-based language models in making inferences over uncertain text that includes uncertain rules of reasoning. We cover both Pre-trained Language Models (PLMs) and generative Large Language Models (LLMs). Our evaluation results show that both generations of language models struggle with reasoning over uncertain text. We propose a novel end-to-end fine-tuning approach, Probabilistic Constraint Training (PCT), that utilizes probabilistic logical rules as constraints in the fine-tuning phase without relying on these rules in the inference stage. To assess the effectiveness of PCT, we utilize the related corpora and, additionally, create a new and more challenging benchmark that, unlike the previous ones, uses instance-specific rules. Our study demonstrates that PCT improves the transformer-based language model’s intrinsic reasoning and makes their probabilistic logical reasoning process more explicit and explainable. Furthermore, PCT equips these models to effectively handle novel situations, including higher reasoning depth, new domains, and complex probabilistic structures.

## introduction language models have demonstrated high performance across a wide range of natural language processing (nlp) tasks @xcite which in the case of large language models holds even in zero-shot setting (chen, 2023). however, they struggle to reason over uncertain text involving logical probabilistic rules @xcite . this is confirmed by the reported poor results in arithmetic reasoning when using transformers @xcite which is required for probabilistic logical reasoning. additionally, logical probabilistic inference requires coherent step-by-step reasoning. however, plms' evaluation of various question-answering (qa) benchmarks shows they produce contradictory results that violate the expected steps of reasoning, such as following transitivity or symmetry rules @xcite . this has led to the development of hybrid approaches, where reasoning tasks are outsourced to neuro-symbolic engines, bypassing the need for reasoning by transformers @xcite . to overcome these limitations, we embed probabilistic reasoning into transformers by imposing the rules of logical probabilistic reasoning as constraints during their training phase. there are only a few research efforts dealing with uncertainty in text. understanding logical and uncertain rules in natural language form has been investigated in recent research on question answering @xcite , and there have been several attempts to teach transformers how to follow these rules @xcite . while incorporating hard logical rules is undoubtedly important and is still being investigated, in the real world, most of the external knowledge and rules involve uncertainty. for example, only a small fraction of the logical rules in dbpedia can be deemed certain @xcite . inference over text that includes uncertainty concerning facts, relations, and rules is required in many natural language comprehension tasks. for example, scientific content often utilizes hedges to express the measure of certainty in factual statements (pei and jurgens, 2021; national academies of @xcite . a related but different challenge is the explainability of the solutions provided by transformerbased language models. without the capability of providing the underlying components and steps necessary to answer a question, a language model's reasoning remains inexplicable even when it accurately answers a question @xcite . in this paper, we propose a method that forces the transformer to follow coherent reasoning steps to answer the final question, as shown in ## related work previous works mostly looked into the integration of crisp logic @xcite . the earlier work on qa with probabilistic rules in the text is rulebert @xcite , which serves as the baseline for our comparative study. while rulebert pioneers this field and introduces weighted binary cross-entropy loss to incorporate probabilistic learning in transformers, it lacks a mechanism to follow the probabilistic reasoning steps explicitly. additionally, our experiments revealed that the rules in textual form in this dataset are not properly utilized by the models (see section 6.1), which prompted us to introduce ruletaker-pro with context-specific rules. reasoning steps. explicit elucidation of reasoning steps in qa models has been central in recent literature. @xcite plms' reasoning by mapping their output to an inference graph, necessitating the model to learn its nodes and edges. while tafjord et al. utilize t5 to create an inference path, this and similar studies have focused on using non-probabilistic logical rules. in several other related works, the reasoning for qa is approached by generating an output that follows a predefined formal language for theorem proving given the logical rules, which is a very different approach from ours @xcite @xcite . wu et al. introduce reasoning in llms by generating intermediate reasoning steps as an extra output. however, we enable plms to incorporate this reasoning in training with no additional output. constraints. our approach's primary contribution is incorporating probabilistic constraints in the loss function. while various studies incorporate logical constraints into the loss function @xcite @xcite @xcite , no work has explored the application of probabilistic constraints in this context to date. neuro-symbolic methods. central to our approach is the implementation of an end-to-end model, ensuring the transferability of our model to various domains without the need to modify the model's architecture or decision processes. in contrast, numerous studies in this field rely on a pipeline approach, often incorporating a neuro-symbolic engine. zhang et al. proposes a framework in which transformers extract the factual knowledge in the text. consequently, a symbolic engine conducts the reasoning inference. more general approaches use deep neural methods to process the input and use either an existing engine @xcite such as problog @xcite or define a language to create a logical structure as an inference engine @xcite . ## training with probabilistic constraints we aim to develop a model capable of following probabilistic reasoning steps to infer the probability of a given hypothesis. these reasoning steps for the examples in in the upcoming subsections, we will explain the process of formulating and utilizing constraints. ## dataset creation motivation ruletaker-pro is created to address some of the shortcomings of the rulebert dataset. rulebert @xcite is built using about 100 rules with fixed probabilities that are applied to many examples in the dataset. the probabilities of these rules are extracted from an external source and remain constant for all examples in the dataset. however, we want a dataset with example-specific rules to make the required reasoning more realistic. for example, the probability of two married people being cousins in the context of one culture is high, while it is close to zero in another or, in the medical domain, the prevalence or mortality of a disease varies depending on gender or location @xcite . rule generation we developed ruletaker-pro by modifying ruletaker's crisp logical rules (p 1 , p 2 , ..., p n ) → q (with p r equal to 1.0) to include probabilities while the rest of the context remains unchanged (examples shown in the right side of after assigning probabilities to the rules, we use problog @xcite , a probabilistic logical inference tool that facilitates the encoding of probabilistic facts and rules, to compute the probability of the hypothesis. the resulting rules are similar to rulebert rules (p 1 , p 2 , ..., p n ) → q, p r. see appendix a.2 for details of data creation and distribution, which demonstrates its robustness. ## experiments in this section, we address four questions using our synthesized ruletaker-pro and the rulebert datasets: q1. how do textual rules affect probabilistic reasoning (6.1)? we will also discuss the baseline results this section. q2. to what extent does the baseline language model improve with pct concerning probabilistic reasoning and intermediate inferred facts (6.2)? we also include the ablation study to investigate the impact of various losses and datasets on our approach using multiple metrics. q3. can we transfer the probabilistic reasoning capabilities of the language model when pre-trained with pct(6.3)? q4. how do llms compare to fine-tuned bert-based models (6.4)? evaluation metrics. we use several performance measures following @xcite . binary accuracy (ba) deems predictions correct if ground truth and predicted probability both fall under or over 0.5. the ca25, ca10, and ca1 require the predicted probability to be in a window @xmath0.25, ±0.10, @xmath1.01 of the ground truth, respectively. @xcite applies ca10 and ca1 metrics to dataset splits with isolated rules, while ba is used for all reasoning depths for datasets involving all the rules. for comparison, we use ba for rule-bert, but we thoroughly evaluate ruletaker-pro using all relevant criteria. we use an extra metric, cs, to measure soft constraint satisfaction that deems the constraint (defined in equation 3 ) satisfied if the following inequality holds: this means that the difference between the predicted and calculated probability of an inferred fact, based on premise facts, must be less than a threshold. this threshold is 0.01 for cs1, 0.10 for cs10, and 0.25 for cs25. ## conclusion and future work addressing the problem of reasoning over uncertain rules in textual format, we create a new dataset, ruletaker-pro, extending the limited resources for studying this problem. we investigate how uncer-tain rules can be represented in the text and used by the learning models. we propose a novel approach that explicitly uses the rules of probabilistic reasoning as constraints in the loss. this approach improves the performance and reasoning of the backbone language models. our experiments on llms have revealed that they struggle to perform probabilistic reasoning in zero-shot and few-shot scenarios, despite their impressive capabilities in solving other nlp tasks. our future objective is to develop models that utilize the text of the rules more effectively and transfer their reasoning abilities to more realistic qa domains featuring uncertainty and more advanced structures of probabilistic reasoning. also, it is worth exploring prompt engineering methods for large language models to ease the use of uncertain text and inference on them.