# Recommendation Algorithm Based on Heterogeneous Information Network and Attention Mechanism
## 3 Main Model
### Node and Neighbor Information Embedding  
To learn the attribute information of users and items in the heterogeneous information network, this model uses HIN2 vec [34] to represent the nodes in the heterogeneous  
Figure 3: The overall framework of NMRec model.  
information network as low \(u\) dense vectors, and \(x_{u}\), \(y_{i}\) are the learned characteristic vector embedding of users \(u\) and items \(i\).  
After obtaining the user and item node embedding, we need to study how to extract the missing information of users and items more efficiently. We consider that in practical recommendation tasks, people who become friends often have similar interests, and each user is influenced by the preferences of family, friends, and colleagues. Therefore, we extract the nodes' one-hop neighbor information to supplement the nodes' missing information. In this paper, we calculate the cosine similarity of vectors between nodes and establish the connected edges between nodes to aggregate the user and item one-hop neighbor information according to the similarity.  
Since the one-hop neighbor links only account for a small percentage, they are not enough to represent the global information of users and items. Considering that in social networks, two people have more identical friends, then the probability of becoming friends between them is greater. Therefore, this paper introduces the two-hop neighbor information to supplement the richness of the recommendation algorithm and mine the users' real interest. This cannot be satisfied only by the one-hop neighbor information; that is, the more similar users are not necessarily the better, and complementary users can sometimes provide more useful information. Let \(P_{u}=(w_{u^{1}},\ldots,w_{u^{|v|}})\) denote the first-order proximity of node \(u\) to other vertices. Then, the second-order proximity between \(u\) and \(v\) is determined by the cosine similarity between \(p_{u}\) and \(p_{v}\). The connected edges between nodes are built based on the similarity to aggregate the second-hop neighbor information of users and items.  
In real life, the friends and family that have the greatest impact on users are concentrated in the scope of second-hop neighbors, and beyond the second-hop neighbors, there is almost no influence on the node. In addition, considering the amount of data, processing speed, and other factors, users and items are only aggregated to the second-hop neighbor information. In this paper, referring to the network node aggregation method of HAN [17], we first convert the neighbor information into feature vectors with the same dimensionality. After that, considering that different nodes have different importance to different users and items, we use the attention mechanism to learn the weight size of each node. Then, _Softmax_ normalizes the user and item information with a function that imposes the attention mechanism to obtain weight coefficients of each feature vector. Finally, we obtain the node aggregation representation, calculated as:  
\[U=\sigma\left(\sum_{i\in N^{\prime}(u)}e_{i}M_{u}\right) \tag{1}\]  
\[I=\sigma\left(\sum_{j\in N^{\prime}(i)}e_{j}M_{i}\right) \tag{2}\]  
where \(M_{u}\) and \(M_{i}\) are learnable parameters, \(N^{\prime}(u)\) denotes the one-hop and two-hop neighbor information of user and user, and \(N^{\prime}(i)\) denotes the one-hop and two-hop neighbor information of item and item. The aggregated one-hop neighbor information of the user and item are \(U_{1}\) and \(I_{1}\), and the aggregated two-hop neighbor information of the user and item are \(U_{2}\) and \(I_{2}\).