## 2 Materials and Methods
### A Hybrid Approach for Diagnosis Refinement  
In this section, we describe the mathematical details of our symptom checking system. Consider a network \(G\) comprising a set of diseases \(D=\{d_{1},\dots,d_{m}\}\) and symptoms \(S=\{s_{1},\dots,s_{n}\}\), where each disease \(d_{i}\) is associated with a subset of symptoms \(s_{i}\), and each edge between a symptom \(s_{i}\) and the associated disease \(d_{j}\) is defined by a Conditional Probability Table (CPT) representing \(P(s_{i}|d_{j})\) that follows the Noisy-OR assumptions. When a user provides a description of symptoms \(T\) in the form of a list of words \(T=(w_{1},\dots,w_{t})\), a BERT model computes the a priori probabilities of the disease vector  
Figure 4: Noisy-OR gate. \(P(D|T)\). The probability is represented by the function denoted \(f_{\theta}(T)\), where \(\theta\) represents the model weights. The BERT model output is formalized as follows:  
\[f_{\theta}(T)=\text{softmax}(W^{T}\cdot\text{BERT}_{\text{enc}}(T)), \tag{5}\]  
where \(W\in\mathbb{R}^{m\times H}\), with \(H\) being the output vector size of the BERT model. As discussed in the previous section, while our deep learning model is designed to predict categories, the Bayesian network operates at the level of individual conditions. To address this, we identify the \(K\) most probable categories, as predicted by the neural network. We then construct a graph comprising the top \(k\) conditions associated with these categories based on the output probability for each category defined by the BERT model. In the second stage of the algorithm, we compute the probability of symptoms based on the a priori values and the network \(G\); we start by taking the top \(k\) diseases from the disease probability vector \(P(D|T)\) as was mentioned before. \[D_{k}=\text{top}_{k}(P(D|T)). \tag{6}\]  
With this, we construct a subnetwork \(G_{k}\) from \(G\), including only the diseases in \(D_{k}\) and their associated symptoms \(S_{k}=\bigcup_{d_{i}\in D_{k}}s_{d_{i}}\). The joint distribution represented by this subnetwork is given by  
\[P(S,D)=P(S|D)P(D)=\prod_{s_{i}\in S_{k}}P(s_{i}|D)\prod_{d_{j}\in D_{k}}P(d_{j }|T), \tag{7}\]  
as shown in Equation (1). The probabilities of each symptom are computed by  
\[P(s_{i}|T)=\sum_{d\in D_{k}}P(s_{i}|d)P(d|T). \tag{8}\]  
The probabilities of each disease are computed as  
\[P(d_{j}|S)=\frac{1}{\mathcal{N}}\sum_{d_{i}\in D_{k}\setminus\{d_{j}\}}P(S|d_{ i})P(d_{i}), \tag{9}\]  
where \(\mathcal{N}\) is a normalization factor ensuring that probabilities sum to 1. To gather new evidence, we start by querying the user to confirm or deny the presence of the \(q\) top-ranked symptoms:  
\[S_{q}=\text{top}_{q}(P(S|T)), \tag{10}\]  
where \(S_{q}\) represents the symptoms with the highest updated probabilities and \(q\) is a parameter of the algorithm that represents how many symptoms the user confirms or rejects at each step. The user then provides evidence that looks like \(e=\{S_{1}=1,S_{2}=1,\ldots S_{q}=0\}\) in each step. The new evidence \(e\) is added to the existing evidence vector \(E=E+e\), and the disease probability vector is updated using Equation (9). Then, new probabilities for the symptoms excluded from the evidence vector \(S_{n}^{\prime}=S-E\) are computed and the process repeats for \(t\) iterations, each time updating the probabilities and gathering new evidence. Finally, the most probable disease is determined as  
\[D_{p}=\text{arg max}(P(D|T,E)). \tag{11}\]  
The complete algorithm is resumed in Algorithm 1.