A social text sentiment classification method and device based on temporal sentence features

By employing sentence vector-based synthesis techniques and the Bi-Lstm-attention model, the problem of insufficient utilization of temporal information and sentence vectors in social text sentiment analysis is solved, achieving more accurate sentiment polarity judgment.

CN117251568BActive Publication Date: 2025-10-28XIAMEN MEIYA PICO INFORMATION CO LTD
View PDF 2 Cites 0 Cited by

Patent Information

Application Number
CN202311096153.6
Authority / Receiving Office
CN · China
Patent Type
Patents(China)
Current Assignee / Owner
Filing Date
2023-08-29
Publication Date
2025-10-28
Estimated Expiration
2043-08-29

AI Technical Summary

Technical Problem

Existing social text sentiment analysis models have shortcomings in processing temporal and sentence vector information, ignoring the temporal relationships between sentences and the importance of sentence vectors, resulting in inaccurate sentiment judgments.

Method used

We employ a sentence vector-based synthesis technique, utilizing the Bi-LSTM-attention model combined with temporal sentence features. We extract upstream and downstream sentences through a time window, synthesize sentence vectors using the TF-IDF algorithm, and perform sentiment classification using the Bi-LSTM-attention model.

Benefits of technology

It improves the accuracy of sentiment analysis of social texts, better captures the temporal dependencies between sentences, and enhances the accuracy of sentiment polarity judgment.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN117251568B_ABST
    Figure CN117251568B_ABST
Patent Text Reader

Abstract

This invention proposes a method and apparatus for social text sentiment classification based on temporal sentence features, comprising: responding to the acquisition of social text data; using a trained base classifier model to determine the category of the acquired social text data; based on the determination result, extracting upstream and downstream related sentences of the acquired social text through a time window, synthesizing sentence vectors from the extracted sentences, and converting them into sentence vectors using TF-DIF average calculation; inputting the sentence vectors into a Bi-LStm-attention model in temporal order to obtain the final sentiment label of the target text. This method not only incorporates the current text but also comprehensively models and calculates the preceding and following sentences in the sentiment analysis, innovatively using sentence vectors as model input vectors. Combined with the Bi-LStm-attention model, it overcomes the shortcomings of previous sentiment analysis methods in handling temporal text, showing promising application prospects in sentiment polarity analysis and sentiment opinion judgment in social apps and social forums.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] This invention belongs to the field of sentiment classification technology, specifically relating to a method and apparatus for sentiment classification of social text based on temporal sentence features. Background Technology

[0002] With the rapid development of the internet and the widespread use of social media platforms, more and more people are expressing their opinions and views through comments and chats on these platforms. Sentiment analysis is a technique that uses models to automatically extract people's emotions and opinions from text. With the development of deep learning models, sentiment text classification models, due to their intelligent and automated characteristics, are widely used for sentiment extraction from social texts. For example, in e-commerce, sentiment extraction from product or service reviews helps optimize service strategies and product sales; in stock platforms, analyzing stock market comments helps identify the relationship between the stock market and investor sentiment; and on social media platforms like Weibo, analyzing individual comments helps extract public sentiment. Therefore, a sentiment model trained based on the characteristics of social text is of paramount importance.

[0003] Currently, sentiment analysis models can be broadly categorized into two types: supervised sentiment analysis models and unsupervised sentiment analysis models. Unsupervised sentiment analysis models typically employ a sentiment polarity dictionary to score the sentiment polarity of words within a sentence, thereby obtaining the overall sentiment score for the sentence. Examples include Naive Bayes classifiers and TF-IDF classification methods.

[0004] Unsupervised sentiment analysis utilizes existing machine learning and deep learning techniques to train models on labeled sentiment text data, then uses the trained models to automatically extract sentiment information from the text. In machine learning models, many use bagging with XGBoost and logistic regression for text classification. In deep learning models, the most representative model is TextCNN, which is characterized by fast inference speed and simple training in sentiment classification. However, TextCNN has limitations in considering the context of words. To overcome this shortcoming, models with global feature extraction, such as TextRNN, Transformer, and BERT, are increasingly being applied to sentiment analysis.

[0005] From the perspective of unsupervised sentiment classification models, the extraction of sentiment opinions mainly relies on individual sentences. However, in the realm of social text, an individual's sentiment polarity often requires joint analysis of multiple sentences to obtain an effective judgment. Secondly, social text contains temporal information, such as the time when an individual expresses their opinion or chats, which many models do not effectively utilize during modeling. Finally, compared to word vectors, sentence vectors contain more information, and most existing studies use word vectors as input for modeling, neglecting the influence of sentence vectors.

[0006] In view of this, it is very meaningful to propose a social text sentiment classification method and device based on temporal sentence features. Summary of the Invention

