# Collaborative Filtering Recommendation Algorithm Based on Knowledge Graph

Authors: Ruihui Mu; Xiaoqin Zeng
Journal: Mathematical Problems in Engineering
 (2018)

---

## Abstract

To solve the problem that collaborative filtering algorithm only uses the user-item rating matrix and does not consider semantic information, we proposed a novel collaborative filtering recommendation algorithm based on knowledge graph. Using the knowledge graph representation learning method, this method embeds the existing semantic data into a low-dimensional vector space. It integrates the semantic information of items into the collaborative filtering recommendation by calculating the semantic similarity between items. The shortcoming of collaborative filtering algorithm which does not consider the semantic information of items is overcome, and therefore the effect of collaborative filtering recommendation is improved on the semantic level. Experimental results show that the proposed algorithm can get higher values on precision, recall, and F-measure for collaborative filtering recommendation.


---

## Body

## 1. Introduction

Due to information explosion, huge number of items are present over web which makes it difficult for user to find appropriate item from available set of options. Recommender system (RS) overcomes the problem of information overload and suggests items that interest a user. It has gained a lot of popularity in past decades and huge amount of work has been done in this field.Collaborative Filtering (CF) is the most popular and widely used approach for RS which tries to analyze the user’s interest over the target item on the basis of views expressed by other like-minded users. It has been successfully applied in the industrial fields such as e-commerce [1], online learning [2], and news media [3]. It has also attracted attention from a large number of scholars in the academic. Recommendation is according to the similarity between the target user and other users. The recommender systems let users give ratings about a set of items such as movies, songs, and hotels; thus, we can make recommendation to each user when enough information is stored on the system. In other words, we can compute the similarity between two users or items by considering the corated items, which are commonly rated by both users. In traditional CF, items are recommended based on rating information of similar users on the items and using some well-known similarity measurements, such as the Pearson correlation coefficient, cosine similarity, and adjusted cosine measure.In [4], they integrated the Facebook user’s personalized data into CF and improved the accuracy of recommendation by merging multi-domain data sets. In [5], they proposed a collaborative filtering model that combines singularity and diffusion processes to solve the problem of information overload by using the rating context information. In [6], they proposed content-based CF algorithm and improved the performance of news recommendation. In the traditional CF recommender systems, they use the information such as user implicit feedback data (such as purchase records) and user explicit feedback data (such as rates) to make predictions or recommendations.However, these methods mainly used the external information, such as user-item rating matrix, and did not fully consider the internal semantic information of the items itself. With the development of knowledge graph technology, the industry has accumulated a large number of open semantic data, such as Freebase [7] and Dbpedia [8]; it contains a vast of information. How to use these open semantic data to improve the performance of recommender system is a hot topic. In [9], they attempted to use the structural features of the knowledge graph to fuse the ontology into the CF algorithm. Existing research shows that the knowledge graph representation learning method can embed the knowledge graph into a low-dimensional semantic space and then use continuous numerical vectors to reflect the structural features of the knowledge graph. This method can efficiently calculate the semantic connections between entities. In [10], they attempted to combine the knowledge graph representation learning algorithm with implicit feedback based collaborative filtering, convert the original data into a preference sequence for parameter learning, and enhance the performance of the recommendation, but they did not consider the semantic information of the items itself.The purpose of our work is to take a step further in addressing the cold start and data sparsity problems by proposing a novel approach to integrate the semantic information of the items itself with the CF recommendation algorithm.In this paper, we address the above issues by introducing a novel similarity model based on knowledge graph representation learning. The proposed similarity model can select different neighbors which have higher similarity with the target user for each different target item and take the semantic similarity of the items into account.The proposed model uses the knowledge graph representation learning-TransE algorithm to obtain the semantic information of the item, calculates the semantic similarity between the items, integrates the semantic information of the item into the recommendation process, and produce the recommended list for users.The rest of this paper is organized as follows. Section2 gives a brief overview of related literatures on item-based CF and KG representation learning. In Section 3, we describe the details of the proposed algorithm. In Section 4, we present an experimental evaluation comparing our models with existing work. Finally, Section 5 concludes our work and outlines potential future work.


## 2. Related Work

### 2.1. Item-Based Collaborative Filtering Recommendation Algorithm

Item-based CF recommendation algorithm [11] is a nearest neighbor recommendation algorithm; it is based on the assumption that users tend to like similar items. In the recommender system, the algorithm recommends the most similar items to the user by calculating the similarity between the items. The recommendation process is as follows: suppose there is a list of m users U=U1,U2,…,Um and a list of n items I=I1,I2,…,In and the user-item rating matrix Rm×n is (1)Rm×n=R11R12⋯R1j⋯R1nR21R22⋯R2j⋯R2n⋮⋮⋯⋮⋯⋮Ri1Ri2⋯Rij⋯Rin⋮⋮⋯⋮⋯⋮Rm1Rm2⋯Rmj⋯Rmnwhere Rij denotes the rate of the user i on the itemj and represents the useri’s preference of the item j. The similarity between two items can be measured by treating each item as a vector and computing the cosine of the angle formed by the vectors.SupposeA and B are vectors and n is their dimension; vector cosine similarity between A and B is defined as(2)simcosA,B=cos⁡θ=A·BA×B=∑i=1nAi×Bi∑i=1nAi2×∑i=1nBi2s i m c o s (A, B) is bigger, and the vectors A and B are more similar. When simcos(A, B) =0, it means the two vectors are completely dissimilar and simcos(A, B) =1 means they are completely similar.The ratings are relative sparse in the user-item rating matrix. In [12], they proposed the importance of similarity weights to avoid data sparsity. The method uses the idea of shrinking in the Bayesians. When only a small number of ratings are used for similarity calculation, reduce the similarity weight between them. Therefore, the improved similarity weight between items is(3)wij′=UijUij+β×wijwherew′ij is similarity weight after contraction. wij (i.e., simcos(A, B)) denotes the similarity of the items, computed by (2). Uij represents the number of users who corated item i andj, and β is a contraction coefficient. When Uij is small, β plays contraction effect. When Uij>>β, the effect is not significant.According (2) and (3), the item-based CF recommendation algorithm converts the user-item rating matrix into item-item similarity matrix and uses Top-k recommendation algorithm to produce k most similar items. It has two steps: (1) prefiltering neighbors from the item-item similarity matrix. Prefiltering neighbors is to filter the neighbors of the similarity weight larger than the threshold. (2) Find k most similar items after computing the similarities and then get the Top-k most similar items for recommendation.


