# Research of Personalized Recommendation Technology Based on Knowledge Graphs
## 4 Movie Recommendation Model Based on Knowledge Graph Representation Learning
### KG-NN Recommend Model  
This section proposes a movie recommendation algorithm that combines knowledge graphs and neural network, referred to as KG-NN.  
The main steps of the KG-NN algorithm are as follows: we first use the improved TransE representation learning method in Section 4 to obtain the entity vector and the relation vector. After the embedding layer, the user data and movie data are, respectively, generated corresponding embedding vectors. Then input the movie entity vector generated by the learning process as auxiliary information into the neural network together. After that, it is the MLP fully connected layer, ReLU activation function and so on. In order to predict the user's interest in the movie, we combined the user-movie real rating data and Adam optimization method for iterative training. Finally, the rating values of the model training are used to sort from large to small to generate a movie recommendation list.  
The flow chart of the KG-NN model in the movie recommendation process of this article is shown in Figure 10. The input of the KG-NN model mainly has two types. The first type is the embedding vector generated by the basic user data and movie data through the embedding layer. The second type is the movie entity vector generated by the improved TransE representation learning algorithm.  
According to the above introduction, we have generated the embedding vector corresponding to the user data and the movie data. We stitch the movie data embedding vector and the movie entity vector horizontally, then stitch it horizontally with the user data embedding vector and input it into the fully connected layer. Through the fully connected neural network for dimensional transformation and feature extraction, we can learn the hidden vectors of users and movies and retain useful information in the neural network. A ReLU function is immediately followed by each fully connected layer.  
Finally, the output value obtained by the last fully connected layer of the model is returned to between zero and one after the sigmoid function, as shown in the following formula. Since users in the movie data set rated movies on a five-point scale, we also normalized it to a value between zero and one to get \(y_{t}\).  
\[{y_{p}}^{(i)}=sigmoid(x_{i})=\frac{1}{1+e^{-x_{i}}} \tag{24}\]  
Among them, \(x_{i}\) represents the weighted output of the last fully connected layer. Then compare it with the normalized user-movie rating data \(y_{t}\), and use cross entropy as the loss function. The entire model is trained iteratively with Adam optimizer. The loss function is shown in Formula (25).  
\[Loss=-\frac{1}{n}\sum_{i=1}^{n}({y_{t}}^{(i)}\log{y_{p}}^{(i)}+(1-{y_{t}}^{(i)})\log( 1-{y_{p}}^{(i)})) \tag{25}\]  
Among them, \(y_{p}\) is the predicted score of the KG-NN model. \(y_{t}\) is the normalized real score, and \(n\) is the total number of user-movie score data in the training set.  
In order to prepare for the final movie recommendation, the model needs to predict the rating value of the movie for each user, and decide whether to recommend the movie to the user according to the calculated score.  
We finally get the parameters of the entire KG-NN model. When performing TOP-N recommendation, we use the entire model to predict the user's ratings of unseen movies. We sort the predicted ratings in descending order, and extract the top N after sorting [36]. Movies are recommended to users as a recommendation list.