[0007] To address the problems existing in the prior art, this invention provides a social text sentiment classification method and apparatus based on temporal sentence features. Based on sentence vector synthesis technology, a Bi-Lstm-attention classifier is constructed with sentence vectors as the granularity. When judging the sentiment category, not only the current sentence is considered, but also the contextual information of the sentence is added, so as to solve the aforementioned technical defects.

[0008] Firstly, this invention proposes a social text sentiment classification method based on temporal sentence features, which includes the following steps:

[0009] Responding to the acquisition of social text data;

[0010] The acquired social text data is classified using a trained base classifier model.

[0011] Based on the judgment result, the upstream and downstream related sentences of the obtained social text are truncated through a time window to obtain the truncated sentences. The truncated sentences are then synthesized into sentence vectors and converted into sentence vectors using tf-dif average calculation.

[0012] The sentence vectors are input into the Bi-Lstm-attention model in temporal order to obtain the final sentiment label of the target text.

[0013] Preferably, the synthesis of the sentence vectors includes synthesizing sentence vectors from the chat text using the wordtovector and tf-idf algorithms, specifically including:

[0014] The training of the basic text classifier involves extracting a portion of chat content from the preprocessed dataset to form a dataset, labeling the extracted dataset, and using the labeled dataset and the TextCnn model to obtain a basic text classification model.

[0015] The words are converted into word vectors. The embedding layer is extracted using the already trained basic classification model. Since the text classification model has already corrected and iterated the embedding layer during the forward and backward propagation iterations, the embedding vector of the basic classifier now contains all the information of the words.

[0016] Sentence vector synthesis uses TF-IDF to average the truncated sentences and convert them into sentence vectors. A higher TF-IDF value indicates a greater importance of a word in the sentence. The formula for TF-IDF is as follows:

[0017]

[0018] Where n k Let represent the number of times the k-th word appears in the sentence, n represent the sum of the occurrences of all words, and N represent the total number of sentences. k This represents the number of sentences containing the k-th word;

[0019] The sentence vector is obtained by weighted summation of the word vectors using the calculated TF-IDF values. The formula for synthesizing the sentence vector is as follows:

[0020]

[0021] Where α i w represents the tf-idf value of the i-th word. i Let m be the word vector of the i-th word, and m be the number of words in the sentence.

[0022] Further preferred options include constructing a Bi-LSTM-attention model:

[0023] Construct sentence vector time series, let text set K = {S} T}, S T The representative text is the text identified as negative by the base classifier in the user's chat messages. Taking the sending time of this text as the center, m sentences identified as negative by the base classifier are extracted forward and backward and added to the text set K = {S}. T-m ,,S T-m+1 ...,S T ,...S T+m-1 ,S T+m}, using the sentence vector synthesis formula, we obtain the sentence vector time series set V = {V T-m ,,V T-m+1 ...,V T ,...V T+m-1 V T+m};

[0024] A Bi-LSTM-attention model is built, with the sentence vector set V as the input of the model. The Bi-LSTM model and attention are used to perform matrix transformation on the sentence vectors in the time series to obtain the output vector that can contain all sentence information. Finally, the softmax layer is used to determine the sentiment category of the sentence based on the category with the highest output probability.

[0025] The loss function and model training are determined. Bi-LSTM-attention uses the ADM optimizer, and the loss function is multi-class cross-entropy, with the function expression as follows:

[0026]

[0027] Where p i y represents the output probability of the neural network. i This represents the actual label value, where n is the number of categories.

[0028] Further preferred options include:

[0029] The input vector of the Bi-LSTM-attention model is a matrix composed of sentence vectors. Let the set of sentences obtained in the preceding and following time intervals be V = {V1,,V2,...,V...} 2m+1}, then the input matrix Where n represents the number of sentences obtained, n = 2m + 1, and d is 768. When the number of sentences obtained is less than 2m + 1, the position of the hit sample at the center point of the time series is used to fill the gap.

[0030] A Bi-LSTM model is used to capture temporal dependency information of sentences. The specific formula is as follows:

[0031]

[0032]

[0033]

[0034] The input to the cell of the LSTM model is the output vector h from the previous step. t-1 The current input sentence vector s t and memory unit c t-1 f(·) represents the LSTM function. This represents the positive hidden layer output vector. w represents the reverse hidden layer output vector. t v t Here is the weight matrix, b is the bias term, and h is the weight matrix. t The latent vector representing the output of Bi-LSTM;

[0035] By concatenating the output sets of Bi-LSTM, a new sentence vector matrix H = [h1, h2, ... h1] is obtained. n The matrix H is processed using self-attention, and the specific formula is as follows:

[0036] p t =tanh(W t *h+b t )

[0037]

[0038]

[0039] b = fullconnect(a)

[0040] Among them W t b t For calculating the weight matrix and bias term when calculating attention, u t Here, denoted as attention weights, a is the output vector after the attention mechanism, and b is the vector after the fully connected layer.

