Bert-based sentiment analysis method and device based on key sentences
By augmenting news headlines and filtering key sentences, the problem of insufficient data in news sentiment analysis was solved, enabling more accurate sentiment prediction.
Patent Information
- Application Number
- CN202211737783.2
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2022-12-30
- Publication Date
- 2026-11-03
- Estimated Expiration
- 2042-12-30
AI Technical Summary
In existing news sentiment analysis, the accuracy of predictions is not high due to insufficient data collection.
By augmenting the news data titles, multiple synonym data are generated. Key sentences with high similarity to the synonym data are selected from the content data, concatenated, and then input into the BERT model to determine the sentiment type.
The accuracy of sentiment prediction based on news data has been improved by using more sentence data that reflects the news theme as input, thus enhancing the model's predictive performance.
Smart Images

Figure CN116151237B_ABST
Abstract
Description
Technical Field
[0001] This invention relates to the field of artificial intelligence technology, and in particular to a Bert sentiment analysis method and apparatus based on key sentences. Background Technology
[0002] In sentiment analysis of news data, the data is typically extracted and input into a BERT model to determine the sentiment type of the news data.
[0003] Existing news sentiment analysis methods simply extract news data directly and input the extracted segments into the model for prediction, or match summaries from news data to train and predict the model, or perform segment-level recursion based on news data before making model predictions. These methods only extract a small amount of news data, resulting in insufficient data and low prediction accuracy. Summary of the Invention
[0004] This invention provides a BERT sentiment analysis method and apparatus based on key sentences to solve the technical problem that the existing technology has insufficient data volume in the process of extracting news data and inputting it into the model for prediction, resulting in low prediction accuracy.
[0005] This invention provides a BERT sentiment analysis method based on key sentences, comprising:
[0006] Data augmentation processing is performed on the headline data of the news data to obtain multiple synonyms of the headline data;
[0007] From the content data of the news data, obtain key sentence data whose similarity to the synonym data is greater than a preset similarity threshold;
[0008] The obtained key sentence data is concatenated and then input into the BERT model to determine the sentiment type of the news data. The BERT model is trained based on the news data samples and their corresponding sentiment type labels.
[0009] According to a BERT sentiment analysis method based on key sentences provided by the present invention, key sentence data with a similarity greater than a preset similarity threshold to the synonym data is obtained from the content data of the news data, including:
[0010] The sentence data in the content data is traversed, and the similarity between each synonym and the sentence data is determined. Sentence data with a similarity greater than a preset similarity threshold are taken as key sentence data of the content data.
[0011] According to a BERT sentiment analysis method based on key sentences provided by the present invention, the similarity between each synonym data and the sentence data is determined, including:
[0012] Based on the number of shared words in synonym data and sentence data, the total number of words in the synonym data, and the total number of words in the sentence data, a similarity calculation formula for synonym data and sentence data is determined.
[0013] Based on the similarity calculation formula, the similarity between each synonym data and the sentence data is determined.
[0014] According to the BERT sentiment analysis method based on key sentences provided by this invention, the similarity calculation formula is as follows:
[0015]
[0016] Where W represents the similarity between synonym data and sentence data, X represents the number of shared words in synonym data and sentence data, Y represents the total number of words in synonym data, and Z represents the total number of words in sentence data.
[0017] According to the BERT sentiment analysis method based on key sentences provided by the present invention, the data augmentation processing includes at least one of the following: synonym replacement processing, random insertion processing, random swapping processing, and random deletion processing.
[0018] According to the BERT sentiment analysis method based on key sentences provided by the present invention, before inputting the concatenated sentence data into the BERT model, the method further includes:
[0019] If the length of the concatenated sentence data is greater than the preset length, the concatenated sentence data is truncated to determine that the length of the concatenated sentence data is less than or equal to the preset length.
[0020] The present invention also provides a BERT sentiment analysis device based on key sentences, comprising:
[0021] An augmentation processing module is used to perform data augmentation processing on the title data of news data to obtain multiple synonym data of the title data;
[0022] The filtering module is used to extract key sentence data from the content data of the news data that has a similarity greater than a preset similarity threshold with the synonym data;
[0023] The model processing module is used to concatenate multiple key sentence data and input the concatenated sentence data into the BERT model to determine the sentiment type of the news data. The BERT model is trained based on news data samples and their corresponding sentiment type labels.
[0024] The present invention also provides an electronic device, including a memory, a processor, and a computer program stored in the memory and executable on the processor, wherein the processor executes the computer program to implement the BERT sentiment analysis method based on key sentences as described above.
[0025] The present invention also provides a non-transitory computer-readable storage medium having a computer program stored thereon, wherein the computer program, when executed by a processor, implements any of the key sentence-based BERT sentiment analysis methods described above.
[0026] The present invention also provides a computer program product, including a computer program that, when executed by a processor, implements the BERT sentiment analysis method based on key sentences as described above.
[0027] The BERT sentiment analysis method and apparatus based on key sentences provided by this invention obtains multiple synonyms from the headline data of news data by performing data augmentation on the headline data. Sentences with high relevance to these synonyms are extracted from the content data of the news data and used as input to the subsequent BERT model. This enables the prediction of the sentiment tendency of news data by obtaining more information reflecting the news theme from the content data, thereby improving the accuracy of sentiment tendency prediction for news data. Attached Figure Description
[0028] To more clearly illustrate the technical solutions in this invention or the prior art, the accompanying drawings used in the description of the embodiments or the prior art will be briefly described below. Obviously, the accompanying drawings described below are some embodiments of this invention. For those skilled in the art, other drawings can be obtained based on these drawings without creative effort.
[0029] Figure 1 This is a flowchart illustrating the BERT sentiment analysis method based on key sentences provided by this invention.
[0030] Figure 2 This is a flowchart illustrating the application of the BERT sentiment analysis method based on key sentences provided by this invention.
[0031] Figure 3 This is a schematic diagram of the Bert sentiment analysis device based on key sentences provided by the present invention;
[0032] Figure 4 This is a schematic diagram of the structure of the electronic device provided by the present invention. Detailed Implementation
[0033] To make the objectives, technical solutions, and advantages of this invention clearer, the technical solutions of this invention will be clearly and completely described below with reference to the accompanying drawings. Obviously, the described embodiments are only some, not all, of the embodiments of this invention. All other embodiments obtained by those skilled in the art based on the embodiments of this invention without creative effort are within the scope of protection of this invention.
[0034] This invention provides a BERT sentiment analysis method based on key sentences. Figure 1 This is a flowchart illustrating the BERT sentiment analysis method based on key sentences provided by this invention. (Refer to...) Figure 1 The BERT sentiment analysis method based on key sentences provided by this invention may include:
[0035] Step 110: Perform data augmentation on the title data of the news data to obtain multiple synonym data of the title data;
[0036] Step 120: Obtain key sentence data from the content data of the news data that has a similarity greater than a preset similarity threshold with the synonym data;
[0037] Step 130: The obtained multiple key sentence data are concatenated and the concatenated sentence data is input into the BERT model to determine the sentiment type of the news data. The BERT model is trained based on the news data samples and their corresponding sentiment type labels.
[0038] The executor of the BERT sentiment analysis method based on key sentences provided by this invention can be an electronic device, a component within an electronic device, an integrated circuit, or a chip. The electronic device can be a mobile electronic device or a non-mobile electronic device. For example, a mobile electronic device can be a mobile phone, tablet computer, laptop computer, PDA, ultra-mobile personal computer (UMPC), netbook, or personal digital assistant (PDA), etc., while a non-mobile electronic device can be a server, network attached storage (NAS), or personal computer (PC), etc. This invention does not impose specific limitations.
[0039] The technical solution of this invention will be described in detail below using the BERT sentiment analysis method based on key sentences provided by this invention, which is executed by a computer.
[0040] In step 110, the headline data in the news data is subjected to data augmentation processing to obtain multiple synonyms of the headline data.
[0041] News data includes headline data and body text data. Generally, the headline data in news data reflects the core summary of the entire news story, but the specific content is revealed in the body text.
[0042] After obtaining the headline data from the news data, the obtained headline data is subjected to data augmentation processing.
[0043] Data augmentation is a technique for automatically expanding training data; it simply means increasing the scale of the data. The use and training of deep learning models require a large amount of labeled data. In real-world applications, problems such as a lack of labeled data and uneven data distribution often lead to poor model robustness and performance. Data augmentation can solve these problems to some extent.
[0044] Optional data augmentation processing includes synonym replacement, random insertion, random swapping, and random deletion.
[0045] Synonyms Replacement involves randomly selecting n words from the title data, then randomly selecting synonyms from a thesaurus and replacing them.
[0046] Randomly insert processing involves randomly selecting a word from the title data, then randomly choosing one from the set of synonyms for that word, and inserting it into a random position in the original sentence. This process can be repeated n times.
[0047] Randomly swapping involves randomly selecting two words from the title data and swapping their positions. This process can be repeated n times.
[0048] Randomly delete processing involves randomly deleting each word in the title data with a set probability p.
[0049] Understandably, after obtaining the headline data from news articles, data augmentation can be performed on the headline data to obtain multiple synonyms with similar meanings. Based on these multiple synonyms, the input to subsequent models or the sample data for model training can be enriched.
[0050] In step 120, after obtaining multiple synonyms of the title data in step 110, based on similarity, key sentence data with a similarity greater than a preset similarity threshold is obtained from the content data of the news data.
[0051] Based on multiple synonym data from the news headline data, the content data of the news data is filtered to select content data that reflects the core theme of the news. Key sentences from the acquired news content data with a similarity greater than a preset similarity threshold to synonym data are used as the filtered content data that reflects the core theme of the news.
[0052] By filtering each sentence in the news data, sentences with low similarity can be removed based on the calculation of the similarity between each sentence and each synonym.
[0053] Understandably, based on the similarity between each sentence in the news content data and its synonyms, each sentence in the content data is filtered, and the sentences with high similarity are selected as key sentences. Key sentences are those that reflect the core viewpoint of the news data. At the same time, by using multiple synonyms from the title data, rather than just the title data, more sentences that reflect the news content can be obtained, facilitating subsequent processing based on the model.
[0054] In step 130, the multiple key sentence data obtained in step 120 are concatenated, and the concatenated sentence data is input into the BERT model to determine the sentiment type of the news data. The BERT model is trained based on news data samples and their corresponding sentiment type labels.
[0055] BERT is a neural network model that predicts sentiment based on input text data. The BERT (Bidirectional Encoder Representation from Transformers) model is essentially a bidirectional encoder for Transformers. The basic ensemble unit of BERT is the Transformer encoder, but its semantic understanding capabilities surpass those of other models like Transformers. The BERT model utilizes the Transformer's attention mechanism to learn the contextual relationships between words in the text. The Transformer consists of two independent mechanisms: an encoder that reads the text input and a decoder that generates predictions for the task. Because BERT aims to generate a language model, only the encoder mechanism is needed. Unlike directional models that read text input sequentially (from left to right or right to left), the Transformer encoder reads the entire word sequence at once, thus it is considered bidirectional. This characteristic allows the model to learn the context of a word based on its surrounding environment (its left and right neighbors).
[0056] Before using the BERT model, it must be trained first. Obtain news data samples and their corresponding sentiment type labels, and then train the initial BERT model. The sentiment type can be positive, neutral, negative, etc.
[0057] After training the BERT model, multiple key sentence data points are concatenated, and the concatenated sentence data is input into the BERT model. Based on the BERT model, the sentiment type of the news data is identified, thus determining the sentiment type of the news data.
[0058] Understandably, in news sentiment analysis, the structure of a news article includes a headline and body. While headlines typically reveal the news content, their limited length often results in insufficient information for classification, making direct sentiment prediction based solely on headlines inaccurate. Extracting highly relevant sentences from the news data to form key sentences, which then serve as input to the BERT model, can address the accuracy issue in sentiment analysis of long texts.
[0059] The BERT sentiment analysis method based on key sentences provided in this invention augments the headline data of news data to obtain multiple synonyms. Sentences highly relevant to these synonyms are then extracted from the content data of the news data and used as input to the subsequent BERT model. This improves the accuracy of sentiment prediction for news data by extracting more information reflecting the news theme from the content data.
[0060] In one embodiment, obtaining key sentence data from the content data of the news data that has a similarity greater than a preset similarity threshold with the synonym data includes: traversing the sentence data in the content data, determining the similarity between each synonym data and the sentence data, and using the sentence data with a similarity greater than the preset similarity threshold as the key sentence data of the content data.
[0061] After obtaining multiple synonyms from the title data, key sentence data with a similarity greater than a preset similarity threshold is extracted from the content data of the news data. This process iterates through all sentence data within the content data. Sentence data is determined by the individual sentences that constitute the news content. One sentence in the news content corresponds to one sentence data point.
[0062] The similarity between each synonym and the content data is determined, and sentence data with a similarity greater than a preset similarity threshold is identified as key sentence data in the content data.
[0063] Understandably, based on the similarity between each sentence in the news content data and its synonyms, each sentence in the content data is filtered, and the sentences with high similarity are selected as key sentences. Key sentences are those that reflect the core viewpoint of the news data. At the same time, by using multiple synonyms from the title data, rather than just the title data, more sentences that reflect the news content can be obtained, facilitating subsequent processing based on the model.
[0064] The BERT sentiment analysis method based on key sentences provided in this invention extracts sentences with high relevance to multiple synonyms from the content data of news data as input to the subsequent BERT model. This enables the identification of more data reflecting the news theme from the content data of news data to predict the sentiment tendency of news data, thereby improving the accuracy of sentiment tendency prediction for news data.
[0065] In one embodiment, a similarity calculation formula for synonym data and sentence data is determined based on the number of shared words in synonym data and sentence data, the total number of words in the synonym data, and the total number of words in the sentence data; and the similarity between each synonym data and the sentence data is determined based on the similarity calculation formula.
[0066] When determining the similarity between synonym data and sentence data, it can be based on the number of shared words in the synonym data and sentence data, the total number of words in the synonym data, and the total number of words in the sentence data.
[0067] Understandably, the proportion of shared words can be determined based on the number of shared words in synonym data and sentence data, the total number of words in synonym data, and the total number of words in sentence data. A higher proportion of shared words indicates a higher similarity between synonym data and sentence data, while a lower proportion indicates a lower similarity. Therefore, a formula for calculating the similarity between synonym data and sentence data can be determined based on the number of shared words in synonym data and sentence data, the total number of words in synonym data, and the total number of words in sentence data.
[0068] After determining the formula for calculating the similarity between synonym data and sentence data, the similarity between each synonym data and the sentence data in the news content is determined, thereby enabling the filtering of content data in the news data.
[0069] Understandably, based on the similarity between each sentence in the news content data and its synonyms, each sentence in the content data is filtered, and the sentences with high similarity are selected as key sentences. Key sentences are those that reflect the core viewpoint of the news data. At the same time, by using multiple synonyms from the title data, rather than just the title data, more sentences that reflect the news content can be obtained, facilitating subsequent processing based on the model.
[0070] The BERT sentiment analysis method based on key sentences provided in this invention realizes the similarity calculation formula between synonym data and sentence data by using the number of common words in synonym data and sentence data, the total number of words in synonym data, and the total number of words in sentence data, thus providing a foundation for subsequent filtering of news content data.
[0071] In one embodiment, the similarity calculation formula is:
[0072]
[0073] Where W represents the similarity between synonym data and sentence data, X represents the number of shared words in synonym data and sentence data, Y represents the total number of words in synonym data, and Z represents the total number of words in sentence data.
[0074] The formula for calculating the similarity between synonym data and sentence data is determined by identifying the number of shared words in synonym data and sentence data, the total number of words in synonym data, and the total number of words in sentence data.
[0075] The formula for calculating similarity is:
[0076]
[0077] Where W represents the similarity between synonym data and sentence data, X represents the number of shared words in synonym data and sentence data, Y represents the total number of words in synonym data, and Z represents the total number of words in sentence data.
[0078] Understandably, based on a defined similarity formula, the proportion of shared words can be determined. The higher the proportion of shared words between synonym data and sentence data, the higher the similarity between the synonym data and sentence data; conversely, the lower the proportion of shared words between synonym data and sentence data, the lower the similarity between the synonym data and sentence data.
[0079] The BERT sentiment analysis method based on key sentences provided in this invention realizes the similarity calculation formula between synonym data and sentence data by using the number of common words in synonym data and sentence data, the total number of words in synonym data, and the total number of words in sentence data, thus providing a foundation for subsequent filtering of news content data.
[0080] In one embodiment, the data augmentation process includes at least one of the following: synonym replacement processing, random insertion processing, random swapping processing, and random deletion processing.
[0081] In the process of augmenting the headline data of news data, the augmentation process includes at least one of the following: synonym replacement, random insertion, random swapping, and random deletion.
[0082] Specifically, the synonym replacement process involves randomly selecting n words from the title data, then randomly selecting synonyms from a thesaurus and replacing them. These synonyms are typically verbs, nouns, or sentiment words.
[0083] Randomly insert processing involves randomly selecting a word from the title data, then randomly choosing one from the set of synonyms for that word, and inserting it into a random position in the original sentence. This process can be repeated n times.
[0084] Randomly swapping involves randomly selecting two words from the title data and swapping their positions. This process can be repeated n times.
[0085] Randomly delete processing involves randomly deleting each word in the title data with a set probability p.
[0086] Understandably, after obtaining the headline data from news articles, data augmentation can be performed on the headline data to obtain multiple synonyms with similar meanings. Based on these multiple synonyms, the input to subsequent models or the sample data for model training can be enriched.
[0087] The BERT sentiment analysis method based on key sentences provided in this invention expands the title data after acquiring the title data of the news data. This allows for the acquisition of more data reflecting the news theme from the content data of the news data to predict the sentiment tendency of the news data, thereby improving the accuracy of the sentiment tendency prediction for the news data.
[0088] In one embodiment, before inputting the concatenated sentence data into the BERT model, the method further includes: if the length of the concatenated sentence data is greater than a preset length, truncating the concatenated sentence data to determine that the length of the concatenated sentence data is less than or equal to the preset length.
[0089] When concatenating multiple key sentence data, the resulting concatenated sentence data may be too long, making it impossible for the sentiment analysis model to identify it. Therefore, it is necessary to determine the length of the concatenated sentence data. If the length of the concatenated sentence data exceeds a preset length, the concatenated sentence data can be truncated.
[0090] For example, the BERT model can support a maximum token length of 512 words. If too many key sentence data are selected, it may be impossible to perform subsequent predictions based on the BERT model.
[0091] Therefore, when the concatenated sentence data is obtained, its length is judged. If the length of the concatenated sentence data is greater than 512 words, the concatenated sentence data is truncated to ensure that its length is less than or equal to 512 words.
[0092] The BERT sentiment analysis method based on key sentences provided in this invention determines the length of the concatenated sentence data. If the length of the concatenated sentence data is greater than a preset length, the concatenated sentence data is truncated to ensure that the length of the concatenated sentence data is less than or equal to the preset length. This provides a foundation for subsequent sentiment prediction based on the BERT model.
[0093] The following is a flowchart illustrating the application of the BERT sentiment analysis method based on key sentences provided by this invention. Figure 2 For example, the technical solution provided by this invention will be explained:
[0094] Step 210: Augment the headline data of the news data to obtain multiple synonyms for the headline data;
[0095] Step 220: Based on multiple synonym data, determine the key sentence data in the content data of the news data. The key sentence data is determined based on the similarity between the synonym data and the sentence data in the content data.
[0096] Step 230 involves concatenating multiple key sentence data and inputting the concatenated sentence data into the BERT model to obtain the sentiment type of the news data output by the BERT model. The BERT model is trained based on news data samples and their corresponding sentiment type labels.
[0097] Figure 3 A schematic diagram of the BERT sentiment analysis device based on key sentences provided by the present invention is shown below. Figure 3 As shown, the device includes:
[0098] The augmentation processing module 310 is used to perform data augmentation processing on the title data of news data to obtain multiple synonym data of the title data;
[0099] The filtering module 320 is used to obtain key sentence data from the content data of the news data that has a similarity greater than a preset similarity threshold with the synonym data;
[0100] The model processing module 330 is used to concatenate multiple key sentence data and input the concatenated sentence data into the BERT model to determine the sentiment type of the news data. The BERT model is trained based on news data samples and their corresponding sentiment type labels.
[0101] The BERT sentiment analysis device based on key sentences provided in this invention performs data augmentation on the headline data of news data to obtain multiple synonyms for the headline data. Sentences with high relevance to these synonyms are extracted from the content data of the news data and used as input for subsequent BERT models. This enables the prediction of the sentiment tendency of news data by obtaining more information reflecting the news theme from the content data, thereby improving the accuracy of sentiment tendency prediction for news data.
[0102] In one embodiment, the filtering module 320 is specifically used for:
[0103] From the content data of the news data, key sentence data with a similarity greater than a preset similarity threshold to the synonym data is obtained, including:
[0104] The sentence data in the content data is traversed, and the similarity between each synonym and the sentence data is determined. Sentence data with a similarity greater than a preset similarity threshold are taken as key sentence data of the content data.
[0105] In one embodiment, the filtering module 320 is further configured to:
[0106] Determining the similarity between each synonym and the sentence data includes:
[0107] Based on the number of shared words in synonym data and sentence data, the total number of words in the synonym data, and the total number of words in the sentence data, a similarity calculation formula for synonym data and sentence data is determined.
[0108] Based on the similarity calculation formula, the similarity between each synonym data and the sentence data is determined.
[0109] In one embodiment, the filtering module 320 is further configured to:
[0110] The formula for calculating similarity is:
[0111]
[0112] Where W represents the similarity between synonym data and sentence data, X represents the number of shared words in synonym data and sentence data, Y represents the total number of words in synonym data, and Z represents the total number of words in sentence data.
[0113] In one embodiment, the augmentation processing module 310 is specifically used for:
[0114] Data augmentation processing includes at least one of the following: synonym replacement processing, random insertion processing, random swapping processing, and random deletion processing.
[0115] In one embodiment, the model processing module 330 is specifically used for:
[0116] Before inputting the concatenated sentence data into the BERT model, the following steps are also included:
[0117] If the length of the concatenated sentence data is greater than the preset length, the concatenated sentence data is truncated to determine that the length of the concatenated sentence data is less than or equal to the preset length.
[0118] Figure 4 An example is a schematic diagram of the physical structure of an electronic device, such as... Figure 4 As shown, the electronic device may include: a processor 410, a communications interface 420, a memory 430, and a communication bus 440, wherein the processor 410, the communications interface 420, and the memory 430 communicate with each other via the communication bus 440. The processor 410 can call logical instructions in the memory 430 to execute a key sentence-based BERT sentiment analysis method, which includes:
[0119] Data augmentation processing is performed on the headline data of the news data to obtain multiple synonyms of the headline data;
[0120] From the content data of the news data, obtain key sentence data whose similarity to the synonym data is greater than a preset similarity threshold;
[0121] The obtained key sentence data is concatenated and then input into the BERT model to determine the sentiment type of the news data. The BERT model is trained based on the news data samples and their corresponding sentiment type labels.
[0122] Furthermore, the logical instructions in the aforementioned memory 430 can be implemented as software functional units and, when sold or used as independent products, can be stored in a computer-readable storage medium. Based on this understanding, the technical solution of the present invention, essentially, or the part that contributes to the prior art, or a part of the technical solution, can be embodied in the form of a software product. This computer software product is stored in a storage medium and includes several instructions to cause a computer device (which may be a personal computer, server, or network device, etc.) to execute all or part of the steps of the methods described in the various embodiments of the present invention. The aforementioned storage medium includes various media capable of storing program code, such as USB flash drives, portable hard drives, read-only memory (ROM), random access memory (RAM), magnetic disks, or optical disks.
[0123] On the other hand, the present invention also provides a computer program product, the computer program product comprising a computer program stored on a non-transitory computer-readable storage medium, the computer program comprising program instructions, wherein when the program instructions are executed by a computer, the computer is able to execute the key sentence-based BERT sentiment analysis method provided by the above methods, the method comprising:
[0124] Data augmentation processing is performed on the headline data of the news data to obtain multiple synonyms of the headline data;
[0125] From the content data of the news data, obtain key sentence data whose similarity to the synonym data is greater than a preset similarity threshold;
[0126] The obtained key sentence data is concatenated and then input into the BERT model to determine the sentiment type of the news data. The BERT model is trained based on the news data samples and their corresponding sentiment type labels.
[0127] In another aspect, the present invention also provides a non-transitory computer-readable storage medium having a computer program stored thereon, which, when executed by a processor, is implemented to perform the aforementioned key-sentence-based BERT sentiment analysis methods, the method comprising:
[0128] Data augmentation processing is performed on the headline data of the news data to obtain multiple synonyms of the headline data;
[0129] From the content data of the news data, obtain key sentence data whose similarity to the synonym data is greater than a preset similarity threshold;
[0130] The obtained key sentence data is concatenated and then input into the BERT model to determine the sentiment type of the news data. The BERT model is trained based on the news data samples and their corresponding sentiment type labels.
[0131] The device embodiments described above are merely illustrative. The units described as separate components may or may not be physically separate. The components shown as units may or may not be physical units; that is, they may be located in one place or distributed across multiple network units. Some or all of the modules can be selected to achieve the purpose of this embodiment according to actual needs. Those skilled in the art can understand and implement this without any creative effort.
[0132] Through the above description of the embodiments, those skilled in the art can clearly understand that each embodiment can be implemented by means of software plus necessary general-purpose hardware platforms, and of course, it can also be implemented by hardware. Based on this understanding, the above technical solutions, in essence or the part that contributes to the prior art, can be embodied in the form of a software product. This computer software product can be stored in a computer-readable storage medium, such as ROM / RAM, magnetic disk, optical disk, etc., and includes several instructions to cause a computer device (which may be a personal computer, server, or network device, etc.) to execute the methods described in the various embodiments or some parts of the embodiments.
[0133] Finally, it should be noted that the above embodiments are only used to illustrate the technical solutions of the present invention, and not to limit them; although the present invention has been described in detail with reference to the foregoing embodiments, those skilled in the art should understand that modifications can still be made to the technical solutions described in the foregoing embodiments, or equivalent substitutions can be made to some of the technical features; and these modifications or substitutions do not cause the essence of the corresponding technical solutions to deviate from the spirit and scope of the technical solutions of the embodiments of the present invention.
Claims
1. A BERT sentiment analysis method based on key sentences, characterized in that, The method includes: The headline data of the news data is subjected to data augmentation processing to obtain multiple synonym data of the headline data; the data augmentation processing includes synonym replacement processing; the synonym replacement processing involves randomly extracting multiple words from the headline data, and then randomly extracting synonyms of the multiple words from a thesaurus and replacing them; the randomly extracted words are verbs, nouns or sentiment words; Traverse the sentence data in the content data, determine the similarity between each synonym and the sentence data, and take the sentence data with the similarity greater than a preset similarity threshold as the key sentence data of the content data; The obtained key sentence data are concatenated and the concatenated sentence data is input into the BERT model to determine the sentiment type of the news data. The BERT model is trained based on the news data samples and their corresponding sentiment type labels. Determining the similarity between each synonym data and the sentence data includes: Based on the number of shared words in synonym data and sentence data, the total number of words in the synonym data, and the total number of words in the sentence data, a similarity calculation formula for synonym data and sentence data is determined. Based on the similarity calculation formula, the similarity between each synonym data and the sentence data is determined; Before inputting the concatenated sentence data into the BERT model, the process also includes: If the length of the concatenated sentence data is greater than the preset length, the concatenated sentence data is truncated to determine that the length of the concatenated sentence data is less than or equal to the preset length. The determination of the similarity between each synonymous data and the sentence data based on the similarity calculation formula includes: The similarity is determined based on the number of shared words in the synonym data and sentence data, the total number of words in the synonym data, and the total number of words in the sentence data.
2. The BERT sentiment analysis method based on key sentences according to claim 1, characterized in that, The similarity calculation formula is as follows: in, The similarity between synonym data and sentence data. This represents the number of shared words between synonym data and sentence data. This represents the total number of words in the synonym data. This represents the total number of words in the sentence data.
3. The BERT sentiment analysis method based on key sentences according to claim 1, characterized in that, The data augmentation process includes at least one of the following: synonym replacement, random insertion, random swapping, and random deletion.
4. A BERT sentiment analysis device based on key sentences, characterized in that, include: An augmentation processing module is used to perform data augmentation processing on the title data of news data to obtain multiple synonym data of the title data; the data augmentation processing includes synonym replacement processing; the synonym replacement processing involves randomly extracting multiple words from the title data, and then randomly extracting synonyms of the multiple words from a thesaurus and replacing them; the randomly extracted words are verbs, nouns, or sentiment words; The filtering module is used to traverse the sentence data in the content data, determine the similarity between each synonym and the sentence data, and take the sentence data with the similarity greater than a preset similarity threshold as the key sentence data of the content data; The model processing module is used to concatenate multiple key sentence data and input the concatenated sentence data into the BERT model to determine the sentiment type of the news data. The BERT model is trained based on news data samples and their corresponding sentiment type labels. Determining the similarity between each synonym data and the sentence data includes: Based on the number of shared words in synonym data and sentence data, the total number of words in the synonym data, and the total number of words in the sentence data, a similarity calculation formula for synonym data and sentence data is determined. Based on the similarity calculation formula, the similarity between each synonym data and the sentence data is determined; Before inputting the concatenated sentence data into the BERT model, the process also includes: If the length of the concatenated sentence data is greater than the preset length, the concatenated sentence data is truncated to determine that the length of the concatenated sentence data is less than or equal to the preset length. The determination of the similarity between each synonymous data and the sentence data based on the similarity calculation formula includes: The similarity is determined based on the number of shared words in the synonym data and sentence data, the total number of words in the synonym data, and the total number of words in the sentence data.
5. An electronic device comprising a memory, a processor, and a computer program stored in the memory and executable on the processor, characterized in that, When the processor executes the computer program, it implements the BERT sentiment analysis method based on key sentences as described in any one of claims 1 to 3.
6. A non-transitory computer-readable storage medium having a computer program stored thereon, characterized in that, When the computer program is executed by a processor, it implements the key sentence-based Bert sentiment analysis method as described in any one of claims 1 to 3.
7. A computer program product, comprising a computer program, characterized in that, When the computer program is executed by a processor, it implements the key sentence-based Bert sentiment analysis method as described in any one of claims 1 to 3.
Citation Information
Patent Citations
Automatic generation method and device for internet news
CN105787095A
Text retrieval matching method and system
CN114428850A
Filtering and sentiment analysis method based on news comments
CN115062229A
