A social network user cognitive state characterization method based on self-attention neural network
Patent Information
- Application Number
- CN202310199714.9
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2023-03-05
- Publication Date
- 2026-10-20
- Estimated Expiration
- 2043-03-05
AI Technical Summary
[0004]如今海量的交互数据,增大了社交网络用户认知状态刻画技术实现的难度
[0015]1)提出了一种基于自注意力神经网络的社交媒体用户认知状态刻画方法,首先搭载了微博数据采集引擎,传统的数据获取方法成本偏高且花费时间很长,此发明可以快速、大量的获取社交媒体网络用户数据,方便模型更好的建立用户认知状态。2)使用自注意力神经网络(transformer)与前馈神经网络相结合,解决了社交媒体网络用户文本数据这种序列信息表征能力不强的问题,此发明可以更好的关注文本数据的总体特征,并且准确的映射到预定的场景空间中,也能够根据不同的场景输出情感极性,利于用户认知状态的构建。3)利用可视化的方法,将预定场景标签与态度相结合,综合考虑用户基本信息,实现多维度用户认知状态的展示。
Smart Images

Figure CN116561441B_ABST
Abstract
Description
Technical Field
[0001] This invention, based on social network data and a self-attention neural network model, studies a method for characterizing user cognitive states. First, web crawling technology is used to acquire social media network user data. Then, a self-attention neural network (transformer) is used to extract deep semantic features from the dataset. Next, a feedforward neural network is used to classify the extracted deep semantic features according to predefined categories. Finally, a trained neural network model is used to characterize user cognitive states on social media network data based on the ABC theory of emotion. This invention belongs to the field of computer natural language processing, specifically involving web crawling, deep learning, and other technologies. Background Technology
[0002] User cognitive state profiling, as a precise depiction of user behavior, helps to understand user needs and preferences, improve personalized services, and has been widely applied in various fields. User cognitive state is a digitalized user image and a tagged comprehensive picture of the user in the computer world. It involves processing and analyzing data on real-world users' demographic attributes, behavioral habits, social networks, personality traits, psychological cognition, interests, and emotional changes, abstracting and refining information tag combinations. Moreover, according to the ABC theory of emotion, individual cognitive state is one of the important factors influencing their emotions. The same event may evoke different emotions in different people, mainly due to differences in their cognitive states. Therefore, emotion is an explicit expression of a user's cognitive state, and cognitive state is one of the causes of emotion. Based on users' emotional expressions regarding a large number of events, it is possible to estimate the common cognitive states behind the corresponding emotions. In recent years, the rapid development of internet technology and the rise of various social networking platforms have fundamentally changed people's previous ways of information exchange, communication, and leisure. Social networks have gradually become the main carriers of information sharing, experience exchange, and public opinion. In the era of big data, personalized services centered on "user" have enormous potential. User cognitive state, as a technology that can quickly and accurately analyze user behavior patterns and represent user characteristics, has become a research hotspot in the field of social media computing, attracting widespread attention from industry and academia.
[0003] Methods for constructing user cognitive states can be categorized into three types: 1) Topic-based user cognitive construction methods, whose basic idea is that a document is a collection of multiple topics, such as the classic LDA model and the three-layer Bayesian probability model, which includes a three-layer structure of words, topics, and documents; 2) User behavior and interest-based cognitive construction methods, which utilize user behavior logs on online platforms. Through mathematical modeling, user behavior is analyzed to establish user interest and consumption profiles, or decision trees and Bayesian networks are used to model user consumption habits and interests; 3) User cognitive construction methods based on personality traits and user emotions combine users' personal characteristics and emotional information. Research has found that users with extroverted personalities exhibit a higher number of online behaviors on social networking platforms. Introducing user emotions into the construction of user cognitive states can analyze and predict user behavior.
[0004] The sheer volume of interactive data today increases the difficulty of characterizing the cognitive states of users on social networks. Meanwhile, social forums and websites (such as Weibo, WeChat, and forums) are user-centric social networking platforms with a large number of high-quality users. Users on these platforms can share content, express opinions, and convey emotions and preferences. Therefore, this invention aims to use social network platforms as a data source for collection, cleaning, and analysis, combining this with deep learning technology to deeply mine massive amounts of user data. Based on the ABC theory of emotion, the data will be categorized for different scenarios and events, and user emotions will be analyzed according to these scenarios to construct the user's cognitive state. Summary of the Invention
[0005] This invention differs from existing methods for characterizing user cognitive states by proposing a method combining big data processing and deep learning technology. Furthermore, based on the ABC theory of emotion, a user's emotion towards an event is the result of the interaction between their cognitive state and the context. Different people experience different emotions in the same context because their cognitive states differ. Therefore, this invention considers a user's emotion towards a context as an explicit expression of their cognitive state, thus characterizing the user's cognitive state. First, it utilizes web crawling technology for large-scale user data collection, proposing a social network data acquisition method: collecting microblog data based on keywords (hot topics), simulating the working principle of a browser, sending requests to the target website's server, extracting the desired text content based on the server's response, and selecting the desired microblog users based on the collected content. Historical microblogs are then retrieved and cleaned using the user's unique user ID, as shown in the attached diagram. Figure 1As shown, the neural network is then trained using a self-attention neural network. Unlike CNNs and RNNs, the self-attention mechanism is more similar to how the human brain processes information, filtering out interesting information from tedious data and ignoring irrelevant information. Adding a self-attention mechanism to the neural network improves its efficiency, allowing it to process only key input information. A special token is added at the beginning of the text data to represent the overall sentence features. The main purpose is to complete a classification task based on predefined application scenario labels, classifying data according to predefined scenario categories and corresponding attitudes. Finally, the collected user data is combined with the trained model to characterize the user's cognitive state based on their attitude towards different events.
[0006] The overall process is as follows: Figure 2 As shown
[0007] In summary, the main process of this method can be divided into the following three steps: acquisition of social media network user data, neural network training, and characterization of user cognitive state.
[0008] (1) Acquisition of user data based on social media networks
[0009] This invention focuses on social media network users. To quickly and massively acquire user data, a microblogging data collection engine was built, encompassing the collection of trending topics and user microblogging content. Web crawling technology is used to simulate the working principle of a browser, constructing corresponding request headers to send requests to the target server. The returned files are then parsed as JSON files to obtain the microblogging content, the author, and their ID. Suitable user IDs are selected based on the number of microblogging posts and followers for user data collection. Regular expressions are used to clean the data, and finally, the user information is persistently stored.
[0010] (2) Neural Network Training
[0011] The purpose of training the neural network is to extract user features. The neural network model is trained using predefined scene themes and emotion categories. The neural network uses a transformer model within a self-attention architecture, with a feedforward neural network module added according to task requirements. This model aims to solve the complexity of long sequences and the mapping from sequence information to sequence representations. Compared to previous architectures such as RNNs, transformers offer superior parallel computing performance and more powerful information encoding capabilities. A special token is added before the model's input to represent the entire sentence. Since this token carries the overall information of the sentence, its semantic features are connected to the feedforward neural network module, enabling the model to achieve better classification capabilities. The model is pre-trained using relevant data from Chinese Wikipedia to enhance its generalization ability. Then, the model is fine-tuned using the wimai_10k and Thucnews datasets to better suit the classification task and improve accuracy. The overall structure diagram is attached. Figure 3 As shown
[0012] (3) Depicting the user's cognitive state
[0013] This invention provides a method for characterizing user cognitive states based on the analysis of different attitudes under predetermined scene tags. By training a neural network with social media network user data, the model can accurately map user text content into a semantic space under scene tags, calculating the similarity between the feature vectors of the corresponding dimensions of the scene tags and the feature vectors of the text content. This establishes the correspondence between user text content and scene tags, and the model can also categorize the text content into different attitudes. Combining predetermined scene tags with attitudes yields corresponding coordinate values, which are then converted to polar coordinates and visualized to flexibly display and serve multi-dimensional user cognitive states.
[0014] Compared with the prior art, the present invention has the following obvious advantages and beneficial effects:
[0015] 1) A method for characterizing the cognitive state of social media users based on a self-attention neural network is proposed. Firstly, it incorporates a Weibo data acquisition engine. Traditional data acquisition methods are costly and time-consuming; this invention can quickly and massively acquire social media network user data, facilitating the model to better establish user cognitive states. 2) By combining a self-attention neural network (transformer) with a feedforward neural network, the problem of weak sequential information representation capabilities in social media network user text data is addressed. This invention can better focus on the overall characteristics of text data and accurately map it to a predetermined scene space. It can also output emotional polarity according to different scenes, which is beneficial for constructing user cognitive states. 3) Utilizing a visualization method, predetermined scene labels and attitudes are combined, comprehensively considering basic user information to achieve a multi-dimensional display of user cognitive states. Attached Figure Description
[0016] Figure 1 This is a flowchart of data acquisition.
[0017] Figure 2 This is a flowchart of a user profile construction method based on social media networks.
[0018] Figure 3 This is a diagram of a self-attention and feedforward neural network architecture. Detailed Implementation
[0019] Based on the above description, the following is a specific implementation process, but the scope of protection of this patent is not limited to this implementation process.
[0020] Step 1: Acquiring user data based on social media networks
[0021] Step 1.1 Obtaining Chinese Hot Topic Data
[0022] Encoding is performed based on trending Chinese topics to obtain the URL for searching trending topics on Weibo: 'https: / / m.weibo.cn / api / container / getIndex'. Then, corresponding request headers and params are constructed based on the trending topics to simplify the URL length. `request.get(url, headers, params)` is called to construct a URL object requesting resources from the server, obtaining the response object returned by the server. The JSON file in the response is parsed to obtain the Weibo content, the Weibo author, and their user_id. Suitable user IDs are filtered based on the number of Weibo posts and followers for user data collection. The data is cleaned and extracted using the regular expression `re.compile(r'<[^>]+>')`, using the fields: page number, Weibo ID, Weibo author, author ID, posting time, Weibo content, number of reposts, number of comments, and number of likes. Finally, the user information is persistently stored.
[0023] Step 1.2 Obtaining User Weibo Data
[0024] Obtaining user data from Weibo first requires simulating a login. Specifically, this involves logging into your Weibo account, obtaining the account's cookies through the browser's developer options, and adding the cookie value to the request header. This solves the problem of needing to log in every time. User data is then scraped via the URL 'https: / / weibo.cn / userid', where 'userid' is a list of 'user_id' obtained in step 1.1. The HTML file corresponding to the Weibo homepage address is downloaded and parsed using XPath. This primarily involves using XPath syntax to locate the nodes containing the data and obtaining the data by reading the node attribute values or the node's text content. Filtering rules are written using XPath syntax to quickly locate nodes based on information provided by the browser's developer options, and then calling node attribute methods or context methods to obtain the user data. The user data is permanently stored in CSV and TXT formats. The user data includes user information and Weibo information. The stored user information fields are as follows: userid, nickname, gender, birthday, location, education, work experience, number of Weibo posts, number of followings, and number of followers (11 items in total). The Weibo information fields are as follows: Weibo ID, Weibo content, Toutiao article URL, original image URL, Weibo posting location: the posting location within the Weibo post, Weibo posting time, number of likes, number of reposts, and number of comments. The storage of user information is for identifying users with similar user types, while the storage of Weibo information is for characterizing user scenarios and emotional states.
[0025] Step 2: Building and Training the Neural Network Model
[0026] Step 2.1: Data Preprocessing
[0027] Based on the task requirements and model input requirements, preprocessing of the text data is necessary, including word segmentation, stop word removal, punctuation removal, and the removal of specific formatting marks and number merging. Word segmentation mainly refers to splitting Chinese text using a dictionary and specialized word segmentation techniques. The model's data comes from the Thucnews and wimai_10k datasets, converting the text in these datasets into words with independent meaning. A dictionary containing characters and special characters is used for Chinese word segmentation, dividing the text content into individual Chinese characters, and adding a [CLS] token at the beginning of the first character for subsequent overall information representation. The resulting word segmentation is then compared with the word embeddings matrix We∈R in the transformer. 21128*768 Matching yields the text vector of each segmented word, also known as the word embedding, with a size of Vn∈R. seq_len*768 Where We∈R 21128*768 The size of the matrix is 21128*768. Subsequent matrices in this invention are expressed in this way, and will not be elaborated further. seq_len is the text length.
[0028] Step 2.2 Construction based on self-attention neural network (transformer)
[0029] Step 2.2.1 Model Input
[0030] The idea of this invention comes from the encoder structure in Transformer, which consists of a multi-head self-attention module composed of input word segmentation embedding, position embedding, self-attention mechanism, and residual connection.
[0031] In addition to the word segmentation embeddings obtained in step 2.1, the model's input also needs to use positional embeddings to represent the positions of words within the sentence. Because the Transformer does not use an RNN structure but instead utilizes global information, it cannot leverage word order information, which is crucial for NLP. Therefore, the Transformer uses positional embeddings to store the relative or absolute positions of words in the sequence. Positional embeddings are represented by PEs, and the dimensionality of the PE is the same as that of the word segmentation embeddings. The formula is calculated as follows:
[0032] PE(pos,2i)=sin(pos / 100002i / dmodel )
[0033] PE(pos,2i+1)=cos(pos / 10000 2i / dmodel )
[0034] Where pos represents the position of the word in the sentence, dmodel represents the dimension of PE (same as word segmentation embedding), 2i represents an even-numbered dimension, 2i+1 represents an odd-numbered dimension (i.e., 2i≤d, 2i+1≤d), and PE∈R 1*768 The input X∈R of the model is obtained by adding the token embedding and position embedding of each word segmentation vector. seq_len*768 .
[0035] Step 2.2.2 Construction of the self-attention module
[0036] The network first uses a self-attention module to calculate the attention between the text segment and other segments in the sentence. The purpose is to solve the long-distance dependency problem by calculating the mutual influence between words. The formula is:
[0037] A output :
[0038] Where Q, K, and V are the Query matrix, Key matrix, and Value matrix, respectively. First, as in step 2.1, the input sequence is transformed into word vector embeddings V1…Vn. Each word vector embedding Vn is then compared with W… Q W K W V ∈R 768*768 The linear transformation matrix yields the Q, K, V matrices ∈ R seq_len*768 W Q W K W V It belongs to the learnable matrix. Compare matrix Q with K... T Multiplying yields the attention weight of each word segmentation for each word in the sentence, and then... Dividing reduces the range of the dot product. The size is 768 to prevent the partial derivatives from approaching zero due to an excessively large input softmax value. Softmax is used to ensure the non-negativity of the attention weights while also adding non-linearity. The attention weight matrix is multiplied by matrix V, and the features of each word in the sentence are weighted and summed using the weights of each word segment to obtain the output vector A. output It has a size of 768 dimensions, takes into account the entire sentence sequence, and also represents the semantic relationship between the word segment and other words in the sentence.
[0039] Step 2.2.3 Construction of the multi-head self-attention module
[0040] Furthermore, since single-head self-attention can only map on one semantic dimension, using multi-head self-attention helps to represent sentence segmentation across multiple semantic spaces. The output A of each single-head self-attention module... output These are then concatenated to form a multi-head attention module. The multi-head self-attention module is formed by combining eight Self-Attention steps from step 2.2.2. First, the input word vector X is passed to eight different Self-Attention modules. Each Self-Attention module has a 96-dimensional input. The first 96-dimensional embedding of the word vector is input to the first Self-Attention module, the second 96-dimensional embedding to the second Self-Attention module, and so on, up to eight Self-Attention modules, for a total of 768 dimensions (matching the dimensionality of the input word vector).
[0041] The formula is:
[0042] MultiHead(Q,K,V)=Concat(head1,…,headi)W o
[0043] MultiHead(Q,K,V) represents the output of multi-head self-attention, where head1…headi are the eight output matrices Z calculated by the eight self-attention modules, concatenated with W. o Matrix multiplication yields the output Z1∈R seq_len*768 This represents the feature vector of each word in the sentence. The output matrix Z1 is residually concatenated with the original input (using an Add operation) to create a direct path for gradient backpropagation and prevent gradient vanishing. Specifically, the residual connection involves adding the matrix formed by the word segmentation embeddings from the model's original input to the matrix Z1 output by the multi-head self-attention mechanism. Then, a LayerNorm normalization operation is performed. Specifically, the embedding of each word is normalized to ensure that the meaning vectors of words in each sequence are of the same scale, as shown in the following formula:
[0044] LayerNorm(X+MultiHead(X))
[0045] Where LayerNorm represents layer normalization, + represents residual connection, X represents the word vector Vn obtained from word segmentation, and the final output Z∈R is obtained. seq_len*768
[0046] Step 2.3 Construction of the feedforward neural network module
[0047] Step 2.2 yields the feature vector for each word segment. To characterize the user's cognitive state, the feature vectors need to be mapped to predefined scene labels and corresponding sentiment polarity labels. Therefore, this invention designs two independent feedforward neural network modules: scene_FFN and sentiment-FFN. Different FFN modules are called for different data: the formula is as follows:
[0048] scene_FFN(x)=max(0,x*W1+b1)*W2+b2
[0049] scentiment_FFN(x)=max(0,x*W3+b3)*W4+b4
[0050] W1, W2, W3, and W4 are hidden layers, and b1, b2, b3, and b4 are bias layers. Two fully connected network operations are performed. The ReLU activation function (the max operation in the formula) is used in scene_FFN and sentiment_FFN. The input to the feedforward neural network module is the 0th dimension vector in the multi-head attention output Z. Because a special [cls] marker is added to the initial input of the model, the purpose is to extract the overall features of the text sequence, and the [cls] feature vector ∈ R... 1*768 The semantic space feature vectors of the preset scene and emotion are obtained through the hidden layer W, the bias layer b, and the ReLU activation function. Where W1, W3 ∈ R 768*10 ,W2∈R 10*10 ,W4∈R 10*2 `scene_FFN` yields a 10-dimensional feature vector, corresponding to: Sports, Entertainment, Home, Real Estate, Education, Fashion, Current Affairs, Society, Technology, and Finance. `sentiment-FFN` yields a 2-dimensional feature vector, corresponding to: Positive and Negative sentiment.
[0051] An Encoder block can be constructed using the Multi-Head Attention, Add & Norm, and FFN modules described above. This Encoder block receives an input matrix of size (seq_len * 768) and outputs a matrix of size (seq_len * 768). Multiple Encoder blocks can be stacked to form an Encoder. The first Encoder block takes the word representation vector matrix as input, subsequent Encoder blocks take the output of the previous Encoder block as input, and the last Encoder block outputs the encoded information matrix.
[0052] Step 2.4 Setting Model Parameters
[0053] For the entire network, the training batch size is 64 parameters. The learning rate is initially set to 5. -5 It decayed to 5 after 100 batches. -6 The total number of training batches was set to 1000. A total of 12 encoder blocks were used. During training, softmax and cross-entropy were used to calculate the loss. The overall model was trained in stages by combining the corresponding class obtained through the softmax function with the cross-entropy loss function. The softmax formula is:
[0054]
[0055] We obtain the probability of each class, where yi represents the value output by the model for the i-th class. Then, we use the CrossEntropy loss function to make the model continuously approximate the true class. The formula for the CrossEntropy loss function is:
[0056] Loss=-∑qi log pi
[0057] qi represents the true label, and pi represents the result after Softmax. Combining Softmax with cross-entropy loss allows for faster model convergence and also aligns with the data classification objective of this invention. The overall model structure is shown in the attached figure. Figure 3 As shown
[0058] Step 3: Depicting the User's Cognitive State
[0059] Using the ABC theory, the characterization of user cognitive states on social media networks is transformed into a process of labeling user emotions based on pre-defined scenarios. User cognitive states are estimated using scenario and emotion labels, and the resulting Weibo posts are then processed and segmented. A multinomial distribution θ (document-topic) and a multinomial distribution Φ (topic-word) with Dirichlet prior hyperparameters α = 0.1 and β = 0.02 are used. Experiments show that the topic distribution results are relatively ideal when k = 10. The main content of a topic is obtained by summarizing words highly relevant to that topic using the following formula:
[0060]
[0061] Indicates the relevance of a word to a specific topic. The probability of a word appearing under a certain theme is p(w), which is the total probability of that word appearing. By adjusting the hyperparameter λ, the 10 key scene words are finally obtained: sports, entertainment, home, real estate, education, fashion, current affairs, society, technology, and finance. The constructed user cognition model can be divided into user scene cognition state and user emotional cognition state. Through the training of the model in step two, the scene words and emotions corresponding to the Weibo information data obtained in step one can be output to establish user scene cognition and user emotional cognition. The emotional cognition states corresponding to different scene behaviors of the same user are accumulated to obtain their individual cognition state, thus completing the characterization of the individual cognition state. At the same time, based on the user data obtained in step one, and the feature vectors of each user scene and user emotion, the similarity of the multidimensional vector space is calculated to classify user group types, and the formula is:
[0062]
[0063] Indicates user u x The system generates scene and emotion feature vectors. It calculates the similarity of two sets of features. When calculating user scene similarity, the parameter n is set to 10, representing the similarity of users' cognitive states across 10 different scene themes. When calculating emotion similarity, the parameter is set to 2, representing the similarity of users' emotional cognition across different scenes. Through visualization, users with similar basic information are grouped together, and their emotional attitudes towards different scenes are displayed, yielding corresponding coordinate values. These values are then converted to polar coordinates to achieve a flexible display and service of multi-dimensional user cognitive states.
Claims
1. A method for characterizing the cognitive state of social network users based on a self-attention neural network, characterized in that: Step 1: Obtaining user data based on social media networks Step 1.1 Obtaining Chinese Hot Topic Data Encode the Chinese trending topics to obtain the URL for searching Weibo trending topics: 'https: / / m.weibo.cn / api / container / getIndex'. Then, construct the corresponding request headers and params based on the trending topics to simplify the URL length. Call request.get(url, headers, params) to construct a URL object that requests resources from the server and obtain the response object returned by the server. Parse the JSON file in the response to obtain the Weibo content, Weibo author and their user_id. Filter suitable user IDs based on the number of Weibo posts and followers to collect user data. Use the regular expression re.compile(r'<[^>]+>') to clean and extract the Weibo content. Through the fields: page number, Weibo ID, Weibo author, author ID, posting time, Weibo content, number of reposts, number of comments, number of likes, finally persist the user information. Step 1.2 Obtaining User Weibo Data Obtaining user data from Weibo first requires simulating a login. Specifically, this involves logging into your Weibo account, obtaining the account's cookies through the browser's developer options, and adding the cookie value to the request header, thus resolving the need for login each time. User data is then scraped via the URL 'https: / / weibo.cn / userid', where 'userid' is a list of 'user_id' obtained in step 1.
1. The HTML file corresponding to the Weibo homepage address is downloaded and parsed using XPath. This primarily involves using XPath syntax to locate the nodes containing the data and obtaining the data by reading node attribute values or node text content. Filtering rules are written using XPath syntax to quickly locate nodes based on information provided by the browser's developer options, and then calling node attribute methods or context methods to obtain the user data. The user data is permanently stored in CSV and TXT formats, including user information and Weibo information. The stored user information fields are as follows: userid, nickname, gender, birthday, location, education, work experience, number of Weibo posts, number of followings, and number of followers (11 items in total). The Weibo information fields are as follows: Weibo ID, Weibo content, Toutiao article URL, original image URL, Weibo posting location: the posting location in the Weibo post, Weibo posting time, number of likes, number of reposts, and number of comments; the storage of user information is to identify users with similar types, and the storage of Weibo information is to depict user scenarios and emotional cognitive states; Step 2: Building and Training the Neural Network Model Step 2.1: Data Preprocessing The text data is preprocessed, including word segmentation, stop word removal, punctuation removal, and the removal of specific formatting marks and number merging. Word segmentation mainly refers to splitting Chinese text using a dictionary and specialized word segmentation techniques. The model's data comes from the Thucnews and wimai_10k datasets, converting the text in these datasets into words with independent meaning. A dictionary containing characters is used for Chinese word segmentation, dividing the text content into individual Chinese characters, and adding a [CLS] token at the beginning of the first character for subsequent overall information representation. The resulting word segmentation is then compared with the word embeddings matrix We∈R in the transformer. 21128*768 Matching yields the text vector of each segmented word, also known as the word embedding, with a size of Vn∈R. seq_len*768 Where We∈R 21128*768 This is represented as a matrix with a size of 21128*768, where seq_len is the text length; Step 2.2 Construction of a self-attention neural network transformer Step 2.2.1 Model Input The construction of the self-attention neural network transformer consists of input word segmentation embedding, position embedding, a multi-head self-attention module with self-attention mechanism, and residual connections; In addition to the word segmentation embeddings obtained in step 2.1, the model's input also needs to use positional embeddings to represent the positions of words in the sentence; positional embeddings are represented by PEs, and the dimensions of PEs are the same as those of word segmentation embeddings; the formula is calculated as follows: PE(pos,2i) = sin(pos / 10000 2i / dmodel ) PE(pos,2i+1) = cos(pos / 10000 2i / dmodel ) Where pos represents the position of the word in the sentence, dmodel represents the dimension of PE, 2i represents an even dimension, and 2i+1 represents an odd dimension, i.e., 2i≤d, 2i+1≤d; PE∈R 1*768 The input X∈R of the model is obtained by adding the token embedding and position embedding of each tokenized vector. seq_len*768 ; Step 2.2.2 Construction of the self-attention module The network first uses a self-attention module to calculate the attention magnitude between the text segment and other segments in the sentence, using the following formula: ; Where Q, K, and V are the Query matrix, Key matrix, and Value matrix, respectively; first, as in step 2.1, the input sequence is transformed into word vector embeddings V1…Vn, and each word vector embedding Vn is associated with W. Q W K W V ∈R 768*768 The linear transformation matrix yields the Q, K, V matrices ∈ R seq_len*768 W Q W K W V It belongs to the learnable matrix; compare matrix Q with K T Multiplying yields the attention weight of each word segmentation for each word in the sentence, and... Dividing reduces the range of the dot product. The size is 768. Softmax is used to ensure the non-negativity of the attention weights while adding non-linearity. The attention weight matrix is multiplied by matrix V, and the features of the characters in the sentence are weighted and summed using the weight of each word segment to obtain the output vector A. output It has a size of 768 dimensions, takes into account the entire sentence sequence, and also represents the semantic relationship between the word segment and other words in the sentence; Step 2.2.3 Construction of the multi-head self-attention module Multi-head self-attention is used to represent sentence segmentation in multiple semantic spaces; the output A of each single-head self-attention module is... output These will be spliced together to form a multi-head attention module; the multi-head self-attention module is formed by combining eight Self-Attention modules from step 2.2.
2. First, the input word vector X is passed to eight different Self-Attention modules. The input size of each Self-Attention module is 96 dimensions. The first 96-dimensional embedding of the word vector is input to the first Self-Attention module, the second 96-dimensional embedding is input to the second Self-Attention module, and so on up to eight Self-Attention modules, for a total of 768 dimensions. The formula is: ; This represents the output of multi-head self-attention, where head1…headi are the 8 output matrices Z calculated by the 8 self-attention modules, concatenated together with… Matrix multiplication yields the output Z1∈R seq_len*768 This represents the feature vector of each word in the sentence. The output matrix Z1 is then residually concatenated with the original input. Specifically, the residual concatenation involves adding the matrix formed by the word segmentation embeddings (the original input of the model) to the matrix Z1 output by the multi-head self-attention mechanism. Then, a LayerNorm normalization operation is performed. Specifically, the embedding of each word is normalized to ensure that the meaning vectors of words in each sequence are of the same scale. The formula is as follows: ; Where LayerNorm represents layer normalization, + represents residual connection, X represents the word vector Vn obtained from word segmentation, and the final output Z∈R is obtained. seq_len*768 Step 2.3 Construction of the feedforward neural network module Step 2.2 yields the feature vector for each word segment. To characterize the user's cognitive state, the feature vectors need to be mapped to predefined scene labels and corresponding sentiment polarity labels. Therefore, two independent feedforward neural network modules are designed: scene_FFN and sentiment-FFN. Different FFN modules are called for different data: The formula is as follows: ; ; W1, W2, W3, and W4 are hidden layers, and b1, b2, b3, and b4 are bias layers. Two fully connected network operations are performed. and The ReLU activation function is used, which is the max operation in the formula; the input of the feedforward neural network module is the 0th dimension vector in the multi-head attention output Z. Because the [cls] marker was added to the input at the beginning of the model, the purpose is to extract the overall features of the text sequence, and the [cls] feature vector ∈ R. 1*768 The semantic space feature vectors of the preset scene and emotion are obtained through the hidden layer W, the bias layer b, and the ReLU activation function; where W1, W3 ∈ R 768*10 ,W2∈R 10*10 ,W4∈R 10*2 Scene_FFN yields a 10-dimensional feature vector, corresponding to: Sports, Entertainment, Home, Real Estate, Education, Fashion, Current Affairs, Society, Technology, and Finance; Sentiment-FFN yields a 2-dimensional feature vector, corresponding to: Positive and Negative sentiments. An Encoder block can be constructed using the Multi-Head Attention, Add & Norm, and FFN modules described above. The Encoder block receives an input matrix of size (seq_len*768) and outputs a matrix of size (seq_len*768). Multiple Encoder blocks can be stacked to form an Encoder. The input of the first Encoder block is the representation vector matrix of the sentence words, the input of subsequent Encoder blocks is the output of the previous Encoder block, and the output matrix of the last Encoder block is the encoded information matrix. Step 2.4 Setting Model Parameters For the entire network, the training batch size is 64; the learning rate is initially set to 5. -5 It decayed to 5 after 100 batches. -6 The total number of training batches was set to 1000; a total of 12 encoder blocks were used; softmax and cross-entropy were used to calculate the loss during training; the overall model was trained in stages by combining the corresponding class obtained through the softmax function with the cross-entropy loss function; the softmax formula is: ; We obtain the probability of each class, where yi represents the value output by the model for the i-th class. Then, we use the CrossEntropy loss function to make the model continuously approximate the true class. The formula for the CrossEntropy loss function is: ; qi is the true label, and pi is the result after Softmax; Step 3: Depicting the User's Cognitive State Using the ABC theory, the characterization of user cognitive states on social media networks is transformed into a process of labeling user emotions based on pre-defined scenarios. User cognitive states are estimated from scenario and emotion labels, and the text content of user-posted Weibo posts is then processed and segmented. The "document-topic" multinomial distribution θ and the "topic-word" multinomial distribution Φ, with Dirichlet prior hyperparameters α = 0.1 and β = 0.02, are used. Experiments show that the topic distribution results are relatively ideal when k = 10. The main content of a topic is obtained by summarizing words with high relevance to that topic using the following formula: ; Indicates the relevance of a word to a specific topic. The probability of a certain word appearing under a certain theme. This represents the total probability of a certain word appearing; ultimately, 10 key scenario words were obtained: sports, entertainment, home, real estate, education, fashion, current affairs, society, technology, and finance; the constructed user cognition model is divided into user scenario cognition state and user emotional cognition state; through the training of the model in step 2, based on the Weibo information data obtained in step 1, the corresponding scenario words and emotions are output to establish user scenario cognition and user emotional cognition; the emotional cognition states corresponding to different scenario behaviors of the same user are accumulated to obtain their individual cognition state, thus completing the characterization of individual cognition state; at the same time, based on the user data obtained in step 1, and the feature vectors of each user scenario and user emotion, the similarity of the multi-dimensional vectors in the space is calculated to classify user group types, the formula is: ; Indicates user The system generates scene and emotion feature vectors; it calculates the similarity between two sets of features; when calculating user scene similarity, the parameter n is set to 10, representing the similarity of users' cognitive states across 10 thematic scenes; when calculating emotion similarity, the parameter is set to 2, representing the similarity of users' emotional cognition across different scenes; through visualization, users are categorized, and their emotional attitudes towards different scenes are displayed, obtaining corresponding coordinate values, which are then converted to polar coordinates to achieve multi-dimensional display and service of user cognitive states.
Citation Information
Patent Citations
Deep microblog sentiment analysis method using social context features
CN110188200A
User group division method based on user emotion behavior characteristics under microblog hot topics
CN111611455A