[0041] Further preferred methods include re-labeling the category labels of the hit sentences based on the text of the sentence context. In order to reduce the amount of data for sentence labeling, sentences with a judgment threshold between 0.5 and 0.7 of the BERT-WWM model are given special attention and labeled to form the training set of the model.

[0042] Preferably, in response to acquiring social text data, a portion of the group chat dataset is crawled using a web crawler written in Python. The dataset mainly contains chat information, chat participants, and message sending times. The dataset is standardized and converted into a specific input format. The acquired chat text is then preprocessed and cleaned.

[0043] Further preferred, the data preprocessing specifically includes:

[0044] Use regular expressions to filter out distracting words such as phone numbers, ID numbers, chat prompts, and web links from text.

[0045] The collected emoji, dictionary, and stop word dictionary were used to filter the data for emojis and stop words;

[0046] We used a collection of social text dictionaries as a user dictionary and used the jieba word segmentation tool to process the chat content into words.

[0047] Secondly, embodiments of the present invention also provide a social text sentiment classification device based on temporal sentence features, the device specifically comprising:

[0048] The data acquisition module is configured to acquire social text data.

[0049] The data preprocessing module is configured to use Python-written web crawler code to crawl a portion of the group chat dataset. The dataset mainly contains chat information, chat participants, and message sending times. The dataset is standardized and converted into a specific input format. The obtained chat text is preprocessed and cleaned first.

[0050] The judgment module is configured to use a trained base classifier model to determine the category of the acquired social text data;

[0051] The truncating module is configured to truncate the upstream and downstream related sentences of the acquired social text through a time window based on the judgment result, and obtain the truncated sentences.

[0052] The sentence vector synthesis module is configured to synthesize sentence vectors from the obtained truncated sentences, and convert them into sentence vectors using tf-dif average calculation.

[0053] The Bi-Lstm-attention model module is configured to input the sentence vectors into the Bi-Lstm-attention model in temporal order to obtain the final sentiment label of the target text.

[0054] Thirdly, embodiments of the present invention provide an electronic device, including: one or more processors; and a storage device for storing one or more programs, wherein when the one or more programs are executed by the one or more processors, the one or more processors implement the method described in any implementation of the first aspect.

[0055] Fourthly, embodiments of the present invention provide a computer-readable storage medium having a computer program stored thereon, which, when executed by a processor, implements the method as described in any of the implementations of the first aspect.

[0056] Compared with the prior art, the beneficial results of the present invention are as follows:

[0057] This invention proposes a sentiment classification method with temporal relationships for the social text domain. When performing sentiment analysis on text, it not only incorporates the current text but also comprehensively models and calculates the preceding and following sentences. It innovatively uses sentence vectors as model input vectors and combines them with the Bi-Lst-attention model to make up for the shortcomings of previous sentiment analysis methods in handling temporal text. This method has good application prospects in sentiment polarity analysis and sentiment opinion judgment in social apps and social forums. Attached Figure Description

[0058] The accompanying drawings are included to provide a further understanding of the embodiments and are incorporated in and constitute a part of this specification. The drawings illustrate embodiments and, together with the description, serve to explain the principles of the invention. Other embodiments and many anticipated advantages of the embodiments will be readily recognized as they become better understood through reference to the following detailed description. Elements in the drawings are not necessarily to scale. The same reference numerals refer to corresponding similar parts.

[0059] Figure 1 This is an exemplary device architecture diagram in which an embodiment of the present invention can be applied;

[0060] Figure 2 This is a technical framework diagram of a social text sentiment classification method based on temporal sentence features, as an embodiment of the present invention.

[0061] Figure 3 This is a flowchart illustrating the social text sentiment classification method based on temporal sentence features, as an embodiment of the present invention.

[0062] Figure 4 This is a flowchart of the Bi-LSTM-attention method for social text sentiment classification based on temporal sentence features, as described in an embodiment of the present invention.

[0063] Figure 5 This is a schematic diagram of the architecture of a social text sentiment classification device based on temporal sentence features according to an embodiment of the present invention;

[0064] Figure 6 This is a schematic diagram of the structure of a computer device suitable for implementing electronic devices according to embodiments of the present invention. Detailed Implementation

[0065] In the following detailed description, reference is made to the accompanying drawings, which form part of the detailed description and are illustrated by specific illustrative embodiments in which the invention may be practiced. In this regard, directional terms such as “top,” “bottom,” “left,” “right,” “up,” “down,” etc., are used with reference to the orientation of the described figures. Because components of the embodiments can be positioned in several different orientations, directional terms are used for illustrative purposes and are by no means limiting. It should be understood that other embodiments may be utilized or logical changes may be made without departing from the scope of the invention. Therefore, the following detailed description should not be taken in a limiting sense, and the scope of the invention is defined by the appended claims.

[0066] It should be understood that Figure 1 The number of terminal devices, networks, and servers shown is merely illustrative. Depending on implementation needs, any number of terminal devices, networks, and servers can be included.