### 2.2. Knowledge Graph Representation Learning

The Word2Vec model is proposed in [13], the model embeds words intoK-dimensional space. The method is to use the analogy to find the similarity between words. In [14], they applied the method to the knowledge graph and proposed the TransE learning algorithm. An energy-based model is for learning low-dimensional embeddings of entities. In TransE, relationships are represented as translations in the embedding space: if (h,r,t) holds, then the embedding of the tail entity t should be close to the embedding of the head entity h plus some vector that depends on the relationship.Given a training set S of triplets(h,r,t)composed of two entitiesh,t∈ E (the set of entities) and a relationship r∈L (the set of relationships), the model learns vector embeddings of the entities and the relationships. The basic idea behind the model is that the functional relation induced by the ‘r -labeled edges corresponds to a translation of the embeddings; i.e., we wanth+r≈t when (h,r,t) holds (t should be a nearest neighbor ofh + r, whileh + r should be far away from t otherwise).All embeddings for entities and relationships are first initialized. At each main iteration of the algorithm, the embedding vectors of the entities are first normalized. Then, a small set of triplets is sampled from the training set, and will serve as the training triplets of the minibatch. For each such triplet, we sample a single corrupted triplet. The parameters are then updated by taking a gradient step with constant learning rate. The algorithm is stopped based on its performance on a validation set.The basic idea of this algorithm is to embed the entities and relations of the knowledge graph into a low-dimensional vector space and then convert the entities and relations into vector representations. Therefore, the similar entities in the KG are also similar representations in the vector space. That is, semantic similar entities are also similar in vector space.Based on the above ideas, we can embed a triplet with rich semantic information into aK-dimensional semantical space and generate corresponding vectors and realize the knowledge graph learning representation.Through the KG representation learning, we can calculate the semantic similarity of two entities, and the knowledge graph can be conveniently used in other learning tasks. There are two methods to implement the KG representation learning:(1) tensor decomposition-based methods and (2) translation-based methods. The former includes NTN [15–19] and RESCAL [19–22]. The latter includes TransE [23–25], TransH [26–29], and TransR/CtransR [30–32]. The relationships are very large and very sparse in the large-scale knowledge bases; the tensor decomposition-based methods are ineffective, so it is more appropriate to select the translation-based methods [33–36].The purpose of our work is to take a step further in addressing the cold start and sparsity problems by proposing a novel approach to combine the knowledge graph in CF.


## 2.1. Item-Based Collaborative Filtering Recommendation Algorithm

Item-based CF recommendation algorithm [11] is a nearest neighbor recommendation algorithm; it is based on the assumption that users tend to like similar items. In the recommender system, the algorithm recommends the most similar items to the user by calculating the similarity between the items. The recommendation process is as follows: suppose there is a list of m users U=U1,U2,…,Um and a list of n items I=I1,I2,…,In and the user-item rating matrix Rm×n is (1)Rm×n=R11R12⋯R1j⋯R1nR21R22⋯R2j⋯R2n⋮⋮⋯⋮⋯⋮Ri1Ri2⋯Rij⋯Rin⋮⋮⋯⋮⋯⋮Rm1Rm2⋯Rmj⋯Rmnwhere Rij denotes the rate of the user i on the itemj and represents the useri’s preference of the item j. The similarity between two items can be measured by treating each item as a vector and computing the cosine of the angle formed by the vectors.SupposeA and B are vectors and n is their dimension; vector cosine similarity between A and B is defined as(2)simcosA,B=cos⁡θ=A·BA×B=∑i=1nAi×Bi∑i=1nAi2×∑i=1nBi2s i m c o s (A, B) is bigger, and the vectors A and B are more similar. When simcos(A, B) =0, it means the two vectors are completely dissimilar and simcos(A, B) =1 means they are completely similar.The ratings are relative sparse in the user-item rating matrix. In [12], they proposed the importance of similarity weights to avoid data sparsity. The method uses the idea of shrinking in the Bayesians. When only a small number of ratings are used for similarity calculation, reduce the similarity weight between them. Therefore, the improved similarity weight between items is(3)wij′=UijUij+β×wijwherew′ij is similarity weight after contraction. wij (i.e., simcos(A, B)) denotes the similarity of the items, computed by (2). Uij represents the number of users who corated item i andj, and β is a contraction coefficient. When Uij is small, β plays contraction effect. When Uij>>β, the effect is not significant.According (2) and (3), the item-based CF recommendation algorithm converts the user-item rating matrix into item-item similarity matrix and uses Top-k recommendation algorithm to produce k most similar items. It has two steps: (1) prefiltering neighbors from the item-item similarity matrix. Prefiltering neighbors is to filter the neighbors of the similarity weight larger than the threshold. (2) Find k most similar items after computing the similarities and then get the Top-k most similar items for recommendation.


