Background
With the advent of the big data era and the explosion of the internet, electronic commerce has come. On the E-commerce platform, users are often difficult to decide about the full-color products, and the recommendation algorithm can utilize data accumulated by the E-commerce platform, including data of purchasing, grading, commenting and the like of the users, to mine potential interests of the users, so as to recommend corresponding products. An excellent recommendation algorithm aims to perform personalized accurate recommendation on a user and provide corresponding explanation, so that the user experience can be improved, and the benefit of an e-commerce platform can be increased. For the user, explanation is provided for the user, the purchase quantity of the commodity can be increased, and the user experience can be improved; for the E-commerce platform, user interest and hobbies and purchasing preference are mastered, so that a user portrait can be constructed for a user, personalized marketing is performed on the user, and the conversion rate of user behaviors is improved. Therefore, the invention of an excellent interpretable recommendation algorithm has important practical significance by utilizing accumulated data of the commercial platform.
In the current recommendation system, one of the common methods is: and carrying out score prediction on the commodities by utilizing the historical behavior data of the user, and recommending the commodities to the user according to the predicted scores. The scoring prediction method mainly comprises the following steps: the first is a traditional matrix decomposition model that uses a scoring matrix to predict the missing scores and generate recommendations. The method only utilizes the historical scoring data of the user, obtains less characteristics of user preference and article attributes, and lacks interpretability. The second type is a model combining a topic model and matrix decomposition, which simultaneously utilizes historical scores and comment data of a user, and the topic model is used for extracting topics in comments so as to provide certain interpretability. But the shortcomings are that the processing of comments by the topic model is simple word extraction, the consideration of the time sequence characteristics of words is lacked, and the topic model is difficult to solve for large-scale data.
The invention provides a commodity recommendation method combining an attention network and user emotion. The method utilizes the memory network and the recurrent neural network to process the comments so as to extract the characteristics, wherein the result of the memory network is used as the attention of the recurrent neural network, so that certain interpretability is provided for the method; meanwhile, different weights are applied to different comments by utilizing the predicted emotion scores, and the interpretability of the recommendation method is further increased. Therefore, the accuracy of the scoring prediction is improved, and the problems that the traditional scoring prediction recommendation method is lack of interpretability and large-scale data is difficult to process are solved.
Disclosure of Invention
The invention aims to overcome the defects of the prior art, provides a commodity recommendation method combining an attention network and user emotion, solves the problems of insufficient interpretability and difficulty in processing big data of the traditional scoring prediction method, improves the scoring prediction accuracy, and increases the interpretability of the method. The method utilizes the grading and comment data of the commodities to construct a user preference vector and a commodity feature vector, predicts the missing grade and provides a recommendation explanation.
In order to achieve the purpose, the technical scheme provided by the invention is as follows: a commodity recommendation method combining attention network and user emotion comprises the following steps:
1) processing historical behavior data of a user in an e-commerce platform, mainly extracting grading and comment data of the user on commodities, including comment text data, preprocessing the comment data, and constructing a sample set T;
2) continuously training by adopting an unsupervised learning model and utilizing text data commented in the sample set T to finally obtain an attribute matrix W of the sample set T;
3) constructing an attention-based neural network structure C, using a memory network and a cyclic neural network based on an attribute matrix W as a basis, using predicted emotion scores as weights, further constructing a user preference vector U and a commodity feature vector I, finally calculating predicted values of deletion scores by using the user preference vector U and the commodity feature vector I, and meanwhile calculating attribute vectors of current users and commodities for final recommendation interpretation;
4) and performing descending sorting according to the predicted scores, recommending the first N commodities for the user, and providing attribute level explanation for the recommendation result according to the attribute matrix W obtained in the step 2) and the attribute vector obtained in the step 3).
In the step 1), grading and comment data of a user on commodities are extracted from user historical behavior data in an e-commerce platform, manual rules are formulated, part of useless data are filtered out, and the comment data are preprocessed and divided into two parts, wherein the first part is used for mapping the ID of the user and the ID of the commodities into numerical values so as to facilitate subsequent use, the second part is used for performing word segmentation processing on the text data of comments and mapping words in the text data into word vectors, and a sample set T is finally obtained after data preprocessing.
In the step 2), text data of all comments in the sample set T is utilized, an unsupervised learning model is adopted to learn an attribute matrix W, the attribute matrix W is initialized randomly at first, an average word vector e is obtained through word vectors of the comments, weights corresponding to the word vectors are obtained according to the association condition of the average word vector e and each word vector in the comments, and the word vectors in the comments are weighted and summed to construct an original vector z of the comments; and then constructing a reconstruction vector r of the comment from the attribute matrix W according to the original vector z, training by taking a difference value between the reconstruction vector r and the original vector z as a target function, and finally obtaining the attribute matrix W of the field corresponding to the sample set T, wherein each dimension of the attribute matrix W represents a corresponding attribute vector.
In the step 3), constructing an attention-based neural network structure C which mainly comprises a memory network and a circulating neural network; for the sample set T, taking the text data of the comments in T as the input of C, and taking the real scoring data in T as the learning target of C; for the appointed users and commodities, firstly processing each comment by using a memory network and a recurrent neural network based on an attribute matrix W, processing the comment by using the memory network, obtaining an attribute vector a from the attribute matrix W, taking the attribute vector a as the attention of a recurrent neural network hidden layer to obtain the output v of the recurrent neural network, and connecting a and v to obtain a corresponding comment vector, wherein in the process, the attribute vector a is used as the attention so that the recurrent neural network can capture the local information related to a in the comment to increase the interpretability, then on the basis that different comments have different degrees of emotion, different weights are given to each comment vector according to the predicted emotion scores to further construct a user preference vector U and a commodity feature vector I, and meanwhile, an attribute vector f for the current users and commodities can be constructed according to the emotion scores, the emotion scores are used, so that comments with higher emotion scores have higher weights, and more information is provided for the construction of U or I, so that the interpretability is further increased; finally, the scores of the current user and the current commodity are predicted by utilizing the user preference U and the commodity feature vector I; this step increases the interpretability of the recommendation method through the use of attention mechanisms and sentiment scores.
In step 4), for a specific user, carrying out score prediction on the commodity set by using the attention-based neural network structure C trained in step 3), sorting the commodity set in a descending order according to scores, and taking the top N commodities as a recommended commodity list for the user; meanwhile, for the recommended commodities, the closest attribute vector is selected from the attribute matrix W obtained in the step 2) according to the attribute vector f calculated in the step 3), wherein each attribute vector corresponds to a specific attribute, and the attribute is used as the recommendation reason of the current commodities, so that the user experience is increased, and the purchase rate of the current commodities can also be improved.
Compared with the prior art, the invention has the following advantages and beneficial effects:
1. according to the method, the score and the comment data of the commodity are reasonably utilized, the missing score is predicted, and compared with a traditional score prediction algorithm, the accuracy of prediction is improved.
2. According to the invention, the attributes in the comment data are obtained through an unsupervised learning method, so that the process of manual labeling is reduced, manual intervention is reduced, and the model is easier to use and operate.
3. The comment data processing method and the comment data processing device simultaneously utilize the memory network and the recurrent neural network to construct a new network to process the comment data, capture the time sequence information of words in the comment and obtain the implicit characteristics of corresponding attribute levels compared with the traditional processing modes such as a theme model. And the problem that the subject model cannot process large-scale data is solved.
4. In the process of generating the prediction scores by the neural network structure, the invention uses the attention mechanism and the sentiment scores, increases the interpretability of the method, acquires the attribute characteristics from the comments and provides attribute level explanation for the final commodity recommendation.
Detailed Description
In order to describe the present invention more specifically, a detailed description of the embodiments of the present invention will be given below with reference to the drawings and examples.
In this embodiment, a commodity recommendation method combining an attention network and user emotion is used to recommend a corresponding commodity to a user by using the scoring and comment data of commodities in an e-commerce platform, an overall flow of the method is shown in fig. 1, and the method mainly includes the following steps:
firstly, data collection and preprocessing:
the data of the embodiment is based on real historical data of the e-commerce platform, firstly, grading and comment data of users are collected from a large amount of historical behavior data of the users, and then filtering is carried out, wherein the specific filtering mode is that less than 5 pieces of user data of grading and comment behaviors are removed. After data collection, preprocessing of the data is required, which is mainly divided into two parts: the first part is that the ID of the user and the ID of the commodity are respectively mapped into numerical values so as to facilitate subsequent use; the second part is to preprocess the text data of the comment, in the embodiment, a stop word list is added through a jieba word segmentation tool, and the text data of the comment is segmented, so that the comment is composed of a plurality of words. And mapping all words into word vectors by utilizing the thought of word2vec and training in the word library of the whole comment, wherein the dimension of the word vectors is d. And finally forming a sample set T after preprocessing of data.
Secondly, constructing an attribute matrix W
This section corresponds to section S2 in fig. 1, and the flow thereof is shown in fig. 2. And training to obtain an attribute matrix W by using text data of comments in the T through an unsupervised learning model.
Firstly, randomly initializing an attribute matrix W, wherein the size of the attribute matrix W is k multiplied by d, k is the number of attributes, and d is the size of each attribute vector and is the same as the size of a word vector; and then training with the text data of all comments in T. The specific operations in this embodiment are: for the unsupervised learning model, each time a comment is input, an average word vector e is obtained by calculation according to all word vectors in the comment, then matrix mapping is carried out on the average word vector e and each word vector to obtain the weight of each word vector by calculation, and finally the original vector z of the comment is obtained by weighting. And then calculating the weight p of each attribute vector in the W by using the original vector z of the comment in the following calculation mode:
p=softmax(Wa·z+b)
wherein, WaFor the weight matrix, b is the bias term, and the softmax function computes the weights for each dimension of the vector, which is defined as follows:
wherein x isiFor the ith dimension of the x vector, after a weight vector p is calculated, a reconstructed vector r of the comments is obtained by weighting and summing each attribute, wherein r is generated based on the attribute matrix. The calculation method is as follows:
r=WT·p
wherein, WTFor the transpose of the attribute matrix W, p is the weight of each attribute vector.
And finally, training by using the difference between the reconstructed vector r of the comment and the original vector z of the comment as an objective function of the model to obtain a final attribute matrix W. And calculating 100 word vectors similar to the attribute vector from each dimension vector of the W to represent one attribute, thereby manually obtaining the specific attribute corresponding to each dimension vector in the W. (for example in the field of cell phones, the acquisition attribute might be camera, CPU, screen, etc.)
Thirdly, combining attention network and user emotion score prediction
This section corresponds to the section S3 in fig. 1, and the processing flow thereof is shown in fig. 3. The method mainly utilizes the comment and the grading data of the commodity to further construct a user preference vector U and a commodity feature vector I, and then uses the idea of a hidden factor model to obtain the final prediction grade.
The whole neural network structure is a parallel structure, the processing modes of users and commodities are similar, and only the learned parameters are different. For a specific user, assuming that there are m comments, processing each comment by the memory network and the recurrent neural network together to capture hidden information in the comment, and representing the parts of the memory network and the recurrent neural network by the neural network structure a, the schematic structural diagram is shown in fig. 4:
firstly, an average word vector e is obtained according to the word vectors in the comments, then e is used as a query vector of the memory network, a parameter matrix is initialized to be used as a key matrix K of the memory network, and a previously trained attribute matrix W is used as a value matrix of the memory network. And obtaining the weight of each attribute of the attribute matrix W from the key matrix K through the query vector e, and further carrying out weighted summation on each attribute vector in W to obtain an attribute vector a of the comment. Then, the word vectors in the comment are input into a recurrent neural network LSTM, and each word vector obtains a corresponding hidden layer vector h. And taking the attribute vector a obtained by the last step as attention, taking the correlation degree between the attribute vector a and the hidden layer vector h as a score, further calculating the weight of each hidden layer vector h, and weighting and summing all the hidden layer vectors h to obtain a vector v. And finally, connecting the vector a and the vector v to obtain a final comment vector l.
After the common processing of the memory network and the recurrent neural network, each comment is to obtain a comment vector l. Different reviews have different degrees of importance to the user, and each review vector contributes differently to the formation of the end user preference vector. Therefore, the score of each comment is mapped into the emotion score of the user for each comment, wherein the emotion score is 1 when the emotion score is higher than three points, and the emotion score is 0 when the emotion score is other points; and obtaining an emotion score vector s, wherein the size of the emotion score vector s is the number m of the comments, and the emotion score vector s ' is used as an emotion score label for training, wherein s ' is a predicted emotion score vector, the calculation method uses the idea of a latent semantic model for reference, and a sigmoid function is used for mapping the emotion score into a section from 0 to 1 for convenience of calculation as a weight, so that s ' can be calculated by the following formula:
s′=sigmoid(qu T·pi+bu+bi+μ)
wherein q isuAs hidden vectors of the user, piIs an implicit vector of the commodity, mu is a global bias term, buBiasing terms for the user, biBiasing the items for the good. And the sigmoid function is defined as follows:
wherein e is a natural base number. And then, endowing each comment with different weights by using a softmax function, wherein a weight vector g of each comment is calculated by the following formula:
g=softmax(s′)
wherein the softmax function is defined in accordance with the softmax function in the second step.
According to the weight vector g, all comment vectors are subjected to weighted summation to finally obtain a current user preference vector U, and according to the emotion weight vector g, a final attribute vector a for the user can also be obtainedu. For the commodity, the processing modeSimilarly, a commodity feature vector I and an attribute vector a for the commodity are finally obtainedi. To auAnd aiAnd averaging to obtain an attribute vector f for the user u and the commodity i. In this step, the attribute vector is used as the attention of the recurrent neural network, and the sentiment score is used as the weight of each comment, so that the interpretability of the method is increased, and the recommendation method is more convincing.
For user u and item i, the prediction scores are
The calculation formula is as follows:
where μ is the global bias term, buBiasing terms for the user, biAnd U is a commodity bias item, and I is a commodity feature vector.
For the whole neural network, a squared error loss function is adopted as a final objective function L, which is defined as follows:
where T is the entire training set, r
u,iIn order to be a true score, the score,
is the predicted score. And Ω (θ) is a regular term of L2, where θ is a parameter set and λ is a coefficient of a regular term of L2.
And (4) obtaining a parameter set theta which is continuously updated through iterative training, and finally obtaining a final attention-based neural network C for predicting the score.
Fourthly, recommendation and explanation are provided
And for a specific user, carrying out score prediction on the commodity set by using the attention-based neural network structure C trained in the S3, sorting the commodity set in a descending order according to the scores, and taking the top N commodities as a recommended commodity list for the user. At the same time, for the recommended product, any one of the attributes is selected from the attribute matrix W based on the attribute vector f calculated in S3, and the reason for recommending the current product is, for example: "recommend commodity a to you because commodity a has excellent attribute B, and you pay more attention to attribute B", this process increases user experience, and can also improve the purchase rate of the current commodity.
The above-mentioned embodiments are merely preferred embodiments of the present invention, and the scope of the present invention is not limited thereto, so that the changes in the shape and principle of the present invention should be covered within the protection scope of the present invention.