[0067] Figure 1 An exemplary system architecture 100 for processing information, or for processing information, to which embodiments of the present invention can be applied, is shown.

[0068] like Figure 1 As shown, system architecture 100 may include terminal devices 101, 102, and 103, a network 104, and a server 105. Network 104 serves as the medium for providing communication links between terminal devices 101, 102, and 103 and server 105. Network 104 may include various connection types, such as wired or wireless communication links, or fiber optic cables, etc.

[0069] Users can use terminal devices 101, 102, and 103 to interact with server 105 via network 104 to receive or send messages, etc. Various communication client applications can be installed on terminal devices 101, 102, and 103, such as web browser applications, shopping applications, search applications, instant messaging tools, email clients, social media platform software, etc.

[0070] Terminal devices 101, 102, and 103 can be various electronic devices with communication functions, including but not limited to smartphones, tablets, laptops, and desktop computers.

[0071] Server 105 can be a server that provides various services, such as a background information processing server that processes verification request information sent by terminal devices 101, 102, and 103. The background information processing server can analyze and process the received verification request information and obtain processing results (such as verification success information used to indicate that the verification request is a valid request).

[0072] It should be noted that the information processing method provided in the embodiments of the present invention is generally executed by server 105, and correspondingly, the device for processing information is generally disposed in server 105. Furthermore, the information sending method provided in the embodiments of the present invention is generally executed by terminal devices 101, 102, and 103, and correspondingly, the device for sending information is generally disposed in terminal devices 101, 102, and 103.

[0073] It should be noted that a server can be either hardware or software. When the server is hardware, it can be implemented as a distributed server cluster consisting of multiple servers, or as a single server. When the server is software, it can be implemented as multiple software programs or software modules (for example, used to provide distributed services), or as a single software program or multiple software modules; no specific limitations are made here.

[0074] The main technology of this invention is to use a trained basic classification model to classify social text. Based on the classification, it extracts related sentences from upstream and downstream of the text through a time window. The extracted sentences are then converted into sentence vectors using TF-DIF average calculation. A Bi-LSTM-attention model is used to input the sentences in chronological order to obtain the final sentiment label for the text. The overall technical framework of the invention is shown in the figure below. Figure 2 As shown.

[0075] In a first aspect, embodiments of the present invention disclose a social text sentiment classification method based on temporal sentence features, such as... Figure 3 As shown, the method includes the following steps:

[0076] S1, responding to the acquisition of social text data;

[0077] S2. Use the trained basic classifier model to determine the category of the acquired social text data;

[0078] S3. Based on the judgment result, the upstream and downstream related sentences of the obtained social text are truncated through a time window to obtain the truncated sentences. The truncated sentences are then synthesized into sentence vectors and converted into sentence vectors using tf-dif average calculation.

[0079] S4. Input the sentence vectors into the Bi-Lstm-attention model in temporal order to obtain the final sentiment label of the target text.

[0080] Specifically, this includes data preprocessing:

[0081] This invention uses Python-written web crawler code to crawl a portion of a group chat dataset. The dataset mainly contains chat information, chat participants, message sending time, etc. The dataset is standardized and converted into a specific input format, as shown in Table 1.

[0082] Table 1 Group Chat Data Format

[0083]

[0084]

[0085] Because social texts are characterized by diverse sentence formats, chaotic syntax, and a large amount of interfering text, preprocessing and cleaning of the chat texts is necessary to facilitate subsequent model training.

[0086] Data preprocessing specifically includes the following steps:

[0087] 1. Use regular expressions to filter out distracting words such as phone numbers, ID numbers, chat prompts, and web links from the text.

[0088] 2. Filter the data using collected emoji, dictionary, and stop word dictionary.

[0089] Third, we used the collected social text dictionary as a user dictionary and used the jieba word segmentation tool to process the chat content into words.

[0090] Furthermore, it also includes sentence vector synthesis:

[0091] This invention utilizes the wordtovector and tf-idf algorithms to synthesize sentence vectors from chat text. It mainly consists of the following steps:

[0092] First, training the basic text classifier. To construct the sentence vectors needed for the model, a basic text classification model needs to be trained. This invention uses the TextCnn model. A portion of the chat content is extracted from the preprocessed dataset to form a dataset. The extracted dataset is then labeled, and a basic text classification model is obtained using the labeled dataset and the TextCnn model.

[0093] Second, words are converted into word vectors. Using the already trained base classification model, the embedding layer is extracted. Since the text classification model has already corrected and iterated the embedding layer during forward and backward propagation iterations, the embedding vector of the base classifier now contains all the information of the words.

[0094] Third, sentence vector synthesis. The TF-IDF algorithm is also one of the algorithms for measuring the importance of words; the larger the TF-IDF value, the higher the importance of the word in the sentence. The formula for TF-IDF is as follows:

[0095]

[0096] Where n k Let represent the number of times the k-th word appears in the sentence, n represent the sum of the occurrences of all words, and N represent the total number of sentences. k This represents the number of sentences containing the k-th word;