## 2.2. Knowledge Graph Representation Learning

The Word2Vec model is proposed in [13], the model embeds words intoK-dimensional space. The method is to use the analogy to find the similarity between words. In [14], they applied the method to the knowledge graph and proposed the TransE learning algorithm. An energy-based model is for learning low-dimensional embeddings of entities. In TransE, relationships are represented as translations in the embedding space: if (h,r,t) holds, then the embedding of the tail entity t should be close to the embedding of the head entity h plus some vector that depends on the relationship.Given a training set S of triplets(h,r,t)composed of two entitiesh,t∈ E (the set of entities) and a relationship r∈L (the set of relationships), the model learns vector embeddings of the entities and the relationships. The basic idea behind the model is that the functional relation induced by the ‘r -labeled edges corresponds to a translation of the embeddings; i.e., we wanth+r≈t when (h,r,t) holds (t should be a nearest neighbor ofh + r, whileh + r should be far away from t otherwise).All embeddings for entities and relationships are first initialized. At each main iteration of the algorithm, the embedding vectors of the entities are first normalized. Then, a small set of triplets is sampled from the training set, and will serve as the training triplets of the minibatch. For each such triplet, we sample a single corrupted triplet. The parameters are then updated by taking a gradient step with constant learning rate. The algorithm is stopped based on its performance on a validation set.The basic idea of this algorithm is to embed the entities and relations of the knowledge graph into a low-dimensional vector space and then convert the entities and relations into vector representations. Therefore, the similar entities in the KG are also similar representations in the vector space. That is, semantic similar entities are also similar in vector space.Based on the above ideas, we can embed a triplet with rich semantic information into aK-dimensional semantical space and generate corresponding vectors and realize the knowledge graph learning representation.Through the KG representation learning, we can calculate the semantic similarity of two entities, and the knowledge graph can be conveniently used in other learning tasks. There are two methods to implement the KG representation learning:(1) tensor decomposition-based methods and (2) translation-based methods. The former includes NTN [15–19] and RESCAL [19–22]. The latter includes TransE [23–25], TransH [26–29], and TransR/CtransR [30–32]. The relationships are very large and very sparse in the large-scale knowledge bases; the tensor decomposition-based methods are ineffective, so it is more appropriate to select the translation-based methods [33–36].The purpose of our work is to take a step further in addressing the cold start and sparsity problems by proposing a novel approach to combine the knowledge graph in CF.


## 3. Proposed Method

In this section, we describe the proposed collaborative filtering recommendation algorithm based on knowledge graph (KG). First, we introduce the framework of the algorithm, followed by the TransE algorithm based KG representation learning. Next, we present the semantic similarity measure. Then, the details of fusion semantic neighbors are provided. Finally, we give the details of the algorithm description.


### 3.1. Algorithm Framework

We propose a novel CF recommendation algorithm based on KG representation learning. Its basic idea is using the KG representation learning-TransE algorithm to obtain the semantic information of the item, calculating the semantic similarity between the items, integrating the semantic information of the item into the recommendation process, and producing the recommended list for users.In the traditional CF algorithms, they only use the external ratings information, such as user-item rating matrix, and the proposed algorithm adds internal knowledge (knowledge graph) into CF and will get better results and improve the recommended performance.We use the KG representation learning algorithm to embed entities into a low-dimensional vector space. Then calculate the semantic similarity between the entities and generate the semantic similarity matrix. Use Top-k algorithm to get the k nearest semantic neighbors of the items. At the same time, we use the user-item rating matrix to calculate the similarity between items and get the item-item similarity matrix and then use Top-k algorithm to get the k nearest neighbors of the items. Finally, adjust the fusion ratio, integrate the nearest semantic neighbors of the items with the CF nearest neighbors of the items, and produce the recommended list.The rich semantic information can alleviate the cold start problem in the recommender system. Figure1 shows the flowchart of proposed algorithm (TransE-CF).Figure 1
TransE-CF flowchart.


### 3.2. TransE Algorithm Based KG Representation Learning

