# Enhanced Knowledge Graph Embedding by Jointly Learning Soft Rules and Facts
## 4 Our Method
### Embedding Learning
#### 4.3.3 Training Objective  
Given a set of labeled triples \(\mathcal{L}=\{(x_{l},y_{l})\}\) and a set of soft rules \(\mathcal{F}=\{(f_{p},c_{p})\}_{p=1}^{p}\) with a set of their groundings \(\mathcal{G}=\cup_{p=1}^{p}\mathcal{G}_{p}\), we would like to learn the relation and entity embeddings \(\Theta\in\mathbb{C}^{d}\) from them.  
To this end, we minimize a global loss over \(\mathcal{L}\) and \(\mathcal{F}\), so as to find embeddings that could predict the labels of triples contained in \(\mathcal{L}\), while imitating the confidences of rules in \(\mathcal{F}\). The training objective was:  
\[\min_{\Theta}\frac{1}{|\mathcal{L}|}\sum_{(x_{l},y_{l})\in\mathcal{L}}L(-f(x_{l} )\cdot y_{l})+\frac{1}{|\mathcal{F}|}\sum_{(f_{p},c_{p})\in\mathcal{F}}\|\pi(f_ {p})-c_{p}\|^{2}, \tag{13}\]  
where \(f(\cdot)\) is the score function w.r.t. \(\Theta\); \(L(x)=\log(1+\exp(x))\) is the soft-plus function; and \(\pi(f_{p})\) is defined in Equation (12) w.r.t. \(\Theta\). We further imposed \(l_{2}\) regularization on \(\Theta\) to avoid overfitting. The former logistic loss of Equation (13) enforces that positive triples have truth values close to one, while negative ones close to \(-1\). Meanwhile, the latter L2 loss enforces that the truth values of rules stay close to their confidences. Gradient descent algorithms can be used to solve this optimization problem. However, it is difficult to compute the gradients of \(\pi(f_{p})\) in the latter L2 loss, since it contains many multiply operations. To overcome this difficulty, we replaced the product of \(\pi(f_{p})\) with the summation of the logarithms, i.e., the squared error \(\|\pi(f_{p})-c_{p}\|^{2}\) changes to \(\|\log\pi(f_{p})-\log c_{p}\|^{2}\). Here, \(\log\pi(f_{p})\) equals \(\sum_{q=1}^{Q_{p}}\log\pi(g_{pq})\) according to Equation (12). Thus, the training objective can be rewritten as:  
\[\min_{\Theta}\Bigl{(}\frac{1}{|\mathcal{L}|}\sum_{(x_{l},y_{l})\in\mathcal{L}} L(-f(x_{l})\cdot y_{l})+\frac{1}{|\mathcal{F}|}\sum_{(f_{p},c_{p})\in\mathcal{F}} \|\sum_{q=1}^{Q_{p}}\log\pi(g_{pq})-\log c_{p}\|^{2}\Bigr{)}. \tag{14}\]  
The embedding learning procedure of our method is shown in Algorithm 1. We took the given KG triples \(\mathcal{T}\) and extracted soft rules \(\mathcal{F}\) with their groundings \(\mathcal{G}\) from the first stage as inputs. Then, we carried out the optimization and learned the embeddings through \(N\) iterations. At each iteration, we first sampled a mini-batch \(\mathcal{T}^{b}\) and \(\mathcal{G}^{b}\) from \(\mathcal{T}\) and \(\mathcal{G}\). After that, a set of negatives \(\mathcal{T}^{b}_{neg}\) was generated by corrupting the triples in \(\mathcal{T}^{b}\). Next, we assigned the label one or \(-1\) for each triple in \(\mathcal{T}^{b}_{neg}\cup\mathcal{T}^{b}\) and constructed the set of labeled triples \(\mathcal{L}^{b}\) (Lines 6-8). Then, we partitioned the batch groundings \(\mathcal{G}^{b}\) into \(\cup_{p=1}^{P^{\prime}}\mathcal{G}^{b}_{p}\) by their associated rules contained in \(\mathcal{F}\). According to \(\cup_{p=1}^{P^{\prime}}\mathcal{G}^{b}_{p}\), we obtained a batch of rules \(\mathcal{F}^{b}=\{(f_{p},c_{p})\}_{p=1}^{P^{\prime}}\) (Line 10). Finally, we conducted gradient descent on these mini-batches and updated the embeddings. In practice, we used Stochastic Gradient Descent (SGD) in mini-batch mode as our optimizer, with [PERSON] [32] to tune the learning rate. Embeddings learned in this way are required to be compatible with not only triples, but also soft rules.