[0097] The sentence vector is obtained by weighted summation of the word vectors using the calculated TF-IDF values. The formula for synthesizing the sentence vector is as follows:

[0098]

[0099] Where α i w represents the tf-idf value of the i-th word. i Let m be the word vector of the i-th word, and m be the number of words in the sentence.

[0100] Furthermore, this also includes the construction of Bi-LSTM-attention models:

[0101] To improve the accuracy of sentiment polarity assessment for selected sentences, it is necessary to jointly model sentences in the preceding and following time series, and to determine sentiment polarity based on the speaker's viewpoint over a period of time. To integrate individual statements and comments at various time points, sentence vectors are used as the main input to the model.

[0102] The specific modeling process consists of the following three steps:

[0103] The first step is to construct a sentence vector time series. Let the text set K = {S} T}, S T The representative text is the text identified as negative by the base classifier in the user's chat messages. Taking the sending time of this text as the center, m sentences that were identified as negative by the base classifier are extracted forward and backward and added to the text set K = {S}. T-m ,,S T-m+1 ...,S T ,...S T+m-1 ,S T+m}, using the sentence vector synthesis formula, we obtain the sentence vector time series set V = {V T-m ,,V T-m+1 ...,V T ,...V T+m-1 V T+m}

[0104] The second step is to build a Bi-LSTM-attention model. The model takes a set of sentence vectors V as input and uses the Bi-LSTM model and attention to perform matrix transformations on the sentence vectors in the time series, obtaining an output vector that contains all sentence information. The model's input vector is a matrix composed of sentence vectors. Let the set of sentences obtained within the preceding and following time periods be V = {V1,,V2,...,V...}. 2m+1}, then the input matrix Where n equals 2m+1 (the number of sentences obtained), and d is 768. When the number of sentences obtained is less than 2m+1, the position of the hit sample at the center point of the time series is used to fill the gap.

[0105] To integrate the temporal information of all sentences, this invention employs a Bi-LSTM model to capture the temporal dependencies between sentences. The Bi-LSTM model effectively captures the dependencies between sentence vectors; the specific formula is as follows:

[0106]

[0107]

[0108]

[0109] The input to the cell of the LSTM model is the output vector h from the previous step. t-1 The current input sentence vector s t and memory unit c t-1 f(·) represents the LSTM function. This represents the positive hidden layer output vector. w represents the reverse hidden layer output vector. t v t Here, b is the weight matrix, and h is the bias term, which is used to fuse the forward and backward hidden layer vectors. t This represents the latent vector output by Bi-Lstm.

[0110] By concatenating the output sets of Bi-LSTM, a new sentence vector matrix H = [h1, h2, ... h1] is obtained. n Since different sentences in the extracted sentences have varying degrees of influence on the current sentence, a self-attention process is applied to matrix H to better measure the impact of the hidden vector output by the Bi-LSTM on the hidden vector of the current sentence. The specific formula is as follows:

[0111] p t =tanh(W t*h+b t )

[0112]

[0113]

[0114] b = fullconnect(a)

[0115] Among them W t b t For calculating the weight matrix and bias term when calculating attention, u t Here, 'a' represents the attention weights, 'b' represents the output vector after the attention mechanism, and 'a' represents the vector after the fully connected layer. Finally, the softmax layer determines the sentiment category of the sentence by selecting the category with the highest output probability.

[0116] The third step is to determine the loss function and model training. Bi-LSTM-attention uses the ADM optimizer, and the loss function is multi-class cross-entropy, with the following expression:

[0117]

[0118] Where p i y represents the output probability of the neural network. i represents the true label value, and n is the number of categories. The category labels of the sentences that match the criteria need to be re-labeled based on the context text. To reduce the amount of data for sentence labeling, this embodiment focuses on and labels sentences whose judgment threshold of the BERT-WWM model is between 0.5 and 0.7, forming the training set for the model. The framework diagram of Bi-LSTM-attention is as follows. Figure 4 As shown.

[0119] This invention proposes a sentiment classification method with temporal relationships for social text. When performing sentiment analysis, it not only incorporates the current text but also models and calculates the combined effects of preceding and following sentences. It innovatively uses sentence vectors as model input vectors and combines them with a Bi-Lst-attention model to overcome the shortcomings of previous sentiment analysis methods in handling temporal text. This method shows promising application prospects in sentiment polarity analysis and sentiment opinion judgment in social apps and social forums.

[0120] This invention requires consideration of the context of the hit text when labeling the hit data, which is too difficult for manual labeling. The sentence vectors synthesized using TF-IDF do not consider the word order. Further improvements will be made to address these shortcomings.

[0121] Secondly, embodiments of the present invention also disclose a social text sentiment classification device based on temporal sentence features, such as... Figure 5 As shown, the device specifically includes: a data acquisition module 51, a data preprocessing module 52, a judgment module 53, a truncation module 54, a sentence vector synthesis module 55, and a Bi-Lstm-attention model module 56.