The knowledge graph is a knowledge network and can be represented by a directed graph (or digraph) formed by the triples and the mutual links between the triples. The triplets carry the semantic information of the entity itself. Nodes represent the entities and edges represent the relationships between the entities.Taking the movie field as an example, the movie entity mainly includes the main features of it, such as actors, types, and directors. These features characterized the movies. Using the movie features, one can obtain a triplet of a movie knowledge graph. As shown in Figure2.Figure 2
Triples of knowledge graph.In Figure2, the movie entity and the actor entity are linked to form a triplet (M, starring_actor, A) and the knowledge graph is formed by the mutual linkage between the triplets. Figure 3 shows the structure of some selected movies and their attributes in the Freebase. In Figure 3, it can be seen that two nodes are closer in the knowledge graph and they are more similar in semantics. Therefore, in the movies recommendation, we can use the user’s rating information of the movie and the movie’s own semantic information. In the CF recommender system, if the ratings of the two items are similar, they are determined as neighbors. Similarly, if the movies are semantically similar in the knowledge graph, they can be judged as neighbors intuitively.Figure 3
Movie knowledge graph.Based on the above ideas, we use the TransE algorithm to integrate the items’ semantic information with the user-item rating matrix for recommendation. According to the definition of the TransE algorithm, triplet (h, r,andt) in the knowledge graph S can be trained using the loss function, defined as (4)L=∑h,r,t∈S∑h′,r,t′∈S′h,r,tγ+h+r-t-h′+r-t′+(5)S′h,r,t=h′,r,t∣h′∈E∪h,r,t′∣t′∈Ewhere(h′,r,t′) is the corrupted triple as negative training sample. The negative sample is the head entity or tail entity of the original correct triplet by randomly replacing it with other entities. γ is margin hyperparameter, denotes the size of the gap, and generally sets γ=1. ∙ is either the L1 or the L2-norm. [·]+ is the hinge loss function, as shown in(6)x+=x,x>00,x≤0where x+ denotes the positive part of x.We minimize the loss functionL over the training set, and the optimization is carried out by stochastic gradient descent (in minibatch mode), over the possibleh,r, andt, with the additional constraints that the L2-norm of the embeddings of the entities, are 1 (no regularization or norm constraints are given to the label embeddingsr).Throughout the training process, TransE uses the idea of maximum separation, pulling distances between positive and negative sample vectors to train and learn. The stochastic gradient descent is continuously iteratively degraded to optimize the loss function. The final training results are(1) similar semantic entities in the KG have closer distances in the low-dimensional space; (2) the head node’s vector plus the relational vector is basically equal to the tail node’s vector. The specific training process is described in [14].


### 3.3. Semantic Similarity Measure

TransE algorithm transforms entities into low-dimensional real-valued vectors. In the different KG representation learning methods, the meanings of the vectors are different and the similarity measures are different too. The representation of the vectors in the TransE algorithm is defined as(7)h+r≈twhereh and t are the head entity and the tail entity respectively and r is the relationship between the entities. The norm ∙ can be selected as the L2 norm.t should be a nearest neighbor of h+r. The closer the entities in the KG are, the more similar the vectors are, as shown in Figure 4.Figure 4
TransE model.Since the TransE algorithm chooses the Euclidean distance to calculate the loss function, we use the same norm Euclidean distance to measure the similarity between the entities, where the selected Euclidean distance range is [0, ∞) and the similarity measure range is[0,1]. For the two entity vectors A andB, through mathematical transformation, the two value domains are matched one by one by. The final semantic similarity measure is defined as (8)simsemA,B=1-A-BA-B+1=1A-B+1In(8), when the value of simsem (A, B) is closer to 1, the entity vectors A and B are more similar; that is, the relationship is closer in the KG. Conversely, if the value of simsem (A, B) is smaller, the more alienation relationship between A andB, and the lower semantic similarity between A andB.We use the semantic similarity for recommendation; the process is similar to the item-based CF recommendation. We use(8) to get the item-item semantic similarity matrix, as shown in Table 1.Table 1
Item-tem semantic similarity matrix.
I t e m I t e m 1 I t e m 2 … I t e m j … I t e m n I t e m 1 1 a 12 … a 1 j … a 1 n I t e m 2 a 21 1 … a 2 j … a 2 n ⋮ ⋮ ⋮  ⋮  ⋮ I t e m i a i 1 a i 2 … a i j … a i n ⋮ ⋮ ⋮  ⋮  ⋮ I t e m n a n 1 a n 2 … a n j … 1In Table1, aij is the semantic similarity between the item i and the itemj, which is obtained according to (8). The similarity matrix element satisfies the condition aij=aji. The ith row is the semantic nearest neighbors of the item i. Fuse the semantic neighbors with the item-based CF neighbors and then get the recommended list.


### 3.4. Fusion Semantic Neighbors

We supposeI is the set of items that the CF algorithm will recommend to users. Next, sort itemsi∈I in decreasing order of the similarity and then get a corresponding sequence L. Similarly,T is the set of semantic neighbors and also sorted in decreasing order and then get a corresponding sequence K. The elements j in K satisfy j∣j∈T,j∉I. Suppose l is the length of the sequenceL; the fusion ratio isp: q. The number of substitutions is n=l×p/p+q, where · is roundup function. Get the following fusion process.Algorithm 1 (fusion semantics neighbor algorithm).
Input
Collaborative Filtering Neighbor SetI, Semantic Neighbor SetT Output
Recommendation SetC (1)
SetL = list(I), K = list(T) (2)
ForLi ∈Ll-n,Ll-n+1,…,Ll do (3)
ForKj ∈K1,K2,…,Kn do (4)
L i = Kj (5)
End do (6)
End do (7)
SetC= set(L).Through Algorithm1, we get the final recommendation setC.


### 3.5. Algorithm Description

The algorithm flowchart is shown in Figure1; the algorithm description is as follows:Algorithm 2 (transE-CF algorithm).
Input
User-item rating matrixRm×n, knowledge graph KG Output
Collaborative filtering recommendation based on knowledge graph representation learning (1)
According to (2), calculate the similarity weight wij (i.e., simcos(A, B)); next, use (3) to calculate similarity weight after contraction w′ij; then generate the item-item similarity matrix, and use the Top-k recommendation algorithm to produce the k most similar items according to the similarities. (2)
Match the items with the entities in the KG and get the entity correspondence table. (3)
Transform the entities and relationships in the KG into the vector setE and the vector setR, respectively. (4)
According to the result of step(3), use (8) to calculate the semantic similarity simsem(A, B) and generate the semantic similarity matrix of the items and then use Top-k recommendation algorithm to produce the k most semantic similar neighbors. (5)
According to Algorithm1 and the result of step (2), select the fusion ratio and replace the recommended items generated in step (1) with the semantic similar neighbors generated in step (4). Finally, produce the recommended list and recommend to users.


