# Learning Heterogeneous Knowledge Base Embeddings for Explainable Recommendation
## 4 Collaborative Filtering on Knowledge Graphs
### Relation Modeling as Entity Translations  
As discussed previously, we assume that the product knowledge can be represented as a set of triplets \(S=\{(e_{h},e_{t},r)\}\), where \(r\) is the relation from entity \(e_{h}\) to entity \(e_{t}\). Because an entity can be associated with one or more other entities through a single or multiple relations, we propose to separate the modeling of entity and relation for CF. Specifically, we project each entity to a low-dimensional latent space and treat each relation as a translation function that converts one entity to another. Inspired by [21], we represent \(e_{h}\) and \(e_{t}\) as latent vectors \(\mathbf{e_{h}}\in\mathbb{R}^{d}\) and \(\mathbf{e_{t}}\in\mathbb{R}^{d}\), and model their relationship \(r\) as a linear projection from \(e_{h}\) to \(e_{t}\) parameterized by \(\mathbf{r}\in\mathbb{R}^{d}\), namely,  
\[\mathbf{e_{t}}=trans(e_{h},r)=\mathbf{e_{h}}+\mathbf{r} \tag{1}\]  
To learn the entity embeddings, we can construct a product knowledge graph by linking entities with the translation function in the latent space. An example generation process of such a graph is shown in Figure 1.  
Solving Equation (1) for all \((e_{h},e_{t},r)\in S\), however, is infeasible in practice. On one hand, a trivial solution that constructs a single latent vector for all entities with the same type will lead to inferior recommendation performance as it ignores the differences between users and items. On the other hand, deriving a solution that assigns different latent vectors for all entities in \(S\) is mathematically impossible because an entity can be linked to multiple entities with a single relationship. For example, we cannot find a single vector for _Also_viewed_ that translates an item to multiple items that have different latent representations. To solve the problems, we propose to relax the constrains of Equation (1) and adopt an embedding-based generative framework to learn it. Empirically, we want the translation model \(trans(e_{h},r)\approx\mathbf{e_{t}}\) for an observed relation triplet \((e_{h},e_{t},r)\in S\) and \(trans(e_{h},r)\
eq\mathbf{e_{t}^{\prime}}\) for an unobserved triplet  
Figure 1: The construction process of knowledge graph with our model. Each entity is represented with a latent vector, and each relation is modeled as a linear translation from one entity to another entity parameterized by the relation embedding. \((e_{h},e_{t}^{\prime},r)\
otin S\). In other words, we want \(trans(e_{h},r)\) to assign high probability for observing \(e_{t}\) but low probability for observing \(e_{t}^{\prime}\), which is exactly the goal of the embedding-based generative framework. The embedding-based generative framework is first proposed by [PERSON] et al. (2016) and has been widely used in word embedding [PERSON] et al. (2016); [PERSON] et al. (2016), recommendation [PERSON] et al. (2016); [PERSON] et al. (2016), and information retrieval tasks [PERSON] et al. (2016); [PERSON] et al. (2016). Formally, for an observed relation triplet \((e_{h},e_{t},r)\in S\), we can learn the translation model \(trans(e_{h},r)\) by optimizing the generative probability of \(e_{t}\) given \(trans(e_{h},r)\), which is defined as:  
\[P(e_{t}|trans(e_{h},r))=\frac{\exp(e_{t}\cdot trans(e_{h},r))}{\sum_{e_{t}^{ \prime}\in E_{t}}\exp(e_{t}^{\prime}\cdot trans(e_{h},r))} \tag{2}\]  
where \(E_{t}\) is the set of all possible entities that share the same type with \(e_{t}\). Because Equation (2) is a softmax function of \(e_{t}\) over \(E_{t}\), the maximization of \(P(e_{t}|trans(e_{h},r))\) will explicitly increase the similarity of \(trans(e_{h},r)\) and \(e_{t}\) but decease the similarity between \(trans(e_{h},r)\) and other entities. In this way, we convert Equation (1) into an optimization problem that can be solved with iterative optimization algorithms such as gradient decent. Another advantage of the proposed model is that it provides a theoretically principled method to conduct soft match between tail entities and the translation model.