# Learning Translation-Based Knowledge Graph Embeddings by \(N\)-Pair Translation Loss
## 4 Considering Multiple Negative Triples though \(N\)-Pair Translation Loss  
Even if translation-based knowledge graph embeddings with the margin-based ranking loss in Equation (2) learn vector representations of entities and relations, they suffer from slow convergence and poor local optima of parameters. These problems arise mostly from the fact that a positive triple is compared with only one negative triple at a single update of the parameters. Figure 1 illustrates the progress of training TransE with a positive triple (\(h\),\(r\),\(t\)) and negative triples (\(h\),\(r\),\(t^{\prime}_{i}\)) obtained by replacing the tail entity \(t\). The bold vector in this figure represents a vector representation of the relation \(r\) in the positive triple, and it is trained to be distinguished from the relation vector representations of the negative triples represented as dotted vectors. When the margin-based ranking loss is used, as in Figure 1, the only thing that is guaranteed is that the bold vector is better than one dotted vector because the positive triple is compared with only one negative triple. This implies that the trained vector representations using the margin-based ranking loss could be far from (local) optima at the early stage of training, even if the vector representations could reach (local) optima after iterating over a number of randomly-sampled negative triples. Furthermore, this type of learning could be unstable depending on the selected negative triple. Figure 1: How to find vector representations of entities and relations in TransE. Margin-based ranking loss (**a**) adopts only one negative triple at a time, while \(N\)-pair translation loss (**b**) considers multiple negative triples at once. On the other hand, if the positive triple is compared against multiple negative triples at once as in Figure 1b, the bold vector should be distinguished from all dotted vectors at the same time. In this figure, the vector representations of tail entities \(\mathbf{t}_{i}^{\prime}\) in the negative triples are distributed over the embedding space, and thus the bold vector can be trained more accurately. In other words, learning with multiple negative triples is stable compared to that optimizing the margin-based ranking loss, and the convergence toward (local) optima is also achieved at the early stage of training. In order to consider multiple negative triples, this paper proposes _N-pair translation loss_, which takes one positive triple and multiple negative triples for each parameter update. The proposed loss is calculated by comparing the positive triple with the multiple negative triples at the same time. Assume that there are _N+1_ triples of one positive triple \((h_{p},r_{p},t_{p})\) and \(N\) negative triples \(\{(h_{i},r_{i},t_{i})\}_{i=1}^{N}\). Then, the _N_-pair translation loss is defined as  
\[\mathcal{L}_{npair}(\{(h_{p},r_{p},t_{p}),\{(h_{i},r_{i},t_{i})\}_{ i=1}^{N}\})\] \[=\log\Big{(}1+\sum_{i=1}^{N}\exp(s(h_{p},r_{p},t_{p})\ -\ s(h_{i},r_{i},t_{i}))\Big{)},\]  
where \(s(\cdot)\) is a score function that is determined by the type of translation-based embedding. The proposed loss first tries to minimize the score of the positive triple to satisfy the constraints of translation-based knowledge graph embeddings. It also maximizes the differences between the score of the positive triple and those of the negative triples. That is, the _N_-pair translation loss satisfies these two constraints at the same time. In addition, since it considers all negative triples at once, the learning parameters move toward better optima. Note that the special case of this loss when \(N=1\) is the margin-based ranking loss [20]. Assume that there is _NG_, a negative triple generator that receives a set of all possible negative triples \(\mathcal{G}^{\prime}_{(h,r,t)}\) and the number of generated triples \(N\). Then, _NG_ generates \(\mathcal{G}^{\prime N}_{(h,r,t)}\), a set of \(N\) negative triples.