## 3.1. Algorithm Framework

We propose a novel CF recommendation algorithm based on KG representation learning. Its basic idea is using the KG representation learning-TransE algorithm to obtain the semantic information of the item, calculating the semantic similarity between the items, integrating the semantic information of the item into the recommendation process, and producing the recommended list for users.In the traditional CF algorithms, they only use the external ratings information, such as user-item rating matrix, and the proposed algorithm adds internal knowledge (knowledge graph) into CF and will get better results and improve the recommended performance.We use the KG representation learning algorithm to embed entities into a low-dimensional vector space. Then calculate the semantic similarity between the entities and generate the semantic similarity matrix. Use Top-k algorithm to get the k nearest semantic neighbors of the items. At the same time, we use the user-item rating matrix to calculate the similarity between items and get the item-item similarity matrix and then use Top-k algorithm to get the k nearest neighbors of the items. Finally, adjust the fusion ratio, integrate the nearest semantic neighbors of the items with the CF nearest neighbors of the items, and produce the recommended list.The rich semantic information can alleviate the cold start problem in the recommender system. Figure1 shows the flowchart of proposed algorithm (TransE-CF).Figure 1
TransE-CF flowchart.


## 3.2. TransE Algorithm Based KG Representation Learning

The knowledge graph is a knowledge network and can be represented by a directed graph (or digraph) formed by the triples and the mutual links between the triples. The triplets carry the semantic information of the entity itself. Nodes represent the entities and edges represent the relationships between the entities.Taking the movie field as an example, the movie entity mainly includes the main features of it, such as actors, types, and directors. These features characterized the movies. Using the movie features, one can obtain a triplet of a movie knowledge graph. As shown in Figure2.Figure 2
Triples of knowledge graph.In Figure2, the movie entity and the actor entity are linked to form a triplet (M, starring_actor, A) and the knowledge graph is formed by the mutual linkage between the triplets. Figure 3 shows the structure of some selected movies and their attributes in the Freebase. In Figure 3, it can be seen that two nodes are closer in the knowledge graph and they are more similar in semantics. Therefore, in the movies recommendation, we can use the user’s rating information of the movie and the movie’s own semantic information. In the CF recommender system, if the ratings of the two items are similar, they are determined as neighbors. Similarly, if the movies are semantically similar in the knowledge graph, they can be judged as neighbors intuitively.Figure 3
Movie knowledge graph.Based on the above ideas, we use the TransE algorithm to integrate the items’ semantic information with the user-item rating matrix for recommendation. According to the definition of the TransE algorithm, triplet (h, r,andt) in the knowledge graph S can be trained using the loss function, defined as (4)L=∑h,r,t∈S∑h′,r,t′∈S′h,r,tγ+h+r-t-h′+r-t′+(5)S′h,r,t=h′,r,t∣h′∈E∪h,r,t′∣t′∈Ewhere(h′,r,t′) is the corrupted triple as negative training sample. The negative sample is the head entity or tail entity of the original correct triplet by randomly replacing it with other entities. γ is margin hyperparameter, denotes the size of the gap, and generally sets γ=1. ∙ is either the L1 or the L2-norm. [·]+ is the hinge loss function, as shown in(6)x+=x,x>00,x≤0where x+ denotes the positive part of x.We minimize the loss functionL over the training set, and the optimization is carried out by stochastic gradient descent (in minibatch mode), over the possibleh,r, andt, with the additional constraints that the L2-norm of the embeddings of the entities, are 1 (no regularization or norm constraints are given to the label embeddingsr).Throughout the training process, TransE uses the idea of maximum separation, pulling distances between positive and negative sample vectors to train and learn. The stochastic gradient descent is continuously iteratively degraded to optimize the loss function. The final training results are(1) similar semantic entities in the KG have closer distances in the low-dimensional space; (2) the head node’s vector plus the relational vector is basically equal to the tail node’s vector. The specific training process is described in [14].


## 3.3. Semantic Similarity Measure

TransE algorithm transforms entities into low-dimensional real-valued vectors. In the different KG representation learning methods, the meanings of the vectors are different and the similarity measures are different too. The representation of the vectors in the TransE algorithm is defined as(7)h+r≈twhereh and t are the head entity and the tail entity respectively and r is the relationship between the entities. The norm ∙ can be selected as the L2 norm.t should be a nearest neighbor of h+r. The closer the entities in the KG are, the more similar the vectors are, as shown in Figure 4.Figure 4
TransE model.Since the TransE algorithm chooses the Euclidean distance to calculate the loss function, we use the same norm Euclidean distance to measure the similarity between the entities, where the selected Euclidean distance range is [0, ∞) and the similarity measure range is[0,1]. For the two entity vectors A andB, through mathematical transformation, the two value domains are matched one by one by. The final semantic similarity measure is defined as (8)simsemA,B=1-A-BA-B+1=1A-B+1In(8), when the value of simsem (A, B) is closer to 1, the entity vectors A and B are more similar; that is, the relationship is closer in the KG. Conversely, if the value of simsem (A, B) is smaller, the more alienation relationship between A andB, and the lower semantic similarity between A andB.We use the semantic similarity for recommendation; the process is similar to the item-based CF recommendation. We use(8) to get the item-item semantic similarity matrix, as shown in Table 1.Table 1
Item-tem semantic similarity matrix.
I t e m I t e m 1 I t e m 2 … I t e m j … I t e m n I t e m 1 1 a 12 … a 1 j … a 1 n I t e m 2 a 21 1 … a 2 j … a 2 n ⋮ ⋮ ⋮  ⋮  ⋮ I t e m i a i 1 a i 2 … a i j … a i n ⋮ ⋮ ⋮  ⋮  ⋮ I t e m n a n 1 a n 2 … a n j … 1In Table1, aij is the semantic similarity between the item i and the itemj, which is obtained according to (8). The similarity matrix element satisfies the condition aij=aji. The ith row is the semantic nearest neighbors of the item i. Fuse the semantic neighbors with the item-based CF neighbors and then get the recommended list.


