# Enhanced Knowledge Graph Embedding by Jointly Learning Soft Rules and Facts
## 4 Our Method
### Embedding Learning
#### 4.3.2 Triple and Rule Modeling  
To model triples, based on the score function of the existing KG embedding model, we aim to find a mapping function \(\phi:\mathcal{E}\times\mathcal{R}\times\mathcal{E}\rightarrow(0,1)\), so as to map the score of one triple \((e_{t},r_{k},e_{j})\) to a continuous truth value lying in the range of \((0,1)\). Such a soft truth value indicates the probability that the triple holds. In our method SoLE, we followed ComplEx and used function \(f(\cdot)\) (defined in Equation (3)) as the score function, as well as function \(\phi(\cdot)\) (defined in Equation (4)) as the mapping function. That is to say, given a triple \((e_{t},r_{k},e_{j})\), its truth value is measured by \(\phi(e_{t},r_{k},e_{j})=\sigma(\text{Re}(\sum_{s=0}^{d-1}[\mathbf{r_{k}}]_{s} \cdot[\mathbf{e_{i}}]_{s}\cdot[\mathbf{e_{j}}]_{s}))\).  
To model groundings, we used the product t-norm, which belongs to t-norm fuzzy logic [31], and defined the truth value of a grounding as a composition of the truth values of its component triples through specific logic connectives. We assumed that the probabilities of the triples in a grounding were independent conditioned on embeddings. Then, according to the product t-norm, the compositions related to logical conjunction and negation can be defined as follows:  
\[\pi(a\wedge b)=\pi(a)\cdot\pi(b), \tag{9}\] \[\pi(\
eg a)=1-\pi(a),\]  
where \(a\) and \(b\) are two logic formulas, which can be either a single triple (atom) or the compositions of triples through logic connectives; and \(\pi(a)\) is the truth value of \(a\), which indicates to what degree the formulae are true. If \(a\) is a single triple, such as \((e_{i},r_{k},e_{j})\), we can obtain \(\pi(a)=\phi(e_{i},r_{k},e_{j})\). Given these compositions, we can compute the truth value of any complex formulae recursively, e.g,  
\[\pi(a\lor b)=\pi(a)+\pi(b)-\pi(a)\cdot\pi(b), \tag{10}\] \[\pi(a\Rightarrow b)=\pi(\
eg a\lor b)=\pi(a)\cdot(\pi(b)-1)+1,\] \[\pi(a\wedge b\Rightarrow c)=\pi(a)\cdot\pi(b)\cdot(\pi(c)-1)+1.\]  
For instance, given a grounding \(g_{pq}\triangleq(e_{u},r_{m},e_{v})\Rightarrow(e_{v},r_{n},e_{u})\), its truth value is calculated as \(\pi(g_{pq})=\phi(e_{u},r_{m},e_{v})\cdot(\phi(e_{v},r_{n},e_{u})-1)+1\).  
To model logical rules, we followed [22] and embedded first order logic through explicit groundings. For rules with universal quantification like \(f_{p}\), we computed its truth value as:  
\[\pi(f_{p})=\pi(\wedge_{q=1}^{Q_{p}^{\prime}}g_{pq}), \tag{11}\]  
where \(Q_{p}^{\prime}\) is the number of all the \(f_{p}\)'s groundings propositionalized from the set \(\mathcal{E}\times\mathcal{E}\). Again, we assumed that the groundings in \(Q_{p}^{\prime}\) were independent. Besides, as we mentioned in Section 2.2, it is non-trivial to get all groundings, and many groundings are unnecessary. Thus, we used valid groundings \(Q_{p}\) of \(f_{p}\) to calculate its truth value and assumed that \(Q_{p}^{\prime}\) equaled \(Q_{p}\). Finally, we can simplify Equation (11) to:  
\[\pi(f_{p})=\prod_{q=1}^{Q_{p}}\pi(g_{pq}). \tag{12}\]  
If some groundings are not independent, we can think of this equation as an approximation.