[0122] In one specific embodiment, the data acquisition module 51 is configured to acquire social text data; the data preprocessing module 52 is configured to use a web crawler written in Python to crawl a portion of the group chat dataset, the dataset mainly containing chat information, chat participants, and message sending time, and to convert the dataset into a specific input format by standardizing the dataset, and to preprocess and clean the acquired chat text data first; the judgment module 53 is configured to use a trained basic classifier model to judge the category of the acquired social text data; the truncation module 54 is configured to truncate the upstream and downstream related sentences of the acquired social text through a time window according to the judgment result, and obtain the truncated sentences; the sentence vector synthesis module 55 is configured to synthesize the sentence vectors of the obtained truncated sentences, and to convert them into sentence vectors by using TF-DIF average calculation; the Bi-LSTM-attention model module 56 is configured to input the sentence vectors into the Bi-LSTM-attention model in chronological order to obtain the final sentiment label of the target text.

[0123] The following is for reference. Figure 6 It illustrates an electronic device suitable for implementing embodiments of the present invention (e.g., Figure 1 The diagram shows the structure of a computer device 600 (a server or terminal device). Figure 6 The electronic device shown is merely an example and should not be construed as limiting the functionality and scope of use of the embodiments of the present invention.

[0124] like Figure 6 As shown, the computer device 600 includes a central processing unit (CPU) 601 and a graphics processing unit (GPU) 602, which can perform various appropriate actions and processes according to programs stored in read-only memory (ROM) 603 or programs loaded from storage section 609 into random access memory (RAM) 604. The RAM 604 also stores various programs and data required for the operation of the device 600. The CPU 601, GPU 602, ROM 603, and RAM 604 are interconnected via a bus 605. An input / output (I / O) interface 606 is also connected to the bus 605.

[0125] The following components are connected to I / O interface 606: an input section 607 including a keyboard, mouse, etc.; an output section 608 including an LCD, speakers, etc.; a storage section 609 including a hard disk, etc.; and a communication section 610 including a network interface card, such as a LAN card or modem. The communication section 610 performs communication processing via a network such as the Internet. A drive 611 may also be connected to I / O interface 606 as needed. A removable medium 612, such as a hard disk, optical disk, magneto-optical disk, semiconductor memory, etc., is installed on drive 611 as needed so that computer programs read from it can be installed into storage section 609 as needed.

[0126] In particular, according to embodiments disclosed in this invention, the processes described above with reference to the flowcharts can be implemented as computer software programs. For example, embodiments disclosed in this invention include a computer program product comprising a computer program carried on a computer-readable medium, the computer program containing program code for performing the methods shown in the flowcharts. In such embodiments, the computer program can be downloaded and installed from a network via communication section 610, and / or installed from removable medium 612. When the computer program is executed by central processing unit (CPU) 601 and graphics processing unit (GPU) 602, the functions defined in the methods of this invention are performed.

[0127] It should be noted that the computer-readable medium described in this invention can be a computer-readable signal medium, a computer-readable medium, or any combination thereof. A computer-readable medium can be, for example,—but not limited to—an electrical, magnetic, optical, electromagnetic, infrared, or semiconductor device, apparatus, or any combination thereof. More specific examples of a computer-readable medium may include, but are not limited to: an electrical connection having one or more wires, a portable computer disk, a hard disk, random access memory (RAM), read-only memory (ROM), erasable programmable read-only memory (EPROM or flash memory), optical fiber, portable compact disk read-only memory (CD-ROM), optical storage device, magnetic storage device, or any suitable combination thereof. In this invention, a computer-readable medium can be any tangible medium containing or storing a program that can be used by or in conjunction with an instruction execution apparatus, device, or device. In this invention, a computer-readable signal medium can include a data signal propagated in baseband or as part of a carrier wave, carrying computer-readable program code. Such propagated data signals can take various forms, including but not limited to electromagnetic signals, optical signals, or any suitable combination thereof. Computer-readable signal media can also be any computer-readable medium other than a computer-readable medium, which can send, propagate, or transmit a program for use by or in connection with an instruction execution device, apparatus, or apparatus. The program code contained on the computer-readable medium can be transmitted using any suitable medium, including but not limited to: wireless, wire, optical fiber, RF, etc., or any suitable combination thereof.

[0128] Computer program code for performing the operations of this invention can be written in one or more programming languages ​​or a combination thereof, including object-oriented programming languages ​​such as Java, Smalltalk, and C++, as well as conventional procedural programming languages ​​such as "C" or similar programming languages. The program code can be executed entirely on the user's computer, partially on the user's computer, as a standalone software package, partially on the user's computer and partially on a remote computer, or entirely on a remote computer or server. In cases involving remote computers, the remote computer can be connected to the user's computer via any type of network—including a local area network (LAN) or a wide area network (WAN)—or can be connected to an external computer (e.g., via the Internet using an Internet service provider).

[0129] The flowcharts and block diagrams in the accompanying drawings illustrate the architecture, functionality, and operation of possible implementations of apparatus, methods, and computer program products according to various embodiments of the present invention. In this regard, each block in a flowchart or block diagram may represent a module, segment, or portion of code containing one or more executable instructions for implementing a specified logical function. It should also be noted that in some alternative implementations, the functions indicated in the blocks may occur in a different order than those indicated in the drawings. For example, two consecutively indicated blocks may actually be executed substantially in parallel, and they may sometimes be executed in reverse order, depending on the functions involved. It should also be noted that each block in the block diagrams and / or flowcharts, and combinations of blocks in the block diagrams and / or flowcharts, may be implemented using dedicated hardware-based devices that perform the specified functions or operations, or using a combination of dedicated hardware and computer instructions.

[0130] The modules described in the embodiments of the present invention can be implemented in software or hardware. The described modules can also be located in a processor.

[0131] In another aspect, the present invention also provides a computer-readable medium, which may be included in the electronic device described in the above embodiments; or it may exist independently and not assembled into the electronic device. The computer-readable medium carries one or more programs, which, when executed by the electronic device, cause the electronic device to: respond to acquiring social text data; perform category determination on the acquired social text data using a trained base classifier model; based on the determination result, truncate the upstream and downstream related sentences of the acquired social text through a time window to obtain truncated sentences; synthesize sentence vectors from the obtained truncated sentences, and convert them into sentence vectors using TF-DIF average calculation; input the sentence vectors into a Bi-LSTM-attention model in temporal order to obtain the final sentiment label of the target text.

[0132] The above description is merely a preferred embodiment of the present invention and an explanation of the technical principles employed. Those skilled in the art should understand that the scope of the invention is not limited to the specific combination of the above-described technical features, but also includes other technical solutions formed by arbitrary combinations of the above-described technical features or their equivalents without departing from the inventive concept. For example, technical solutions formed by substituting the above-described features with (but not limited to) technical features with similar functions disclosed in this invention.

Claims

1. A social text sentiment classification method based on temporal sentence features, characterized in that, The method includes the following steps: Responding to the acquisition of social text data; The acquired social text data is classified using a trained base classifier model. Based on the judgment result, the upstream and downstream related sentences of the obtained social text are truncated through a time window to obtain the truncated sentences. The truncated sentences are then synthesized into sentence vectors and converted into sentence vectors using tf-dif average calculation. The synthesis of the sentence vectors includes synthesizing sentence vectors from the chat text using the wordtovector and tf-idf algorithms, specifically including: The training of the basic text classifier involves extracting a portion of chat content from the preprocessed dataset to form a dataset, labeling the extracted dataset, and using the labeled dataset and the TextCnn model to obtain a basic text classification model. Words are converted into word vectors, and the embedding layer is extracted using the already trained basic classification model. Since the text classification model has already corrected and iterated the embedding layer during forward and backward propagation iterations, the embedding vectors of the basic classifier now contain all the information of the words. Sentence vector synthesis uses TF-IDF to average the truncated sentences and convert them into sentence vectors; a larger TF-IDF value indicates a higher importance of the word in the sentence. The sentence vectors are input into the Bi-Lstm-attention model in temporal order to obtain the final sentiment label of the target text.

2. The social text sentiment classification method based on temporal sentence features according to claim 1, characterized in that, The formula for Tf-idf is as follows: Where n k Let represent the number of times the k-th word appears in the sentence, n represent the sum of the occurrences of all words, and N represent the total number of sentences. k This represents the number of sentences containing the k-th word; The sentence vector is obtained by weighted summation of the word vectors using the calculated TF-IDF values. The formula for synthesizing the sentence vector is as follows: Where α i w represents the tf-idf value of the i-th word. i Let m be the word vector of the i-th word, and m be the number of words in the sentence.

3. The social text sentiment classification method based on temporal sentence features according to claim 2, characterized in that, This also includes building a Bi-LSTM-attention model: Construct sentence vector time series, let text set K = {S} T }, S T The representative text is the text identified as negative by the base classifier in the user's chat messages. Taking the sending time of this text as the center, m sentences identified as negative by the base classifier are extracted forward and backward and added to the text set K = {S}. T-m ,S T-m+1... ,S T ,...S T+m-1 ,S T+m }, using the sentence vector synthesis formula, we obtain the sentence vector time series set V = {V T-m V T-m+1 ...,V T ,...V T+m-1 V T+m }; A Bi-LSTM-attention model is built, with the sentence vector set V as the input of the model. The Bi-LSTM model and attention are used to perform matrix transformation on the sentence vectors in the time series to obtain the output vector that can contain all sentence information. Finally, the softmax layer is used to determine the sentiment category of the sentence based on the category with the highest output probability. The loss function and model training are determined. Bi-LSTM-attention uses the ADM optimizer, and the loss function is multi-class cross-entropy, with the function expression as follows: Where p i y represents the output probability of the neural network. i This represents the actual label value, where n is the number of categories.