## 3.4. Fusion Semantic Neighbors

We supposeI is the set of items that the CF algorithm will recommend to users. Next, sort itemsi∈I in decreasing order of the similarity and then get a corresponding sequence L. Similarly,T is the set of semantic neighbors and also sorted in decreasing order and then get a corresponding sequence K. The elements j in K satisfy j∣j∈T,j∉I. Suppose l is the length of the sequenceL; the fusion ratio isp: q. The number of substitutions is n=l×p/p+q, where · is roundup function. Get the following fusion process.Algorithm 1 (fusion semantics neighbor algorithm).
Input
Collaborative Filtering Neighbor SetI, Semantic Neighbor SetT Output
Recommendation SetC (1)
SetL = list(I), K = list(T) (2)
ForLi ∈Ll-n,Ll-n+1,…,Ll do (3)
ForKj ∈K1,K2,…,Kn do (4)
L i = Kj (5)
End do (6)
End do (7)
SetC= set(L).Through Algorithm1, we get the final recommendation setC.


## 3.5. Algorithm Description

The algorithm flowchart is shown in Figure1; the algorithm description is as follows:Algorithm 2 (transE-CF algorithm).
Input
User-item rating matrixRm×n, knowledge graph KG Output
Collaborative filtering recommendation based on knowledge graph representation learning (1)
According to (2), calculate the similarity weight wij (i.e., simcos(A, B)); next, use (3) to calculate similarity weight after contraction w′ij; then generate the item-item similarity matrix, and use the Top-k recommendation algorithm to produce the k most similar items according to the similarities. (2)
Match the items with the entities in the KG and get the entity correspondence table. (3)
Transform the entities and relationships in the KG into the vector setE and the vector setR, respectively. (4)
According to the result of step(3), use (8) to calculate the semantic similarity simsem(A, B) and generate the semantic similarity matrix of the items and then use Top-k recommendation algorithm to produce the k most semantic similar neighbors. (5)
According to Algorithm1 and the result of step (2), select the fusion ratio and replace the recommended items generated in step (1) with the semantic similar neighbors generated in step (4). Finally, produce the recommended list and recommend to users.


## 4. Experimental Results

In this section, we detail our experiments and results. First, the datasets and evaluation metrics are introduced, followed by the experimental settings. Finally, the results and analysis of experiments are presented.


### 4.1. Data Sets

We use Amazon’s movie dataset in our experiments. It is provided by the University of California, San Diego. The dataset includes Amazon’s products ratings and their metadata. Each data record mainly describes the ratings of the movie by different users. The ratings scale from 1 to 5, which corresponds to the user’s review on the movie: 1 represents the least liked and 5 represents the most liked, at the same time, using metadata to map the movie ID in each record to the movie entity represented by the name of the movie in the knowledge graph.We select the movie ontologies in Freebase 2012-11-09 as knowledge graph dataset. The movie ontology data mainly includes ontology objects such as movies, directors, and actors. In order to fuse multiple ontology objects provided by Freebase, we replace Freebase’s own ID with the entity’s name and extract the entities and relationships. At the same time, in order to reduce the impact of noise data, we selected the movies released after 1979 in Freebase to match the Amazon’s ratings and filtered out the relationships with less than 3 occurrences and finally got a total of 20 semantic relationships of knowledge graph such as “genre” and “starring_actor” on.In order to better match Amazon rating data with the Freebase, we further processed the movie name. Because knowledge graph used unsupervised or semisupervised relation extraction methods [37–43], the extraction of movie names in Freebase is limited by this processing method. The problem is that the item names and the ontology entity names cannot be completely matched. For example, some movies use Roman numerals ‘II’, while others use Arabic numerals ‘2’. In another example, the movie ‘Here Comes the Groom (1934)’ and the movie ‘Here Comes the Groom’ are essentially the same movie but, due to the different version numbers, the Amazon movie name cannot completely match the Freebase movie name.To address above problems, we use the distance editing and string matching rule to preclean the data of the movie name such as version number deletion. Through the edit distance algorithm, the string literal similarity recognition of the original data is corrected and a good cleaning result is obtained. After the final processing, experimental datasets include 672 910 users’ data, 41 255 movies data, and 20 semantic relationships. We divide the datasets 80% as the training set and 20% as the testing set. The training set is used to construct user-item rating matrix. The testing set is used to test the performance of the algorithm.


### 4.2. Evaluation Metrics

In order to evaluate the recommended results, we use three metrics to measure them: Precision, Recall, and F-measure. These three metrics can be derived from the confusion matrix, as shown in Table2.Table 2
Confusion matrix.
System Users like Users dislike Recommended TP FP No recommended FN TNAccording to the confusion matrix, there are formulas as follows:Recall:(9)Recall=TPTP+FNPrecision:(10)Precision=TPTP+FPF-measure:(11)F-measure=2×Precision×RecallPrecision+RecallRecall denotes the proportion of the user’s actual liked items in the recommended list. Precision denotes the recommended level of the recommender system. F-measure is a weighted average of Precision and Recall and evenly reflects the performance of recommendation.


