XRecSys : A framework for path reasoning quality in explainable recommendation

There is increasing evidence that recommendations accompanied by explanations positively impact on businesses in terms of trust, guidance, and persuasion. This advance has been made possible by traditional models representing user–product interactions augmented with external knowledge modeled as knowledge graphs. However, these models produce textual explanations on top of reasoning paths extracted from the knowledge graph without considering relevant properties of the path entities. In this paper, we present XRecSys , a Python framework for the optimization of the reasoning path selection process according to properties deemed relevant by users (e.g., time relevance of the linking interaction or popularity of the entity linked to the explanation). Our framework leads to a higher reasoning path quality in terms of the considered properties and, consequently, textual explanations more relevant for the users.


Introduction
Explaining to users why certain results have been provided to them has become an essential feature of modern information retrieval systems. In the deep learning era, the underlying models tend to be complex and opaque and explanations can improve their understanding and transparency. Under certain conditions, increasing users' awareness on the system's outputs (e.g., via explanations) is also mandatory by law (e.g., European General Data Protection Regulation and California on Automated Decision Systems) [1]. Recommender systems (RSs) The code (and data) in this article has been certified as Reproducible by Code Ocean: (https://codeocean.com/). More information on the Reproducibility Badge Initiative is available at https://www.elsevier.com/physical-sciences-and-engineering/computer-science/journals. * Corresponding author. represent a notable class of information retrieval systems whose outputs require accompanying explanations.
Existing explainable recommender systems augment traditional models representing user-product interactions with external knowledge modeled as knowledge graphs (KGs). On one hand, post-hoc explainable models [2] consider recommendation and explanation generation as two distinct steps. Methods pertaining to this family either pre-compute paths in the knowledge graph and attach them to the recommended products generated by traditional models [3,4] or generate counterfactual explanations [5][6][7][8]. In both cases, the ranked products are  optimized for utility and the training process of the recommendation model does not embed any constraint for the selection of accompanying reasoning paths. On the other hand, self-explainable [9] models perform recommendation and explanation generation jointly. Representative methods of this family include those performing reasoning either on the paths within the KG [10][11][12][13] or via neural symbolic techniques [14,15]. Though the resulting explanation is aligned to the associated recommendation, the utility of the recommendations could decrease and the explanations could not be aligned to the expectation of the users.
Usually, a reasoning path between a product the user already interacted with ( 1 ) and a product recommended to that user ( 2 ) is shaped in the form of interacted 1 share 1 share 2 . This path can be used to provide the textual explanation '' 2 is recommended to you because it shares 1 with another product you interacted with''. These paths basically include a past linking interaction ( interacted 1 ), a shared entity ( 1 ), a sharing relationship (shared), and a recommend item ( 2 ). We believe that the conceptual parts of a path have key characteristics that can significantly influence the perceived explanation quality for the users. For instance, the recency of the linking interaction presented can help the user better remember the interaction that brings to the recommendation. Similarly, a popular entity has a higher likelihood of being already known by the user and, possibly, lead to a better understanding of the provided explanation. Furthermore, the diversity in terms of explanation path types accompanying a recommended list can increase users' satisfaction and help users learn more connections.
In this paper, we present XRecSys, a Python framework for the optimization of the reasoning path selection process based on properties deemed relevant by users. Researchers and practitioners can optimize the suggested lists of products and the candidate reasoning paths generated for each product by a given recommendation model, according to properties of the reasoning paths. XRecSys is built on top of our paper recently published in the proceedings of the ACM SIGIR '22 conference [16]. There, we proposed three novel user-level properties of the reasoning paths emerged from a mixed approach involving a literature review study and an online users' survey, and a suite of re-ranking approaches for their optimization. Case studies for our framework include, among others, the re-ranking of recommendations with explanations provided by the state-of-the-art model PGPR [11]. Being flexible, we expect that XRecSys can be generally used for optimizing and testing any reasoning path property in different domains and with other models. In addition, our framework can be used to study how explanations whose underlying reasoning paths are optimized for certain properties affect users.

Functionality and key features
The proposed framework, illustrated in Fig. 1, produces textual explanations optimized for the proposed properties (e.g., the time relevance of the linking interaction in a reasoning path). In what follows, we describe the three main layers of the framework, namely Input Layer, Optimization Layer, and Result Layer.

Input layer
The Input layer includes two modules: KG-Dataset and Mapper. The KG-Dataset is composed by two ready to use pairs data sets and associated Knowledge Graphs. The dataset can be selected and preprocessed using the Mapper module, where is possible to perform threshold discarding, selecting different splitting methods and map the data in a standardize format that can be leveraged by the Exp. Rec. Module.

Optimization layer
The Optimization Layer is composed by the Explainable Recommender and the Optimizer Module. The Explainable Recommender is represented by a representative state-of-the-art baseline, in our case PGPR [11], that produces as output the whole set of candidate paths and the original preferences represented by pairs of recommended items and associated explanations. This output can be assessed directly thorough the Result Layer or can be redirected as input for the Optimizer module that can achieve two type of optimizations based on which output from the previous module is leveraged. The optimizations are distinguished in i) soft optimization, which performs a re-ranking of only the explanation paths, so the top-recommended products are the same as the original model, while the correspondent explanation paths are selected by picking the path that maximizes the target metric(s), and (ii) weighted optimization, which takes as input the whole set of predicted paths and perform a re-ranking of both products and explanations.

Result layer
The Results layer can take as input either the original or the optimized top-and corresponding explanation paths and allows for the assessment of average path explanation quality metrics and recommendation utility metrics, such as NDCG, Precision, Recall, and Hit Rate.

Software impact
Recommender systems based on path reasoning or neural symbolic reasoning are receiving increasing attention thanks to their capability of providing high fidelity explanations to users. Recent work has investigated the extent to which the characteristics of the reasoning paths selected for generating the textual explanations affect the quality of the recommendations perceived by the users. In this paper, we proposed a novel Python framework, XRecSys, with the purpose of promoting further studies touching on this line of research. For instance, we expect that our framework can ease the operationalization of new properties of reasoning paths as well as the assessment of the existing ones. Our codebase, is accompanied by a range of properties measurable on reasoning paths and optimizable via a suite of re-ranking approaches, according to a recently published paper. As a future direction, we plain to extend the range of available properties, experimental data sets, and recommendation models. Also we plan to incorporate the fairness dimension [17][18][19] to these methods to assess on what extend the recommendation produced are fair. The long-term goal of this framework is to support the community in improving the quality of textual explanations accompanying recommendations and foster the use of such strategies for academic and industrial purposes.

Declaration of competing interest
The authors declare that they have no known competing financial interests or personal relationships that could have appeared to influence the work reported in this paper.