Twitter user location inference method based on heterogeneous graph and graph convolutional neural network
By constructing a heterogeneous graph and graph convolutional neural network, and using TF-IDF and PPMI to calculate edge weights, the problem of user location inference relying on indicator words in existing technologies is solved, achieving higher accuracy and stability, and being able to identify false geographic locations.
Patent Information
- Application Number
- CN202310568907.7
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2023-05-19
- Publication Date
- 2025-09-16
- Estimated Expiration
- 2043-05-19
AI Technical Summary
Existing user location inference methods rely on location indicators and ignore text structure information, resulting in unstable accuracy and failure to fully capture text semantics, affecting the accuracy of user location inference.
Based on heterogeneous graphs and graph convolutional neural networks, a relationship graph between user nodes and word nodes is constructed, edge weights are calculated using TF-IDF and PPMI, and the GCN network is used to learn user location features, reduce dependence on indicator words, and retain text structure information.
It improves the accuracy of user location inference, can identify forged geographic locations and false messages, enhances the fusion of text features, and improves model performance.
Smart Images

Figure CN116795836B_ABST
Abstract
Description
Technical Field
[0001] The present invention relates to the technical field of network security, and in particular to a Twitter user location inference method based on a heterogeneous graph and a graph convolutional neural network. Background Art
[0002] Inference methods based on user-generated text primarily infer the location of social media users based on geographic biases in word usage. This helps analysts identify false information based on location. The basic principle is to mine location-related vocabulary based on word usage habits of users in different regions and infer user locations based on the relationship between tweet topics and geographic regions posted by users in the same region.
[0003] Current naive methods automatically identify local words from tweets posted by users in known locations based on the statistical characteristics of word usage in different locations, and then infer the user's city-level location. However, the accuracy of user location inference is significantly affected by the positional distribution of words in the training set, and they rely heavily on location indicators. This results in unstable performance and a low detection rate for location indicators. Because these methods are based on probabilistic statistics, they use simple vectorization to obtain statistical features of the text and mathematical regression to infer user location. This ignores structural information in the text and fails to fully capture the overall semantics of the text content, resulting in a loss of contextual information and a high risk of misjudging location indicators, which in turn affects the accuracy of user location inference.
[0004] The invention patent with application number 202010328213.2 discloses a user portrait inference method based on spatiotemporal mobile data representation learning, including: obtaining data on multiple users and the locations visited by users, using the edge length weights between users to represent the similarity of the user's spatiotemporal patterns, the edge length weights between locations to represent the functional similarity of locations, and the edge length weights between users and locations to represent the frequency of users visiting locations, to obtain a semantically preserved mobile network; obtaining the user representation vector that minimizes the preset objective function, inputting it into a preset machine learning classification model, and obtaining the inference result of the user portrait; wherein the objective function is constructed based on the above three types of edge length weights, as well as the user representation vector and the location representation vector. This method does not require a large amount of manual feature generation and feature screening, has a high efficiency in training the model, effectively saves labor costs, and can effectively guarantee model performance, thereby achieving accurate user attribute inference based on mobile data. However, the machine learning classification model of the above method requires user access location data, and does not calculate the weights between word nodes, which is not conducive to mining local features of the text. Summary of the Invention
[0005] In response to the technical problem of low accuracy of existing user location inference methods, the present invention proposes a Twitter user location inference method based on heterogeneous graphs and graph convolutional neural networks. It fully utilizes the local and global correlations between words, converts all text corpora into statistical feature vectors, mines user features and word features related to location, retains the context structure, and uses feature vectors as the basis for inference, eliminating the dependence on indicator words, thereby solving the problem of low accuracy of user location inference of naive methods.
[0006] To achieve the above objectives, the technical solution of the present invention is implemented as follows: a Twitter user location inference method based on heterogeneous graphs and graph convolutional neural networks, the steps of which are as follows:
[0007] Step 1: Data preprocessing: preprocess the collected sample data to remove noise data in the sample data;
[0008] Step 2: Location region division: Build a search tree based on the location data in the training set sample data and assign location categories to users in the training set. Assign location regions to users in the test set based on the search tree and the baseline location data of users in the test set. Use the location region number as the user's location label and save it in the dataset.
[0009] Step 3: Heterogeneous graph construction: Treat each user as a user node and the words mentioned in the user's tweets as word nodes. Calculate the TF-IDF value between the user node and the word node, and use the TF-IDF value as the weight of the edge between the user node and the word node. Calculate the PPMI value between the word nodes and the word node, and use the calculated PPMI value as the weight of the edge between the word nodes.
[0010] Step 4: User location inference model training and performance testing: The heterogeneous graph is input into a two-layer GCN network. The second-layer node embedding is input into a softmax classifier to train the location inference model. The trained location inference model is used to infer the user locations in the test set and evaluate the model performance.
[0011] Preferably, the pretreatment method in step 1 includes:
[0012] (1) Interference text elimination: Filter out all special characters and emoticons to remove interference text, and unify all characters into lowercase to facilitate automatic recognition of identical words;
[0013] (2) Stop word filtering: filtering out stop words to remove the same words in tweets from different users and retain the different words;
[0014] (3) Lemma restoration: remove the affixes of a word to obtain the stem of the word;
[0015] (4) Mention relationship filtering: remove mentions between users in tweets, i.e. @ relationships;
[0016] (5) Low-frequency word filtering: Delete words that appear less than a certain frequency in the entire corpus.
[0017] Preferably, the implementation method of step 2 is: mapping the longitude and latitude of the user in the preprocessed data set to different geographic grids according to a certain granularity, dividing each sample data in the data set into regions, and storing the divided location tags in the location division mark field in the data set:
[0018] (1) The latitude and longitude coordinates of all users in the training set form a two-dimensional spatial data set S = {x1, x2, x3, x4, .....x N}, where x t =(x t (1) ,x t (2) ) T ,t=1,2,3,...,N;x t (1) and x t (2) Represent the longitude and latitude of the t-th user, respectively, and N represents the total number of sample data in the training set;
[0019] (2) Build a search tree for the latitude and longitude coordinate set S of users in the training set as the basis for classification;
[0020] (3) Based on the constructed search tree, the users in the test set are assigned location areas.
[0021] Preferably, the method for constructing the search tree is:
[0022] (1) Root node construction: The root node corresponds to the hyperrectangular region of the two-dimensional space containing the data set S: select the longitude x (1) As the coordinate axis, the coordinate axis x of all instances in the data set S (1) The median of the coordinates is the split point, and the super rectangular area corresponding to the root node is split into two sub-areas; the left child node and the right child node with a depth of 1 are generated from the root node, where the left child node corresponds to the sub-area with coordinates less than the split point, and the right child node corresponds to the sub-area with coordinates greater than the split point; the split is made by passing through the split point and intersecting with the coordinate axis x (1) The vertical hyperplane is implemented by saving the instance points that fall on the splitting hyperplane at the root node;
[0023] (2) Recursion: For a node with depth j, select x (L)is the coordinate axis of the segmentation, L = jmod k+1, k represents the dimensional space, and the coordinate axis x of all instances in the region of the node is (L) The median of the coordinates is the dividing point, and the super rectangular area corresponding to the node is divided into two sub-areas. The division is done by passing through the dividing point and intersecting with the coordinate axis x (L) Vertical hyperplane implementation; this node generates a left child node and a right child node with a depth of j+1, where the left child node corresponds to a sub-region with coordinates less than the split point, and the right child node corresponds to the coordinate x (L) For sub-regions larger than the split point, the instance points that fall on the split hyperplane are saved at the node;
[0024] (3) Backtracking: Stop and start backtracking until there are at most m instances in each of the two sub-regions, thus forming the region division of the kd tree; where m is the number of valid nodes.
[0025] Preferably, the method for assigning location categories to users in the training set is as follows: the latitude and longitude coordinates of the users in the training set are divided into N / m leaf nodes, that is, N / m location areas, each user in the training set belongs to the area where one of the leaf nodes is located, and the location categories of the users in the training set are assigned according to the area where the user is located;
[0026] The method for dividing the location areas of users in the test set is:
[0027] (1) For the N / m divided location areas, the average longitude and average latitude of all users in each location area are statistically calculated, and the coordinate point (average longitude, average latitude) is used as the location center point of the location area;
[0028] (2) For each user's latitude and longitude coordinate point c in the test set, traverse the location center points of N / m location areas, calculate the distance between the coordinate point c and the center of each location area, and assign the coordinate point c to the location area with the location center point closest to it;
[0029] (3) Each user in the preprocessed dataset corresponds to a classified location area, and the location area number is used as the user's location label and saved in the dataset.
[0030] Preferably, the method for calculating the PPMI value between word nodes is:
[0031] After preprocessing, each user's tweets are segmented to obtain a set of segmented user tweets. All words are numbered to form a Word set, where Word(i) represents word i and i is the word number. After traversing the words in the user's tweets after segmentation, the co-occurring words in the sliding window are paired to form word pairs Word(i,j)=[Word(i),Word(j)]. The punctual mutual information calculation formula is used to obtain:
[0032]
[0033]
[0034]
[0035] Where i and j are phrase numbers, W is the total number of sliding windows in the dataset, W(i) is the number of windows containing word i in the sliding window, W(i,j) is the number of windows containing word i and word j in the sliding window, P(i,j) is the ratio of the number of sliding windows containing word i and word j to the total number of sliding windows, P(i) represents the ratio of the number of sliding windows containing word i to the total number of sliding windows, and P(j) represents the ratio of the number of sliding windows containing word j to the total number of sliding windows.
[0036] Preferably, the method for calculating the TF-IDF value is: number the phrase set of each user tweet in the data set, traverse each phrase in the data set, and calculate the TF-IDF value of each word in each data. The TF value is: TF(w m ,n)=word w m The number of times it appears in the nth data; the IDF value is: IDF(w m )=log(total number of tweets by user ÷(number of tweets containing word w m The number of user tweets + 1)), the TF-IDF value is: TF-IDF(w m ,n)=TF(m,n)×IDF(w m ), where w m is the word in the user's tweet, and n is the data number of the user's tweet.
[0037] Preferably, the method for obtaining the adjacency matrix A of the heterogeneous graph is:
[0038] Assume that the number of users in the dataset is N u , the total number of unique words in all user tweets is N w , PPMI value established N w The mutual connections between words are represented by the matrix W1∈R Nw*Nw Indicates; TF-IDF value established N u user nodes and Nw The connection between word nodes is represented by the matrix D∈R Nu*Nw Indicates that the adjacency matrix A∈R of the entire heterogeneous graph (Nu+Nw)*Nw The values in are:
[0039]
[0040] Among them, the adjacency matrix A is a two-dimensional matrix, and a and b are the row index and column index of the matrix respectively.
[0041] Preferably, the propagation process of each graph convolution layer of the GCN network is:
[0042]
[0043] in, It is the adjacency matrix A of the constructed heterogeneous graph plus the matrix composed of the connection between each node and itself, I N is the identity matrix; is a matrix The degree matrix of H (l) is the feature matrix of the activation unit of layer l, where H 0 =X=I, I represents the unit matrix, W (l) is the parameter matrix of each layer, l represents the previous graph convolution layer, H (l+1) is the feature matrix of the current graph convolution layer;
[0044] The propagation process of the two-layer graph convolution layer used by the GCN network: the activation function of each layer uses the ReLU function and the Softmax function respectively, and the overall forward propagation is:
[0045]
[0046] in,
[0047] The output dimension of the last graph convolution layer is the total number of user location categories. The last graph convolution layer outputs a vector representation of all user node features. For the vector representation of the obtained user node features, the user's location category probability is calculated through the softmax function, and the user's location category can be inferred.
[0048] Preferably, the loss function uses a cross entropy loss function to calculate all labeled nodes. The cross entropy loss function after one round of training is:
[0049]
[0050] in, is the index set of labeled nodes, F is the latitude of the output feature, Yd,f is the label one-hot encoding of the labeled node, where Z d,f represents the value of the dth row and fth column of the result matrix Z obtained by formula (6).
[0051] Compared with existing technologies, the present invention has the following advantages: It implements text-based location inference of Twitter users, and can infer whether users have fabricated their geographic locations or sent false messages that do not match their geographic locations. Unlike traditional text-based user inference models, the present invention can extract text features from user tweets that are enhanced by integrating statistical features, text semantic information, and location features. The innovation of the present invention is reflected in:
[0052] 1. Based on the co-occurrence relationship between words in social texts and the mention relationship between words in tweets by users, this paper constructs the entire corpus as a representation of a heterogeneous graph, so as to fully utilize the local and global correlations between words to mine user features and word features.
[0053] 2. Representing text content as a heterogeneous graph can capture the discontinuous and long-distance semantics of the text, preserve the contextual structure, facilitate the extraction of user features from user tweets, and further avoid the problem of simple vectorization methods losing structure and affecting the accuracy of user location inference.
[0054] 3. Since the advantage of graph convolutional networks (GCNs) is that they can directly process graphically structured data and make full use of the structured information of graphs, the present invention constructs a location inference model based on GCN to infer user locations, and learns the representation of nodes in the graph for social user location inference to identify whether users are impersonating their geographic locations.
[0055] Therefore, the social media user location inference technology proposed in this paper can assist in location-based social network services, location-based event analysis, and location-based analysis of sensitive individuals. To consider not only statistical features but also the overall characteristics of user text when processing user text information, this paper proposes a Twitter user location inference method based on heterogeneous graphs and graph convolutional neural networks. By calculating the correlation between terms and leveraging the powerful feature extraction capabilities of graph neural networks, this method can obtain text features enhanced with user location. This method helps improve the performance and accuracy of existing text-based user location inference algorithms. BRIEF DESCRIPTION OF THE DRAWINGS
[0056] In order to more clearly illustrate the embodiments of the present invention or the technical solutions in the prior art, the following briefly introduces the drawings required for use in the embodiments or the description of the prior art. Obviously, the drawings described below are only some embodiments of the present invention. For ordinary technicians in this field, other drawings can be obtained based on these drawings without paying any creative work.
[0057] FIG1 is a schematic flow diagram of the present invention. DETAILED DESCRIPTION
[0058] The following will clearly and completely describe the technical solutions in the embodiments of the present invention in conjunction with the accompanying drawings. Obviously, the described embodiments are only part of the embodiments of the present invention, not all of the embodiments. All other embodiments obtained by ordinary technicians in this field based on the embodiments of the present invention without creative work are within the scope of protection of the present invention.
[0059] As shown in Figure 1, a Twitter user location inference method based on heterogeneous graphs and graph convolutional neural networks has the following steps:
[0060] Step 1: Data preprocessing. Each sample data is composed of the username, longitude, latitude, and user tweets. All preprocessed sample data in the dataset is divided into a training set and a test set.
[0061] The present invention involves two parts: model construction and model use. The model construction part mainly includes four steps: data preprocessing, location area division, heterogeneous graph construction, and location inference model training and testing.
[0062] Building a model requires a certain amount of sample data. Each sample data piece consists of a username, longitude, latitude, and tweets. The data is divided into training and test sets according to a certain ratio. To avoid noise interference and make features more distinct, the data preprocessing process of this invention is divided into five steps to remove interference noise from the sample data and further expose features. The specific steps, content, purpose, and characteristics of the preprocessing are as follows:
[0063] (1) Interference text elimination and normalization: Filter out all special characters and emoticons that are not associated with geographic locations to avoid interference, and unify all characters into lowercase to avoid problems caused by case sensitivity.
[0064] (2) Stop word filtering: Filter out words that have no association with geographic location to further expose features.
[0065] (3) Word form restoration: restore words to their original form, reduce the interference of word type, homophone, voice, and homophone on the results, and further highlight the characteristics of tweets.
[0066] (4) Mention relationship filtering: Mention relationship filtering is to remove mentions (@) between users in tweets. Tweets often contain mentions between users. This paper focuses on location inference based on user-posted text. This paper studies the impact of mentions on model performance by filtering out mentions between users in tweets.
[0067] (5) Low-frequency feature filtering: For the two test datasets, words that appear less than 5 and less than 10 times in the entire corpus are deleted respectively to remove unrepresentative features and condense the key attributes of the features.
[0068] Step 2: Location region division: Build a search tree based on the longitude and latitude in the sample data of the training set, and assign location categories to users in the training set; assign location regions to users in the test set based on the search tree, and save the location region number as the user location label in the dataset.
[0069] After data preprocessing is completed, the latitude and longitude of users in the sample dataset need to be mapped to different geographic grids at a certain granularity. Each data item in the dataset is divided and the divided tags are stored in the location division tag field in the dataset. The specific implementation method is as follows:
[0070] 2.1 First, the longitude and latitude coordinates of all users in the training set are used to form a two-dimensional spatial data set S = {x1, x2, x3, x4, .....x N}, where x t =(x t (1) ,x t (2) ) T ,t=1,2,3.....N. x t (1) and x t (2) They represent the longitude and latitude of the t-th user respectively, and N represents the total number of sample data in the training set.
[0071] 2.2 For the latitude and longitude coordinate set S of the users in the training set, perform the following operations to construct a search tree as the basis for classification:
[0072] 2.2.1 Root Node Construction
[0073] The root node corresponds to the hyperrectangular region of the two-dimensional space containing the set S. Select the longitude x (1) is the coordinate axis, with the coordinate axis x of all instances in the set S (1) The median of the coordinates is the dividing point, which divides the super-rectangular area corresponding to the root node into two sub-areas. The division is done by passing through the dividing point and intersecting with the coordinate axis x (1) Vertical hyperplane implementation. Generate left and right child nodes with a depth of 1 from the root node, where the left child node corresponds to the coordinate x (1) The subregion smaller than the split point, the right child node corresponds to the coordinate x (1) The sub-region is larger than the split point. The instance points that fall on the split hyperplane are saved in the root node.
[0074] 2.2.2 Recursion
[0075] For a node with depth j, select x (L) is the coordinate axis of the segmentation, L = j (mod k) + 1, and the coordinate axis x of all instances in the region of the node is (L) The median of the coordinates is the dividing point, and the super rectangular area corresponding to the node is divided into two sub-areas. The division is done by passing through the dividing point and intersecting with the coordinate axis x (L) The vertical hyperplane is realized. This node generates a left child node and a right child node with a depth of j+1, where the left child node corresponds to the coordinate x (L) The sub-region smaller than the dividing point, the right child node corresponds to the coordinate x (L) The sub-region is larger than the cutting point. The instance points falling on the cutting hyperplane are saved at the node. k represents the k-dimensional space. Since the present invention divides the longitude and latitude coordinates, the data is two-dimensional, and k=2.
[0076] 2.2.3 Backtracking
[0077] For a dataset, the backtracking process stops when at most m instances exist in each of the two subregions, thus forming a kd-tree partitioning algorithm. m is the number of valid nodes. Adjustments are made based on the dataset used. In this field, the final partitioning strategy typically uses 32, 128, or 256 location categories, depending on the dataset size. For example, if there are 5685 data points and you want to obtain 32 categories, you can set m to around 180.
[0078] For the training set, according to the latitude and longitude coordinates of the users in the training set, a total of N / m leaf nodes, or N / m location areas, are divided. Each user in the training set belongs to the area where one of the leaf nodes is located, and finally the location category assignment is completed for the users in the training set.
[0079] 2.3 Based on the constructed kd tree, assign location areas to users in the test set.
[0080] 2.3.1 For the N / m location zones defined above, calculate the average longitude and latitude of all users in each location zone. The coordinate point (longitude, latitude) is considered the center of the location zone. For example, for N / m location zones, there are N / m corresponding location centers.
[0081] 2.3.2 For each user's latitude and longitude coordinate point c in the test set, traverse these N / m location center points, calculate the distance between coordinate point c and each location center point, and assign coordinate point c to the area where the location center point closest to it is located.
[0082] 2.3.3 After the location region division is completed for the test data, each user in the preprocessed dataset corresponds to a classified location region. The location region number is used as the user's location label and saved in the dataset.
[0083] Each piece of data in the dataset consists of four parts: username, latitude, longitude, and user tweets. The social media location inference problem involves inferring a user's location based on their social data. This paper considers the user location inference problem as a classification problem. Use the kd tree to divide the user's latitude and longitude coordinates, and divide some users with close distances into the same location area (category). For example, if the following three user tweets (data one: USER_ee551c6c 41.902552 -87.664 693 ralphmarston:No mere opinion from someone else has the power; data two: USER_ca06 7496 40.633008 -73.932381 Yup.A bad one too RT@USER_826381a0:Sanaa Lathan is a real BITCH in dis flik smh; data three: USER_6113e677 38.475521 -121.443418I been sleep since like 1pm.I'm still hella tired!What up world) are divided into location area L1, the location category L1 is used as the location label of these three users, making the user location inference task feasible.
[0084] The reason for using the kd-tree partitioning method to determine user location categories is that common user location inference methods typically use a uniform grid to divide user location regions, but these methods are very sensitive to the distribution of users on the earth, which can lead to large user location errors. For most real Twitter datasets, user densities in different regions often vary. Therefore, to reduce user location inference errors, the present invention uses a kd-tree to discretize all user coordinates to ensure that the number of users in each region (location category) is roughly the same.
[0085] Step 3: Heterogeneous graph construction. Each user is considered a user node, and the words in the user's tweets are considered word nodes. The TF-IDF value between the user node and the word nodes in the user's tweets is calculated, and the TF-IDF value is used as the weight of the edge between the user node and the word node. The PPMI value between the word nodes is calculated, and the calculated PPMI value is used as the weight of the edge between the word nodes.
[0086] The present invention regards each user as a user node and the words in the user's tweets as word nodes. (1) By calculating the TF-IDF value between the user node and the word node in the user's tweet, the relationship between the user node and the word node is established, and the TF-IDF value between the nodes is used as the weight of the edge between the user node and the word node. (2) By calculating the PPMI value between the word node and the word node, the connection between the word nodes is established, and the calculated PPMI value is used as the weight of the edge between the word nodes. Based on the calculation results of (1) and (2), a heterogeneous graph is established. The heterogeneous graph is composed of the user nodes and word nodes in the data set. The adjacency matrix in the heterogeneous graph is represented by A.
[0087] 3.1 Word Segmentation: After preprocessing, each user's tweets are segmented to obtain a word set in the user's tweets and stored in the dataset. All words in the dataset are numbered to form a Word set, where Word(i) represents word i, where i is the word number.
[0088] 3.2 Constructing Initial Text Features X: Declaring Initial Text Features Among them, n d and n w are the number of users and words in the dataset, respectively. I represents the identity matrix.
[0089] 3.3 In order to calculate the weight of the connecting edge between word nodes, calculate the PPMI value.
[0090] Traverse the words in the data set, and the co-occurring words in the sliding window form a word pair Word(i,j)=[Word(i),Word(j)]. PPMI(i,j) is obtained by the PPMI calculation formula, where i and j are the phrase numbers.
[0091]
[0092]
[0093]
[0094] Where W is the total number of sliding windows in the dataset, and W(i) is the number of windows containing word i in the sliding window. W(i,j) is the number of windows containing word i and word j in the sliding window. P(i,j) is the ratio of the number of sliding windows containing word i and word j to the total number of sliding windows, where P(i) represents the ratio of the number of sliding windows containing word i to the total number of sliding windows, and P(j) represents the ratio of the number of sliding windows containing word j to the total number of sliding windows. The present invention uses PPMI to calculate the co-occurrence information between words, obtain the local features between words in user tweets, and thus learn to obtain better word representations.
[0095] 3.4 Calculating TF-IDF Value
[0096] The TF-IDF value is calculated to comprehensively consider the frequency of word occurrence and the total number of times the word appears in the corpus, thereby calculating the weight of the word, thereby better measuring the contribution of the word to the text, and helping to improve the quality of the text representation of user tweets.
[0097] Number the words in each user text in the dataset, traverse each word in the dataset, and calculate the TF-IDF value of each word: TF(w m ,n)=word w m The number of times it appears in the nth data; IDF(w m )=log(total number of tweets by user ÷(number of tweets containing word w m The number of user tweets + 1), TF-IDF (w m ,n)=TF(w m ,n)×IDF(w m ), where w m is the word in the user's tweet, and n is the data number of the user's tweet.
[0098] By using the TF-IDF value as the weight of the edge between the user node and the word node, and the PPMI value as the weight of the edge between the word nodes, the constructed heterogeneous graph can take into account both the overall and local features of the text, and mine richer text information representation.
[0099] 3.5 Obtaining the adjacency matrix A
[0100] The number of users and the words in the user's tweets are numbered. Assuming there are 200 user data and 400 words in these data, the present invention uses sequence numbers 1-600 to represent user nodes and word nodes, where sequence numbers 1-200 represent user nodes and sequence numbers 200-600 represent word nodes.
[0101] Assume that the total amount of user tweets in the dataset is N u (i.e. the number of users), the total number of unique words in all users’ tweets is Nw By calculating the TF-IDF value and PPMI value, a heterogeneous graph is constructed, and then the adjacency matrix A is obtained from the heterogeneous graph. According to the PPMI value, N w The weight of the edge between words is represented by the matrix W1∈R Nw*Nw According to the TF-IDF value, N u user nodes and N w The weight of the edge connecting the word nodes is expressed by the matrix D∈R Nu*Nw Represents. The adjacency matrix A∈R of the entire heterogeneous graph (Nu+Nw)*Nw The values in are defined as follows, where a and b are the row and column indices of the matrix respectively:
[0102]
[0103] The adjacency matrix A is a two-dimensional matrix. For example, if there are 9475 users and 10,000 words, the dimension of A is 19475 x 10,000. The row dimension is 1945, with the first 9475 nodes representing user nodes and the last 10,000 nodes representing word nodes. The column dimension is 10,000, representing the vocabulary dimension. For example, the value of A(3, 8) represents the TF-IDF value between the third user node and the eighth word in the vocabulary; the value of A(19000, 10000) represents the PPMI value between the 19,000th and 10,000th words.
[0104] Step 4: User location inference model training and performance testing: After the heterogeneous graph is constructed, it is input into a two-layer GCN. The node (word / user) embeddings output by the second layer are input into a softmax classifier to train the location inference model. The trained model is used to infer the user locations in the test set and evaluate the model performance.
[0105] The input of the GCN network is the adjacency matrix A of the graph and the initial feature matrix X of the nodes in the graph. In this paper, the adjacency matrix in the heterogeneous graph is used as matrix A, and X is initialized to an identity matrix I, where the dimension size of I is the same as the dimension size of the adjacency matrix A. The output dimension size of the last hidden layer of GCN is set to the total number of user location categories.
[0106] The characteristic of the GCN network is that it uses information from known labeled data to infer unknown labeled data. The adjacency matrix A and the initial text features X are input into the GCN network. After two layers of GCN networks are trained on the training set data, the vector representation of each node in the GCN network is updated and output. Finally, the obtained vector representation is probabilistically calculated using the softmax function to obtain the inferred user location label. The specific steps are as follows.
[0107] The present invention uses a two-layer GCN model, that is, a GCN model with two graph convolutional layers.
[0108] (1) Input: adjacency matrix A and initial text features X.
[0109] (2) Output: The geographic location label evaluated by the GCN model based on the features.
[0110] (3) Model structure:
[0111] The propagation process of each graph convolution layer is:
[0112]
[0113] in, It is the adjacency matrix A of the constructed heterogeneous graph plus the matrix composed of the connection between each node and itself, I N is the identity matrix. is a matrix The degree matrix of H (l) is the feature matrix of the activation unit of layer l, where H 0 =X,W (l) Is the parameter matrix of each layer. The feature matrix H of the current graph convolution layer of GCN (l+1) Through the matrix and the characteristic matrix H (l) Multiply to get the summary of each node and its neighbors’ features, where l represents the previous graph convolutional layer.
[0114] Propagation process of two-layer graph convolutional layer: Using a two-layer GCN, the activation functions are ReLU and Softmax respectively. The overall forward propagation formula is:
[0115]
[0116] Among them, the output dimension of the last graph convolution layer is set to the total number of categories of the user location. Then, based on the vector representation of the user document node obtained, the softmax function is used to identify the location category probability Z of the document node of the user's tweet. Finally, the cross entropy loss function is used to calculate the loss function of all labeled nodes after one round of training. The calculation formula is as follows:
[0117]
[0118] in, is the index set of labeled nodes, F is the latitude of the output feature, Y d,f is the label one-hot encoding of the labeled node, where Z d,frepresents the value of the dth row and fth column of the result matrix Z obtained by propagating formula (6).
[0119] The GCN model is a semi-supervised model that uses known label data to infer the labels of nodes with unknown labels. When the location region is divided in step 2, the test set data is also divided into location regions. When constructing the heterogeneous graph, calculating the TF-ID value and calculating the PPMI value, the test data of the test set are used to learn their feature vectors. When training the location inference model, the labels of the training set are used to calculate the loss function, and the labels of the test set are used to verify the accuracy of the model inference. After the softmax function of the last layer of graph convolution, the location labels of all user nodes can be obtained. The present invention evaluates the performance of the user location inference model by calculating the following three evaluation indicators: (1) Acc@161: the proportion of users whose inferred user locations are within 161 miles of the actual location to the total number of test users; (2) Mean: the average error, which is the average value of the error distance between the inferred location and the actual location of all users; (3) Median: that is, first sort the user errors, and then take the median of all user errors as the median error. For these three indicators, the higher the Acc@161 and the lower the Mean and Median, the better the location inference model. The experimental results of the present invention on two public Twitter datasets, GeoText and TW-US, are shown in Table 1.
[0120] Table 1 Test results
[0121]
[0122] GMM_T is a neural network-based model that combines a Gaussian mixture distribution to propose a text-based geolocation method; MLP_T is a text-based model that simply extracts TF-IDF features from text as input to a multi-layer perceptron to train a user location inference model; HGeo is the method proposed by this invention, and HGeo_men is a variant of this method. The difference between the two methods is that HGeo_men does not filter out inter-user mentions in tweets. As shown in Table 1, on the two public Twitter datasets GeoText and TW-US, compared to the best-performing baseline method MLP_T, the proposed method improves the accuracy on Acc@161 by 2% and 5%, respectively, reducing the mean error by 31 km and 54 km, and the median error by 46 km and 36 km, respectively. This demonstrates that the proposed method can better extract user text features and improve the accuracy of user location inference. Furthermore, the proposed method found that excluding @mentions during data preprocessing results in better model performance. This suggests that although the proposed method infers location based on pure text, the model can automatically learn social network structural features through @mentions in the neural network layer, further improving the accuracy of user location inference.
[0123] The present invention combines TF-IDF and PPMI to convert the dataset into a heterogeneous graph, and uses the GCN network to infer the location of social media users with unknown locations based on the structural characteristics of the heterogeneous graph; uses TF-IDF to fully utilize the local and global correlations between words to mine user features and word features; uses PPMI to fully utilize the local and global correlations between words to mine user features and word features; constructs a heterogeneous graph based on TF-IDF and PPMI, and uses GCN to learn Twitter user feature representation and train a user location inference model.
[0124] The present invention differs from previous text-based user location inference models in that the graphs constructed in previous work are all social network graphs based on user mention relationships or heterogeneous graphs based on social networks. The present invention calculates the word frequency and inverse text frequency index between words and users, and the positive mutual information between users and words, establishes connections between users and words, and between words and words, and assigns weights. The entire corpus is constructed as a heterogeneous graph representation to capture the discontinuous and long-distance semantics of the text, and fully utilizes the local and global correlations between words to mine location-enhanced user features and word features. The present invention uses GCN to fully utilize heterogeneous graph features and infer user locations based on the characteristics of social media text.
[0125] The above description is only a preferred embodiment of the present invention and is not intended to limit the present invention. Any modifications, equivalent substitutions, improvements, etc. made within the spirit and principles of the present invention should be included in the scope of protection of the present invention.
Claims
1. A Twitter user location inference method based on heterogeneous graphs and graph convolutional neural networks, characterized by: The steps are as follows: Step 1: Data preprocessing: preprocess the collected sample data to remove noise data in the sample data; Step 2: Location region division: Build a search tree based on the location data in the training set sample data and assign location categories to users in the training set. Assign location regions to users in the test set based on the search tree and the baseline location data of users in the test set. Use the location region number as the user's location label and save it in the dataset. Step 3: Heterogeneous graph construction: each user is considered as a user node, and the words mentioned in the user's tweets are considered as word nodes; Calculate the TF-IDF value between the user node and the word node, and use the TF-IDF value as the weight of the edge between the user node and the word node; Calculate the PPMI value between word nodes and use the calculated PPMI value as the weight of the edge between word nodes; Step 4: User location inference model training and performance testing: The heterogeneous graph is input into a two-layer GCN network. The second-layer node embedding is input into a softmax classifier to train the location inference model. The trained location inference model is used to infer the user locations in the test set and evaluate the model performance. The propagation process of each graph convolution layer of the GCN network is: in, It is the adjacency matrix A of the constructed heterogeneous graph plus the matrix composed of the connection between each node and itself, I N is the identity matrix; is a matrix The degree matrix of H (l) is the feature matrix of the activation unit of layer l, where H 0 =X=I, I represents the unit matrix, W (l) is the parameter matrix of each layer, l represents the previous graph convolution layer, H (l+1) is the feature matrix of the current graph convolution layer; The propagation process of the two-layer graph convolution layer used by the GCN network: the activation function of each layer uses the ReLU function and the Softmax function respectively, and the overall forward propagation is: in, The output dimension of the last graph convolution layer is the total number of user location categories. The last graph convolution layer outputs a vector representation of all user node features. For the vector representation of the obtained user node features, the user's location category probability is calculated through the softmax function, and then the user's location category is inferred.
2. The Twitter user location inference method based on heterogeneous graph and graph convolutional neural network according to claim 1 is characterized in that The pretreatment method in step 1 includes: (1) Interference text elimination: Filter out all special characters and emoticons to remove interference text, and unify all characters into lowercase to facilitate automatic recognition of identical words; (2) Stop word filtering: filtering out stop words to remove the same words in tweets from different users and retain the different words; (3) Lemma restoration: remove the affixes of a word to obtain the stem of the word; (4) Mention relationship filtering: remove mentions between users in tweets, i.e. @ relationships; (5) Low-frequency word filtering: Delete words that appear less than a certain frequency in the entire corpus.
3. The Twitter user location inference method based on heterogeneous graph and graph convolutional neural network according to claim 1 or 2, characterized in that: The implementation method of step 2 is as follows: the latitude and longitude of the user in the pre-processed data set are mapped to different geographic grids according to a certain granularity, each sample data in the data set is divided into regions, and the divided location labels are stored in the location division mark field in the data set: (1) The latitude and longitude coordinates of all users in the training set form a two-dimensional spatial data set S = {x1, x2, x3, x4, .....x N }, where x t =(x t (1) ,x t (2) ) T ,t=1,2,3,...,N;x t (1) and x t (2) Represent the longitude and latitude of the t-th user, respectively, and N represents the total number of sample data in the training set; (2) Build a search tree for the latitude and longitude coordinate set S of users in the training set as the basis for classification; (3) Based on the constructed search tree, the users in the test set are assigned location areas.
4. The Twitter user location inference method based on heterogeneous graph and graph convolutional neural network according to claim 3 is characterized in that The method for constructing the search tree is: (1) Root node construction: The root node corresponds to the hyperrectangular region of the two-dimensional space containing the data set S: select the longitude x (1) As the coordinate axis, the coordinate axis x of all instances in the data set S (1) The median of the coordinates is the split point, and the super rectangular area corresponding to the root node is split into two sub-areas; the left child node and the right child node with a depth of 1 are generated from the root node, where the left child node corresponds to the sub-area with coordinates less than the split point, and the right child node corresponds to the sub-area with coordinates greater than the split point; the split is made by passing through the split point and intersecting with the coordinate axis x (1) The vertical hyperplane is implemented by saving the instance points that fall on the splitting hyperplane at the root node; (2) Recursion: For a node with depth j, select x (L) is the coordinate axis of the segmentation, L = jmod k+1, k represents the dimensional space, and the coordinate axis x of all instances in the region of the node is (L) The median of the coordinates is the dividing point, and the super rectangular area corresponding to the node is divided into two sub-areas. The division is done by passing through the dividing point and intersecting with the coordinate axis x (L) Vertical hyperplane implementation; this node generates a left child node and a right child node with a depth of j+1, where the left child node corresponds to a sub-region with coordinates less than the split point, and the right child node corresponds to the coordinate x (L) For sub-regions larger than the split point, the instance points that fall on the split hyperplane are saved at the node; (3) Backtracking: Stop and start backtracking until there are at most m instances in each of the two sub-regions, thus forming the region division of the kd tree; where m is the number of valid nodes.
5. The Twitter user location inference method based on heterogeneous graph and graph convolutional neural network according to claim 4 is characterized in that: The method for assigning location categories to users in the training set is as follows: the longitude and latitude coordinates of the users in the training set are divided into N / m leaf nodes, that is, N / m location regions. Each user in the training set belongs to the region where one of the leaf nodes is located. The location categories of the users in the training set are assigned according to the region where the user is located. The method for dividing the location areas of users in the test set is: (1) For the N / m divided location areas, the average longitude and average latitude of all users in each location area are statistically calculated, and the coordinate point (average longitude, average latitude) is used as the location center point of the location area; (2) For each user's latitude and longitude coordinate point c in the test set, traverse the location center points of N / m location areas, calculate the distance between the coordinate point c and the center of each location area, and assign the coordinate point c to the location area with the location center point closest to it; (3) Each user in the preprocessed dataset corresponds to a classified location area, and the location area number is used as the user's location label and saved in the dataset.
6. The Twitter user location inference method based on heterogeneous graph and graph convolutional neural network according to claim 4 or 5, characterized in that: The method for calculating the PPMI value between word nodes is: After preprocessing, each user's tweets are segmented to obtain a set of segmented user tweets. All words are numbered to form a Word set, where Word(i) represents word i and i is the word number. After traversing the words in the user's tweets after segmentation, the co-occurring words in the sliding window are paired to form word pairs Word(i,j)=[Word(i),Word(j)]. The punctual mutual information calculation formula is used to obtain: Where i and j are phrase numbers, W is the total number of sliding windows in the dataset, W(i) is the number of windows containing word i in the sliding window, W(i,j) is the number of windows containing word i and word j in the sliding window, P(i,j) is the ratio of the number of sliding windows containing word i and word j to the total number of sliding windows, P(i) represents the ratio of the number of sliding windows containing word i to the total number of sliding windows, and P(j) represents the ratio of the number of sliding windows containing word j to the total number of sliding windows.
7. The Twitter user location inference method based on heterogeneous graph and graph convolutional neural network according to claim 6 is characterized in that The method for calculating the TF-IDF value is as follows: number the phrase set of each user's tweet in the data set, traverse each phrase in the data set, and calculate the TF-IDF value of each word in each data. The TF value is: TF(w m ,n)=word w m The number of times it appears in the nth data; the IDF value is: IDF(w m )=log(total number of tweets by user ÷(number of tweets containing word w m The number of user tweets + 1)), the TF-IDF value is: TF-IDF(w m ,n)=TF(m,n)×IDF(w m ), where w m is the word in the user's tweet, and n is the data number of the user's tweet.
8. The Twitter user location inference method based on heterogeneous graph and graph convolutional neural network according to claim 7 is characterized in that: The method for obtaining the adjacency matrix A of the heterogeneous graph is: Assume that the number of users in the dataset is N u , the total number of different words in all users’ tweets is N w , PPMI value established N w The mutual connections between words are represented by the matrix W1∈R Nw*Nw Indicates; TF-IDF value established N u user nodes and N w The connection between word nodes is represented by the matrix D∈R Nu*Nw Indicates that the adjacency matrix A∈R of the entire heterogeneous graph (Nu+Nw)*Nw The values in are: Among them, the adjacency matrix A is a two-dimensional matrix, and a and b are the row index and column index of the matrix respectively.
9. The Twitter user location inference method based on heterogeneous graph and graph convolutional neural network according to claim 1 or 8, characterized in that: The loss function uses the cross entropy loss function to calculate all labeled nodes. After one round of training, the cross entropy loss function is: in, is the index set of labeled nodes, F is the latitude of the output feature, Y d,f is the label one-hot encoding of the labeled node, where Z d,f represents the value of the dth row and fth column of the result matrix Z obtained by formula (6).
Citation Information
Patent Citations
A Method and Apparatus for User Profile Inference Based on Spatiotemporal Mobility Data Representation Learning
CN111695046B
A position inference method for extracting position indication words based on semantic characteristics
CN109918579A
Account position identification method based on multi-modal information fusion in social media
CN113704502A