### 4.3. Experimental Settings

The experimental hardware environment is Intel(R) Core (TM) i7-6700 with 8 GB of memory; the experimental software environment is Python 3.5.


### 4.4. Results and Analysis

#### 4.4.1. Comparisons of Different Fusion Ratios

In the proposed algorithm, we adjust the fusion ration as the parameter. The fusion ratio takes different values; recommended results are also different. We set Top-k k = 100, representation learning embedding dimension is 200, and the fusion ratio scale from (0:10) to (10:0) represents from fully using the semantics for recommendation to fully using collaborative filtering for recommendation. Figures 5–7 are Recall curve, Precision curve, and F-measure curve, respectively. For each set of experiments, iterate 10 times and take the average value.Figure 5
Recall at k=100.Figure 6
Precision at k=100.Figure 7
F-measure at k=100.From Figures5–7, it can be seen that with the increase of the fusion ratio, Recall, Precision, and F-measure all increased and reached the peak at a fusion ratio of 5:5. Fork = 100, the best fusion ratio is 5:5.


#### 4.4.2. Comparisons of Different Embedding Dimensions

The knowledge graph representation learning is to embed the knowledge graph into a low-dimensional space; different dimensions have different effects. In the proposed algorithm, different dimensions have different recommended performance. In the TransE learning algorithm, initialize the triplet (h, r, and t) needed to set the embeddings dimension k. We select experimental dimension from 100 to 500. For each set of experiments, iterate 10 times and take the average value.Figures8–10 show different recommended performance in different dimensions. It can be seen that when embedding dimension is 200, recommended performance is the best.Figure 8
Recall in different dimensions.Figure 9
Precision in different dimensions.Figure 10
F-measure in different dimensions.


#### 4.4.3. Comparisons of Different Algorithms

We select the fusion ratio with the highest F-measure as a representative and compare with other collaborative filtering recommendation algorithms. We select the embedding dimension is 200,k-nearest neighbor is 60, 80, 100, and 120 respectively. For each set of experiments, iterate 10 times and take the average value.From Figures11–13, it can be seen that the collaborative filtering recommendation algorithm based on knowledge graph is superior to the other collaborative filtering recommendation algorithm. The use of semantic information can improve the recommended performance to a certain extent and also get higher values on Recall, Precision, and F-measure, respectively. It can compensate the lack of semantic in the item-based collaborative filtering algorithms.Figure 11
Recall with differentk values.Figure 12
Precision with differentk values.Figure 13
F-measure with differentk values.


## 4.1. Data Sets

We use Amazon’s movie dataset in our experiments. It is provided by the University of California, San Diego. The dataset includes Amazon’s products ratings and their metadata. Each data record mainly describes the ratings of the movie by different users. The ratings scale from 1 to 5, which corresponds to the user’s review on the movie: 1 represents the least liked and 5 represents the most liked, at the same time, using metadata to map the movie ID in each record to the movie entity represented by the name of the movie in the knowledge graph.We select the movie ontologies in Freebase 2012-11-09 as knowledge graph dataset. The movie ontology data mainly includes ontology objects such as movies, directors, and actors. In order to fuse multiple ontology objects provided by Freebase, we replace Freebase’s own ID with the entity’s name and extract the entities and relationships. At the same time, in order to reduce the impact of noise data, we selected the movies released after 1979 in Freebase to match the Amazon’s ratings and filtered out the relationships with less than 3 occurrences and finally got a total of 20 semantic relationships of knowledge graph such as “genre” and “starring_actor” on.In order to better match Amazon rating data with the Freebase, we further processed the movie name. Because knowledge graph used unsupervised or semisupervised relation extraction methods [37–43], the extraction of movie names in Freebase is limited by this processing method. The problem is that the item names and the ontology entity names cannot be completely matched. For example, some movies use Roman numerals ‘II’, while others use Arabic numerals ‘2’. In another example, the movie ‘Here Comes the Groom (1934)’ and the movie ‘Here Comes the Groom’ are essentially the same movie but, due to the different version numbers, the Amazon movie name cannot completely match the Freebase movie name.To address above problems, we use the distance editing and string matching rule to preclean the data of the movie name such as version number deletion. Through the edit distance algorithm, the string literal similarity recognition of the original data is corrected and a good cleaning result is obtained. After the final processing, experimental datasets include 672 910 users’ data, 41 255 movies data, and 20 semantic relationships. We divide the datasets 80% as the training set and 20% as the testing set. The training set is used to construct user-item rating matrix. The testing set is used to test the performance of the algorithm.


## 4.2. Evaluation Metrics

In order to evaluate the recommended results, we use three metrics to measure them: Precision, Recall, and F-measure. These three metrics can be derived from the confusion matrix, as shown in Table2.Table 2
Confusion matrix.
System Users like Users dislike Recommended TP FP No recommended FN TNAccording to the confusion matrix, there are formulas as follows:Recall:(9)Recall=TPTP+FNPrecision:(10)Precision=TPTP+FPF-measure:(11)F-measure=2×Precision×RecallPrecision+RecallRecall denotes the proportion of the user’s actual liked items in the recommended list. Precision denotes the recommended level of the recommender system. F-measure is a weighted average of Precision and Recall and evenly reflects the performance of recommendation.