4. The social text sentiment classification method based on temporal sentence features according to claim 3, characterized in that, Also includes: The input vector of the Bi-LSTM-attention model is a matrix composed of sentence vectors. Let the set of sentences obtained in the preceding and following time intervals be V = {V1, V2, ..., V...} 2m+1 }, then the input matrix V * n*d =V1⊕V2...V 2m+1 Where n represents the number of sentences obtained, n = 2m + 1, and d is 768. When the number of sentences obtained is less than 2m + 1, the position of the hit sample at the center point of the time series is used to fill the gap. A Bi-LSTM model is used to capture temporal dependency information of sentences. The specific formula is as follows: The input to the cell of the LSTM model is the output vector h from the previous step. t-1 The current input sentence vector s t and memory unit c t-1 f(·) represents the LSTM function. This represents the positive hidden layer output vector. w represents the reverse hidden layer output vector. t v t Here is the weight matrix, b is the bias term, and h is the weight matrix. t The latent vector representing the output of Bi-LSTM; By concatenating the output sets of Bi-LSTM, a new sentence vector matrix H = [h1, h2, ... h1] is obtained. n The matrix H is processed using self-attention, and the specific formula is as follows: p t =tanh(W t *h+b t ) k=2m+1 k=2m+1 b = fullconnect(a) Among them W t b t For calculating the weight matrix and bias term when calculating attention, u t Here, denoted as attention weights, a is the output vector after the attention mechanism, and b is the vector after the fully connected layer.