## 4.3. Experimental Settings

The experimental hardware environment is Intel(R) Core (TM) i7-6700 with 8 GB of memory; the experimental software environment is Python 3.5.


## 4.4. Results and Analysis

### 4.4.1. Comparisons of Different Fusion Ratios

In the proposed algorithm, we adjust the fusion ration as the parameter. The fusion ratio takes different values; recommended results are also different. We set Top-k k = 100, representation learning embedding dimension is 200, and the fusion ratio scale from (0:10) to (10:0) represents from fully using the semantics for recommendation to fully using collaborative filtering for recommendation. Figures 5–7 are Recall curve, Precision curve, and F-measure curve, respectively. For each set of experiments, iterate 10 times and take the average value.Figure 5
Recall at k=100.Figure 6
Precision at k=100.Figure 7
F-measure at k=100.From Figures5–7, it can be seen that with the increase of the fusion ratio, Recall, Precision, and F-measure all increased and reached the peak at a fusion ratio of 5:5. Fork = 100, the best fusion ratio is 5:5.


### 4.4.2. Comparisons of Different Embedding Dimensions

The knowledge graph representation learning is to embed the knowledge graph into a low-dimensional space; different dimensions have different effects. In the proposed algorithm, different dimensions have different recommended performance. In the TransE learning algorithm, initialize the triplet (h, r, and t) needed to set the embeddings dimension k. We select experimental dimension from 100 to 500. For each set of experiments, iterate 10 times and take the average value.Figures8–10 show different recommended performance in different dimensions. It can be seen that when embedding dimension is 200, recommended performance is the best.Figure 8
Recall in different dimensions.Figure 9
Precision in different dimensions.Figure 10
F-measure in different dimensions.


### 4.4.3. Comparisons of Different Algorithms

We select the fusion ratio with the highest F-measure as a representative and compare with other collaborative filtering recommendation algorithms. We select the embedding dimension is 200,k-nearest neighbor is 60, 80, 100, and 120 respectively. For each set of experiments, iterate 10 times and take the average value.From Figures11–13, it can be seen that the collaborative filtering recommendation algorithm based on knowledge graph is superior to the other collaborative filtering recommendation algorithm. The use of semantic information can improve the recommended performance to a certain extent and also get higher values on Recall, Precision, and F-measure, respectively. It can compensate the lack of semantic in the item-based collaborative filtering algorithms.Figure 11
Recall with differentk values.Figure 12
Precision with differentk values.Figure 13
F-measure with differentk values.


## 4.4.1. Comparisons of Different Fusion Ratios

In the proposed algorithm, we adjust the fusion ration as the parameter. The fusion ratio takes different values; recommended results are also different. We set Top-k k = 100, representation learning embedding dimension is 200, and the fusion ratio scale from (0:10) to (10:0) represents from fully using the semantics for recommendation to fully using collaborative filtering for recommendation. Figures 5–7 are Recall curve, Precision curve, and F-measure curve, respectively. For each set of experiments, iterate 10 times and take the average value.Figure 5
Recall at k=100.Figure 6
Precision at k=100.Figure 7
F-measure at k=100.From Figures5–7, it can be seen that with the increase of the fusion ratio, Recall, Precision, and F-measure all increased and reached the peak at a fusion ratio of 5:5. Fork = 100, the best fusion ratio is 5:5.


## 4.4.2. Comparisons of Different Embedding Dimensions

The knowledge graph representation learning is to embed the knowledge graph into a low-dimensional space; different dimensions have different effects. In the proposed algorithm, different dimensions have different recommended performance. In the TransE learning algorithm, initialize the triplet (h, r, and t) needed to set the embeddings dimension k. We select experimental dimension from 100 to 500. For each set of experiments, iterate 10 times and take the average value.Figures8–10 show different recommended performance in different dimensions. It can be seen that when embedding dimension is 200, recommended performance is the best.Figure 8
Recall in different dimensions.Figure 9
Precision in different dimensions.Figure 10
F-measure in different dimensions.


## 4.4.3. Comparisons of Different Algorithms

We select the fusion ratio with the highest F-measure as a representative and compare with other collaborative filtering recommendation algorithms. We select the embedding dimension is 200,k-nearest neighbor is 60, 80, 100, and 120 respectively. For each set of experiments, iterate 10 times and take the average value.From Figures11–13, it can be seen that the collaborative filtering recommendation algorithm based on knowledge graph is superior to the other collaborative filtering recommendation algorithm. The use of semantic information can improve the recommended performance to a certain extent and also get higher values on Recall, Precision, and F-measure, respectively. It can compensate the lack of semantic in the item-based collaborative filtering algorithms.Figure 11
Recall with differentk values.Figure 12
Precision with differentk values.Figure 13
F-measure with differentk values.


## 5. Conclusion and Future Work

In this paper, we proposed a similarity model based on knowledge graph representation learning. The proposed similarity model can select different neighbors which have higher similarity with the target user for each different target item and take the semantic similarity into account.First, we used the knowledge graph representation learning-TransE algorithm to obtain the semantic information of the items; next, calculated the semantic similarity between the items, then integrated the semantic information of the items into the recommendation process, and finally produced the recommendation list for users.Experimental results showed that our method obtained significantly better prediction accuracy in dealing with both general situation and cold start situation, compared with state-of-the-art CF methods.In future work, we plan to apply the algorithm to the content outside the movies for recommendation and further optimize the performance of recommendation.



---

*Source: 9617410-2018-07-31.xml*