5. The social text sentiment classification method based on temporal sentence features according to claim 4, characterized in that, It also includes the need to re-label the category labels of the hit sentences based on the text of the sentence context. In order to reduce the amount of data for sentence labeling, sentences with a judgment threshold between 0.5 and 0.7 of the BERT-WWM model are given special attention and labeled to form the training set of the model.

6. The social text sentiment classification method based on temporal sentence features according to claim 1, characterized in that, In response to the acquisition of social text data, a portion of the group chat dataset was crawled using Python web crawler code. The dataset mainly contains chat information, chat participants, and message sending times. The dataset was standardized and converted into a specific input format. The acquired chat text was then preprocessed and cleaned.

7. The social text sentiment classification method based on temporal sentence features according to claim 6, characterized in that, Data preprocessing specifically includes: Use regular expressions to filter out distracting words such as phone numbers, ID numbers, chat prompts, and web links from text. The collected emoji, dictionary, and stop word dictionary were used to filter the data for emojis and stop words; We used a collection of social text dictionaries as a user dictionary and used the jieba word segmentation tool to process the chat content into words.

8. A social text sentiment classification device based on temporal sentence features, characterized in that, The device specifically includes: The data acquisition module is configured to acquire social text data. The data preprocessing module is configured to use Python-written web crawler code to crawl a portion of the group chat dataset. The dataset mainly contains chat information, chat participants, and message sending times. The dataset is standardized and converted into a specific input format. The obtained chat text is preprocessed and cleaned first. The judgment module is configured to use a trained base classifier model to determine the category of the acquired social text data; The truncating module is configured to truncate the upstream and downstream related sentences of the acquired social text through a time window based on the judgment result, and obtain the truncated sentences. The sentence vector synthesis module is configured to synthesize sentence vectors from the obtained truncated sentences, using tf-idf average calculation to convert them into sentence vectors. The sentence vector synthesis includes synthesizing sentence vectors from chat text using the wordtovector and tf-idf algorithms. Specifically, this includes: training a basic text classifier by extracting a portion of chat content from a preprocessed dataset to form a dataset, labeling the extracted dataset, and using the labeled dataset and the TextCnn model to obtain a basic text classification model; converting words into word vectors by extracting the embedding layer from the already trained basic classification model. Since the text classification model has already corrected and iterated the embedding layer during forward and backward propagation iterations, the embedding vector of the basic classifier now contains all the word information; and sentence vector synthesis by using tf-idf to convert the truncated sentences into sentence vectors, where a larger tf-idf value indicates a higher importance of the word in the sentence. The Bi-Lstm-attention model module is configured to input the sentence vectors into the Bi-Lstm-attention model in temporal order to obtain the final sentiment label of the target text.

9. An electronic device, comprising: One or more processors; Storage device for storing one or more programs; When the one or more programs are executed by the one or more processors, the one or more processors implement the method as described in any one of claims 1 to 7.

10. A computer-readable storage medium having a computer program stored thereon, characterized in that, When the program is executed by the processor, it implements the method as described in any one of claims 1 to 7.

Citation Information

Patent Citations

  • Text sentiment analysis method and system, and computer readable storage medium

    CN108170681A

  • Text information processing method and device, storage medium and electronic equipment

    CN111539212A