Method and device for analyzing sentiment of entity pair relationship, and storage medium

By acquiring entity pair types, relationship types, distances, and sentiments from text, and using a neural network model to analyze entity pair relationship sentiments, this solves the misjudgment problem caused by ignoring these factors in existing technologies, achieving higher accuracy and efficiency.

CN115221279BActive Publication Date: 2026-04-24BEIJING XUEZHITU NETWORK TECH
View PDF 2 Cites 0 Cited by

Patent Information

Authority / Receiving Office
CN · China
Patent Type
Patents(China)
Current Assignee / Owner
BEIJING XUEZHITU NETWORK TECH
Filing Date
2022-07-01
Publication Date
2026-04-24

AI Technical Summary

Technical Problem

Existing technologies, when obtaining the sentiment of relationships between entities in text, ignore the type of entity pair, relationship type, distance, and sentiment polarity, leading to misjudgment.

Method used

By acquiring entity pairs from the text to be analyzed, their type, relationship type, distance, and sentiment are obtained, and a pre-set neural network model is used for analysis, taking into account the contextual information of the entity pairs to improve the accuracy of relationship sentiment.

Benefits of technology

By considering the type of entity pair, relation type, distance, and sentiment polarity, the accuracy and efficiency of entity pair relation sentiment are improved.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN115221279B_ABST
    Figure CN115221279B_ABST
Patent Text Reader

Abstract

The application relates to the technical field of deep learning, and discloses a method for analyzing relationship sentiment of an entity pair, which comprises the following steps: obtaining a text to be analyzed; obtaining an entity pair to be analyzed in the text to be analyzed; obtaining an entity pair type, an entity pair relationship type, an entity pair distance and an entity pair sentiment of the entity pair to be analyzed; and obtaining relationship sentiment of the entity pair to be analyzed according to the text to be analyzed, the entity pair to be analyzed, the entity pair type, the entity pair relationship type, the entity pair distance and the entity pair sentiment. In this way, the entity pair type, the entity pair relationship type, the entity pair distance and the entity pair sentiment can reflect the entity relationship between entities in the entity pair, thereby improving the accuracy of obtaining the relationship sentiment of the entity pair. The application further discloses a device for analyzing relationship sentiment of an entity pair and a storage medium.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] This application relates to the field of deep learning technology, such as a method, apparatus, and storage medium for analyzing entity-to-entity relationship sentiment. Background Technology

[0002] Currently, with the continuous development of natural language processing and artificial intelligence technologies, multimedia information such as voice, text, images, and video is being effectively utilized, providing users with a comfortable sensory experience. Among these multimedia information, text information is particularly important. Whether it's converting speech to text or providing textual descriptions of images or videos, processing textual data can provide a higher level of cognitive intelligence. Sentiment analysis of entities in text is an important direction for intelligent understanding of textual data. However, when there are multiple entities in the text, it is not only necessary to obtain sentiment analysis results at the entity level, but also to pay attention to the sentiment between entities in order to understand customer thoughts and uncover customer emotional tendencies towards products.

[0003] In the process of implementing the embodiments of this disclosure, it has been found that at least the following problems exist in the related technology: the prior art uses the method of obtaining entity emotion to obtain the emotion between entities, but ignores the influence of entity pair type, entity pair relationship type, entity pair distance and entity pair emotion on the emotion polarity of entity pair, which can easily lead to misjudgment of entity pair relationship emotion. Summary of the Invention

[0004] To provide a basic understanding of some aspects of the disclosed embodiments, a brief summary is given below. This summary is not intended as a general commentary, nor is it intended to identify key / important components or describe the scope of protection of these embodiments, but rather as a prelude to the detailed description that follows.

[0005] This disclosure provides a method, apparatus, and storage medium for analyzing the relational sentiment of entity pairs, thereby improving the accuracy of obtaining relational sentiment of entity pairs.

[0006] In some embodiments, the method for analyzing entity pair relationship sentiment includes: acquiring text to be analyzed; acquiring entity pairs to be analyzed from the text to be analyzed; acquiring the entity pair type, entity pair relationship type, entity pair distance, and entity pair sentiment of the entity pairs to be analyzed; and acquiring the relationship sentiment of the entity pairs to be analyzed based on the text to be analyzed, the entity pairs to be analyzed, the entity pair type, the entity pair relationship type, the entity pair distance, and the entity pair sentiment.

[0007] In some embodiments, the apparatus for analyzing entity pair relationship sentiment includes: a text acquisition module configured to acquire text to be analyzed; an entity pair acquisition module configured to acquire entity pairs to be analyzed from the text to be analyzed; an entity pair relationship acquisition module configured to acquire the entity pair type, entity pair relationship type, entity pair distance, and entity pair sentiment of the entity pairs to be analyzed; and an acquisition module configured to acquire the relationship sentiment of the entity pairs to be analyzed based on the text to be analyzed, the entity pairs to be analyzed, the entity pair type, the entity pair relationship type, the entity pair distance, and the entity pair sentiment.

[0008] In some embodiments, the storage medium stores program instructions that, when executed, perform the methods described above for analyzing entity-to-relationship sentiment.

[0009] The method, apparatus, and storage medium for analyzing entity pair relationship sentiment provided in this disclosure can achieve the following technical effects: By obtaining entity pairs to be analyzed from the text to be analyzed, and obtaining the entity pair type, entity pair relationship type, entity pair distance, and entity pair sentiment of the entity pairs to be analyzed, the relationship sentiment of the entity pairs is obtained based on the text to be analyzed, the entity pairs to be analyzed, the entity pair type, entity pair relationship type, entity pair distance, and entity pair sentiment. In this way, the entity relationship between entities within an entity pair is reflected through the entity pair type, entity pair relationship type, entity pair distance, and entity pair sentiment, and the influence of the entity pair type, entity pair relationship type, entity pair distance, and entity pair sentiment on the sentiment polarity of the entity pairs is considered, thereby improving the accuracy of obtaining the relationship sentiment of entity pairs.

[0010] The above general description and the description below are exemplary and illustrative only and are not intended to limit this application. Attached Figure Description

[0011] One or more embodiments are illustrated by way of example with reference to the accompanying drawings. These illustrations and drawings do not constitute a limitation on the embodiments. Elements having the same reference numerals in the drawings are shown as similar elements. The drawings are not to be scaled. And wherein:

[0012] Figure 1 This is a schematic diagram of a method for analyzing entity sentiment in relationships provided in an embodiment of this disclosure;

[0013] Figure 2 This is a schematic diagram of a method for training an entity-pair sentiment analysis model provided in an embodiment of this disclosure;

[0014] Figure 3 This is a schematic diagram illustrating the application of an entity-to-sentiment analysis model provided in an embodiment of this disclosure;

[0015] Figure 4 This is a schematic diagram of an apparatus for analyzing entity sentiment in relational relationships, provided in an embodiment of this disclosure;

[0016] Figure 5 This is a schematic diagram of another apparatus for analyzing entity sentiment toward relationships provided in an embodiment of this disclosure;

[0017] Figure 6 This is a schematic diagram of another apparatus for analyzing entity-to-relationship sentiment provided in an embodiment of this disclosure. Detailed Implementation

[0018] To provide a more detailed understanding of the features and technical content of the embodiments of this disclosure, the implementation of the embodiments of this disclosure will be described in detail below with reference to the accompanying drawings. The accompanying drawings are for illustrative purposes only and are not intended to limit the embodiments of this disclosure. In the following technical description, for ease of explanation, several details are used to provide a full understanding of the disclosed embodiments. However, one or more embodiments may still be implemented without these details. In other cases, well-known structures and devices may be simplified in their depiction to simplify the drawings.

[0019] The terms "first," "second," etc., used in the specification, claims, and accompanying drawings of this disclosure are used to distinguish similar objects and are not necessarily used to describe a specific order or sequence. It should be understood that such data can be interchanged where appropriate for the embodiments of this disclosure described herein. Furthermore, the terms "comprising" and "having," and any variations thereof, are intended to cover non-exclusive inclusion.

[0020] Unless otherwise stated, the term "multiple" means two or more.

[0021] In this embodiment of the disclosure, the character " / " indicates that the objects before and after it are in an "or" relationship. For example, A / B means: A or B.

[0022] The term "and / or" describes an association between objects, indicating that three relationships can exist. For example, A and / or B means: A or B, or A and B.

[0023] The term "correspondence" can refer to an association or binding relationship. The correspondence between A and B means that there is an association or binding relationship between A and B.

[0024] The method for analyzing entity pair relationship sentiment provided in this disclosure is applied to an electronic device. The electronic device acquires text to be analyzed and extracts entity pairs to be analyzed from the text. It then acquires the entity pair type, entity pair relationship type, entity pair distance, and entity pair sentiment of the entity pairs to be analyzed, and obtains the relationship sentiment of the entity pairs based on the text to be analyzed, the entity pairs to be analyzed, the entity pair type, the entity pair relationship type, the entity pair distance, and the entity pair sentiment. The entity pair type, entity pair relationship type, entity pair distance, and entity pair sentiment reflect the entity relationships between entities within an entity pair, and consider the influence of the entity pair type, entity pair relationship type, entity pair distance, and entity pair sentiment on the sentiment polarity of the entity pairs, thereby improving the accuracy of obtaining the relationship sentiment of the entity pairs to be analyzed.

[0025] Combination Figure 1 As shown, this disclosure provides a method for analyzing entity sentiment regarding relationships, including:

[0026] Step S101: The electronic device acquires the text to be analyzed. The text to be analyzed is preceded by a sentence classification identifier, which is "[CLS]".

[0027] Step S102: The electronic device obtains the entity pairs to be analyzed from the text to be analyzed.

[0028] Step S103: The electronic device acquires the entity pair type, entity pair relationship type, entity pair distance, and entity pair sentiment of the entity pair to be analyzed.

[0029] In step S104, the electronic device obtains the relational sentiment of the entity pair based on the text to be analyzed, the entity pair to be analyzed, the entity pair type, the entity pair relation type, the entity pair distance, and the entity pair sentiment.

[0030] The method for analyzing entity pair sentiment provided in this disclosure involves obtaining entity pairs from the text to be analyzed, and acquiring their entity pair type, entity pair relationship type, entity pair distance, and entity pair sentiment. Then, the sentiment of the entity pairs is obtained based on the text to be analyzed, the entity pairs, their entity pair types, entity pair relationship types, entity pair distances, and entity pair sentiments. This approach reflects the entity relationships within an entity pair through the entity pair type, entity pair relationship type, entity pair distance, and entity pair sentiments, and considers the influence of these factors on the sentiment polarity of the entity pairs, thereby improving the accuracy of obtaining the sentiment of entity pairs. Furthermore, the addition of whole-sentence classification identifiers before the text to be analyzed allows the entity pair sentiment analysis model to accurately locate the text, facilitating the acquisition of the sentiment of entity pairs based on the text, the entity pairs within the text, the entity pair types, entity pair relationship types, entity pair distances, and entity pair sentiments, further improving the accuracy of obtaining the sentiment of entity pairs.

[0031] Optionally, the electronic device obtains entity pairs to be analyzed from the text to be analyzed, including: the electronic device extracting multiple entities from the text to be analyzed; the electronic device combining the entities to obtain candidate entity pairs to be analyzed; and the electronic device filtering the candidate entity pairs to be analyzed according to preset filtering rules to obtain the entity pairs to be analyzed. In this way, by filtering the candidate entity pairs to be analyzed from the combinations of entities, unsatisfactory candidate entity pairs are eliminated, while qualified candidate entity pairs are retained. This improves both the accuracy and efficiency of obtaining the relational sentiment of entity pairs.

[0032] Furthermore, the electronic device extracts multiple entities from the text to be analyzed, including: the electronic device performs entity extraction on the text to be analyzed to obtain multiple entities in the text to be analyzed.

[0033] Furthermore, the electronic device combines the entities to obtain candidate entity pairs to be analyzed, including: the electronic device combining two adjacent entities to obtain candidate entity pairs to be analyzed; or, the electronic device combining any two entities to obtain candidate entity pairs to be analyzed.

[0034] Furthermore, the electronic device filters candidate entity pairs for analysis according to preset filtering rules to obtain entity pairs to be analyzed, including: the electronic device acquiring the entity attributes corresponding to each entity in the candidate entity pairs. If the entity attributes corresponding to each entity in a candidate entity pair are different, the electronic device determines that candidate entity pair as the entity pair to be analyzed.

[0035] Optionally, the electronic device acquires the entity pair type, entity pair relationship type, entity pair distance, and entity pair sentiment of the entity pair to be analyzed, including: the electronic device acquires the entity type of each entity in the entity pair to be analyzed; the electronic device acquires the entity pair type based on the entity type of each entity in the entity pair to be analyzed; the electronic device acquires the relationship type between each entity in the entity pair to be analyzed; the electronic device determines the relationship type between each entity in the entity pair to be analyzed as the entity pair relationship type; the electronic device acquires the distance between the entities in the entity pair to be analyzed in the text to be analyzed; the electronic device determines the distance between the entities in the entity pair to be analyzed in the text to be analyzed as the entity pair distance; and the electronic device acquires the entity sentiment of each entity in the entity pair to be analyzed. The entity pair relationship type of the entity pair to be analyzed includes subordinate relationships or contrast relationships, etc. The entity sentiment includes positive, negative, or neutral. In this way, by acquiring the entity pair type, entity pair relationship type, entity pair distance, and entity pair sentiment of the entity pair to be analyzed, the relationship between the entities in the entity pair to be analyzed can be more comprehensively reflected, thereby improving the accuracy of acquiring the relationship sentiment of the entity pair to be analyzed.

[0036] In some embodiments, the relationship category between entities is prone to misclassification. However, by analyzing the entity pair type, entity pair relationship type, entity pair distance, and entity pair sentiment, the relationship category characteristics, entity pair type characteristics, entity pair distance characteristics, and entity pair sentiment characteristics of the entity pair to be analyzed can be accurately understood, thereby improving the accuracy of judging the sentiment of the entity pair relationship. In addition, since the distance between entities whose relationship sentiment needs to be determined is often less than or equal to a preset distance, using entity pair distance as input can improve the accuracy of obtaining the relationship sentiment of the entity pair to be analyzed. At the same time, to compensate for the bias and deficiency in the use of sentiment information, entity pair sentiment can make full use of the sentiment information between entities, improving the accuracy of obtaining the relationship sentiment of the entity pair to be analyzed.

[0037] In some embodiments, the text S1 to be analyzed is represented by 15 characters, with each character represented by C. That is, S1 = [C1 ~ C2]. 15The subscript 'C' indicates the position of the character in the text S1 to be analyzed. The text S1 contains a pair of entities A1 to be analyzed, which includes a first entity Entity1 and a second entity Entity2, where Entity1 = [C3~C5] and Entity2 = [C8~C9]. The first entity is located between the 3rd and 5th elements in the text S1. Therefore, the starting position of the first entity in the text S1 is 3, and the ending position is 5. The second entity is located between the 8th and 9th elements in the text S1. Therefore, the starting position of the second entity in the text S1 is 8, and the ending position is 9. The entity type of the first entity Entity1 is Type1, and the entity type of the second entity Entity2 is Type2. Therefore, the entity pair type TypePair of the entity pair A1 is Type1&Type2. If the relationship type between the first entity Entity1 and the second entity Entity2 is RelType, then the electronic device will determine RelType as the entity pair relationship type of the entity pair A1 to be analyzed. The electronic device will subtract the ending position 5 of the first entity from the starting position 8 of the second entity to obtain the distance Dist, 3 between the first entity Entity1 and the second entity Entity2 in the text S1 to be analyzed. This distance Dist, 3 will be determined as the entity pair distance of the entity pair A1 to be analyzed. The sentiment of the first entity Entity1 will be Sent1, and the sentiment of the second entity Entity2 will be Sent2. Therefore, the entity pair sentiment SentPair of the entity pair A1 to be analyzed will be either Sent1&Sent2 or Sent2&Sent1. The electronic device will obtain the relationship sentiment of the entity pair to be analyzed based on the text S1 to be analyzed, the entity pair A1 to be analyzed, the entity pair type Type1&Type2, the entity pair relationship type RelType, the entity pair distance 3, and the entity pair sentiment Sent1&Sent2. Among them, the entities represented by Sent1 & Sent2 and Sent2 & Sent1 have the same polarity of emotion.

[0038] Optionally, the relational sentiment of the entity pairs can be obtained based on the text to be analyzed, the entity pairs to be analyzed, the entity pair type, the entity pair relationship type, the entity pair distance, and the entity pair sentiment. This includes: inputting the text to be analyzed, the entity pairs to be analyzed, the entity pair type, the entity pair relationship type, the entity pair distance, and the entity pair sentiment into a preset entity pair sentiment analysis model to obtain the relational sentiment of the entity pairs to be analyzed.

[0039] Furthermore, the electronic device inputs the text to be analyzed, the entity pairs to be analyzed, the entity pair types, the entity pair relationship types, the entity pair distances, and the entity pair sentiments into a pre-defined entity pair sentiment analysis model to obtain the relational sentiment of the entity pairs to be analyzed. This includes: the electronic device inputs the text to be analyzed, the entity pairs to be analyzed, the entity pair types, the entity pair relationship types, the entity pair distances, and the entity pair sentiments into the pre-defined entity pair sentiment analysis model to obtain the predicted sentiment probabilities corresponding to each sentiment tag of the entity pairs to be analyzed. The electronic device determines the sentiment tag corresponding to the maximum predicted sentiment probability as the relational sentiment of the entity pairs to be analyzed. Here, sentiment tags are used to represent sentiment polarity. Sentiment tags include positive, negative, and neutral.

[0040] Optionally, the preset entity pair sentiment analysis model is obtained through the following method: The electronic device acquires the sample text to be analyzed. The sample text is accompanied by whole-sentence classification information. Specifically, the whole-sentence classification information is added before the sample text to be analyzed. The electronic device acquires the sample entity pairs to be analyzed from the sample text. The electronic device acquires the sample entity pair type, sample entity pair relation type, sample entity pair distance, and sample entity pair sentiment. The sample text, sample entity pairs, sample entity pair type, sample entity pair relation type, sample entity pair distance, and sample entity pair sentiment are used as training samples. The sample sentiment labels of the sample entity pairs are acquired; the electronic device inputs the training samples with sample sentiment labels into the preset neural network model for training to obtain the entity pair sentiment analysis model. The preset neural network model includes a preset BERT (Bidirectional Encoder Representation from Transformer) model and a preset embedding vector network. The BERT model is a pre-trained language representation model. In this way, by using the sample entity pair type, sample entity pair relationship type, sample entity pair distance and sample entity pair sentiment, which can reflect the entity relationship between the entities in the sample entity pair, as the training sample pair preset neural network model, the trained entity pair sentiment analysis model takes into account the entity relationship between the sample entities in the sample entity pair, thereby improving the accuracy of obtaining the relationship sentiment of the entity pair using the entity pair sentiment analysis model.

[0041] Furthermore, before training the preset neural network model, the parameters in the preset neural network model are randomly initialized.

[0042] Furthermore, the electronic device obtains sample entity pairs to be analyzed from the sample text, including: the electronic device extracts multiple sample entities from the sample text; the electronic device combines the sample entities to obtain candidate sample entity pairs; the electronic device filters the candidate sample entity pairs according to preset filtering rules to obtain sample entity pairs to be analyzed.

[0043] Furthermore, the electronic device extracts multiple sample entities from the sample text, including: the electronic device extracts entities from the sample text to obtain multiple sample entities from the sample text.

[0044] Furthermore, the electronic device combines the sample entities to obtain candidate entity pairs, including: the electronic device combining two adjacent sample entities to obtain candidate sample entity pairs; or, the electronic device combining any two sample entities to obtain candidate sample entity pairs.

[0045] Furthermore, the electronic device filters candidate sample entity pairs according to preset filtering rules to obtain sample entity pairs to be analyzed, including: the electronic device acquiring the entity attributes corresponding to each sample entity in the candidate sample entity pair. If the entity attributes corresponding to each sample entity in the candidate sample entity pair are different, the electronic device determines that candidate sample entity pair as the sample entity pair to be analyzed.

[0046] Furthermore, the electronic device acquires the sample entity pair type, sample entity pair relationship type, sample entity pair distance, and sample entity pair sentiment of the sample entity pair, including: The electronic device acquires the sample entity type of each sample entity in the sample entity pair. The electronic device acquires the sample entity pair type based on the sample entity type of each sample entity in the sample entity pair. The electronic device acquires the sample relationship type between each sample entity in the sample entity pair. The electronic device determines the sample relationship type between each sample entity in the sample entity pair as the sample entity pair relationship type. The electronic device acquires the distance between the sample entities in the sample entity pair in the sample text. The electronic device determines the distance between the sample entities in the sample entity pair in the sample text as the sample entity pair distance. The electronic device acquires the sample entity sentiment of each sample entity in the sample entity pair. The electronic device acquires the sample entity pair sentiment based on the sample entity sentiment of each entity in the sample entity pair.

[0047] Optionally, the electronic device trains a pre-defined neural network model by inputting training samples with sample sentiment labels. This includes: during training, the electronic device inputs sample text and sample entity pairs into a pre-defined BERT model to obtain the entity hidden layer output vectors and label vectors corresponding to the whole sentence classification information for each sample entity in the sample entity pair. The electronic device inputs the sample entity pair type, sample entity pair relation type, sample entity pair distance, and sample entity pair sentiment into a pre-defined embedding vector network to obtain the sample entity pair type embedding vector, sample entity pair relation type embedding vector, sample entity pair distance embedding vector, and sample entity pair sentiment embedding vector. The electronic device obtains the whole sentence classification vector corresponding to the sample text based on the label vectors. The electronic device obtains the entity vector corresponding to each sample entity based on the hidden layer output vectors of each entity. The electronic device obtains the entity pair sentiment analysis model based on the whole sentence classification vector, the entity vector corresponding to each sample entity, the sample entity pair type embedding vector, the sample entity pair relation type embedding vector, the sample entity pair distance embedding vector, the sample entity pair sentiment embedding vector, and the sample sentiment label. In this model, the entity pair type embedding vector, entity pair relation type embedding vector, entity pair distance embedding vector, and entity pair sentiment embedding vector are all entity pair relation embedding vectors used to represent the relationship between entities in the entity pair. Thus, the entire sentence classification vector and the entity vector corresponding to each sample entity are obtained through the entity hidden layer output vector of the neural network model. Based on the entire sentence classification vector, the entity vectors corresponding to each sample entity, the entity pair relation embedding vector, and the sample sentiment label, an entity pair sentiment analysis model is obtained. This model can obtain the relational sentiment of entity pairs based on the entire sentence classification vector, the entity vectors corresponding to each sample entity, and the entity relation embedding matrix, thereby improving the accuracy of obtaining the relational sentiment of entity pairs using this model. Furthermore, the sample sentiment label includes positive, negative, or neutral. The sample sentiment label is used to represent the true relational sentiment of the sample entity pairs.

[0048] Furthermore, the electronic device uses a pre-defined embedding vector network for sample entity pair types, sample entity pair relation types, sample entity pair distances, and sample entity pair sentiment inputs to obtain sample entity pair type embedding vectors, sample entity pair relation type embedding vectors, sample entity pair distance embedding vectors, and sample entity pair sentiment embedding vectors. This includes: the electronic device uses the pre-defined embedding vector network for sample entity pair types, sample entity pair relation types, sample entity pair distances, and sample entity pair sentiment inputs to obtain sample entity pair type embedding matrices, sample entity pair relation type embedding matrices, sample entity pair distance embedding matrices, and sample entity pair sentiment embedding matrices. The electronic device extracts the sample entity pair type embedding vector corresponding to the sample entity pair type from the sample entity pair type embedding matrix. The electronic device extracts the sample entity pair relation type embedding vector corresponding to the sample entity pair relation type from the sample entity pair relation type embedding matrix. The electronic device extracts the sample entity pair distance embedding vector corresponding to the sample entity pair distance from the sample entity pair distance embedding matrix. The electronic device extracts the sample entity pair sentiment embedding vector corresponding to the sample entity pair sentiment from the sample entity pair sentiment embedding matrix. The embedding vector network includes initial sample entity pair type embedding matrices, initial sample entity pair relation type embedding matrices, initial sample entity pair distance embedding matrices, and initial sample entity pair sentiment embedding matrices. Before training, the values ​​in these matrices are randomly initialized. In some embodiments, the dimension of the sample entity pair type embedding matrix is ​​[number of entity pair types × dimension of sample entity pair type embedding vectors]. Each column vector in the sample entity pair type embedding matrix represents an entity pair type. The dimension of the sample entity pair relation type embedding matrix is ​​[number of entity pair relation types × dimension of sample entity pair relation embedding matrix]. Each column vector in the sample entity pair relation type embedding matrix represents an entity pair relation. The dimension of the sample entity pair distance embedding matrix is ​​[preset longest entity distance × dimension of sample entity pair distance embedding vectors]. Each column vector in the sample entity pair distance embedding matrix represents a distance. The dimension of the sample entity pair sentiment embedding matrix is ​​[number of entity pair sentiments × dimension of sample entity pair sentiment embedding vectors]. In this matrix, each column vector of the sample entity pair emotion embedding matrix represents an entity pair emotion.

[0049] Furthermore, the electronic device inputs the sample text and entity pairs into a pre-defined BERT model to obtain the entity hidden layer output vectors corresponding to each sample entity in the sample entity pair and the label vectors corresponding to the whole sentence classification information. This includes: the electronic device inputs the sample text and sample entity pairs into the pre-defined BERT model to obtain the hidden layer output matrix corresponding to the sample text. The electronic device extracts the entity hidden layer output vectors corresponding to each sample entity in the sample entity pair and the label vectors corresponding to the whole sentence classification information from the hidden layer output matrix corresponding to the sample text. The hidden layer output matrix corresponding to the sample text is the matrix output by the last hidden layer of the BERT model.

[0050] Furthermore, the electronic device extracts the entity hidden layer output vector using the following method: The electronic device obtains the sample entity position of each entity in the sample text within the sample entity pair. The electronic device extracts the vector corresponding to the sample entity position from the hidden layer output matrix, which serves as the entity hidden layer output vector for each entity.

[0051] In some embodiments, the sample text S2 to be analyzed is represented by 15 characters, with each character represented by C′. That is, S2 = [C′1~C′1]. 15 The subscript of C′ represents the position of the character in text S2. Sample text S2 contains a pair of sample entity pairs A2, which includes a first sample entity Entity1′ and a second sample entity Entity2′, where Entity1′ = [C3′~C′5] and Entity2′ = [C′8~C′9]. The first sample entity is located at position 3 to 5 in text S2. The second sample entity is located at position 8 to 9 in text S2. The electronic device acquires the sample entity pair type, sample entity pair relationship type, sample entity pair distance, and sample entity pair sentiment. The sample text, sample entity pairs, sample entity pair type, sample entity pair relationship type, sample entity pair distance, and sample entity pair sentiment are used as training samples, and the sentiment labels of the sample entity pairs are acquired. Then, the training samples with sentiment labels are input into a pre-defined neural network model for training to obtain an entity pair sentiment analysis model. During training, the electronic device inputs the sample text and sample entity pairs into a pre-defined BERT model, and the hidden layer output matrix H corresponding to the sample text. Where H = [h1, h2, ... h i ,…,h 15 ]. h i Let h be the vector corresponding to the i-th character. The electronic device extracts the vector corresponding to the position of the sample entity from the hidden layer output matrix and uses it as the entity hidden layer output vector for each entity. Then, the entity hidden layer output vectors corresponding to the first sample entity Entity1′ are h3, h4 and h5, and the entity hidden layer output vectors corresponding to the second sample entity Entity2′ are h8 and h9.

[0052] Furthermore, the electronic device obtains the whole sentence classification vector based on the identifier vector, including: the electronic device inputs the hidden layer output vector of each entity into a preset first feedforward neural network, and uses a preset fourth algorithm to obtain the whole sentence classification vector.

[0053] Furthermore, the electronic device obtains the entire sentence classification vector using a pre-defined fourth algorithm, including: the electronic device calculates H... cls =W cls [tanh(h cls )]+b cls This yields the entire sentence classification vector. Here, tanh() is the hyperbolic tangent function. H cls This is the classification vector for the entire sentence. cls For identification vectors. W cls Let be the first parameter matrix in the first feedforward neural network. Furthermore, the dimension of the first parameter matrix is ​​d×d, where d is a preset vector dimension. cls Let be the first bias vector in the first feedforward neural network. Furthermore, the dimension of the first bias vector is d×1.

[0054] Furthermore, the electronic device obtains the entity vector corresponding to each sample entity based on the entity hidden layer output vector corresponding to each sample entity in the sample entity pair, including: the electronic device inputs the entity hidden layer output vector of each entity into a preset first feedforward neural network, and uses a preset fifth algorithm to obtain the entity vector corresponding to each sample entity.

[0055] Furthermore, the electronic device uses a pre-defined fifth algorithm to obtain the entity vector corresponding to each sample entity, including: the electronic device calculates... Obtain the entity vector corresponding to each sample entity. Where H... entitya Let h be the entity vector corresponding to the a-th sample entity. Further, a is a positive integer. t Let i be the vector corresponding to the t-th character in the hidden layer output matrix. a Let j be the starting position of the a-th sample entity in the sample text. a Let W be the endpoint position of the a-th sample entity in the sample text. entity Let be the second parameter matrix in the first feedforward neural network. Furthermore, the dimension of the second parameter matrix is ​​d×d. entity Let be the second bias vector in the first feedforward neural network. Furthermore, the dimension of the second bias vector is d×1.

[0056] In some embodiments, the sample text S2 to be analyzed is represented by 15 characters, with each character represented by C′. That is, S2 = [C′1~C′1]. 15The subscript of C′ represents the position of the character in text S2. Sample text S2 contains a pair of sample entities A2, which includes a first sample entity Entity1′ and a second sample entity Entity2′, where Entity1′ = [C′3~C′5] and Entity2′ = [C′8~C′9]. The first sample entity is located at the 3rd to 5th position in text S2. Therefore, the starting position of the first sample entity Entity1′ in the sample text is 3, and its ending position is 5. The second sample entity is located at the 8th to 9th position in text S2. The starting position of the second sample entity Entity2′ in the sample text is 8, and its ending position is 9. The electronic device, through calculation... Obtain the entity vector corresponding to the first sample entity. This is achieved through calculation. The entity vector corresponding to the second sample entity is obtained. Then, the electronic device obtains the entity pair sentiment analysis model based on the whole sentence classification vector, the entity vectors corresponding to each sample entity, the sample entity pair relation embedding vector, and the sample sentiment tag.

[0057] Optionally, the electronic device obtains an entity-to-sentiment analysis model based on the whole sentence classification vector, the entity vectors corresponding to each sample entity, the type embedding vectors of sample entity pairs, the relationship type embedding vectors of sample entity pairs, the distance embedding vectors of sample entity pairs, the sentiment embedding vectors of sample entity pairs, and the sentiment embedding vectors of sample entity pairs. This includes: the electronic device concatenating the whole sentence classification vector, the entity vectors corresponding to each sample entity, the type embedding vectors of sample entity pairs, the relationship type embedding vectors of sample entity pairs, the distance embedding vectors of sample entity pairs, and the sentiment embedding vectors of sample entity pairs to obtain a concatenated feature vector. The electronic device then fuses the whole sentence classification vector, the entity vectors corresponding to each sample entity, the type embedding vectors of sample entity pairs, the relationship type embedding vectors of sample entity pairs, the distance embedding vectors of sample entity pairs, and the sentiment embedding vectors of sample entity pairs in the concatenated feature vector using a preset first algorithm to obtain a feature vector; the electronic device then obtains the entity-to-sentiment analysis model based on the feature vector. Thus, the feature vector is obtained by fusing the whole sentence classification vector, the entity vectors corresponding to each sample entity, the type embedding vectors of sample entity pairs, the relationship type embedding vectors of sample entity pairs, the distance embedding vectors of sample entity pairs, and the sentiment embedding vectors of sample entity pairs in the concatenated feature vector using a preset first algorithm. The predicted sentiment of sample entity pairs is obtained based on feature vectors, which facilitates the acquisition of an entity pair sentiment analysis model based on the predicted sentiment and sample sentiment labels. This allows the obtained entity pair sentiment analysis model to comprehensively consider three dimensions—the whole sentence classification vector, the entity vector corresponding to the entity, and the entity relationship embedding vector—to obtain the relational sentiment of entity pairs, thereby improving the accuracy of obtaining relational sentiment of entity pairs using this entity pair sentiment analysis model.

[0058] Furthermore, the electronic device uses a preset first algorithm to fuse the whole sentence classification vector, the entity vector corresponding to each sample entity, the sample entity pair type embedding vector, the sample entity pair relation type embedding vector, the sample entity pair distance embedding vector, and the sample entity pair sentiment embedding vector in the concatenated feature vector to obtain the feature vector, including: H merge =W merge [concat(H z )]+b merge , thus obtaining the feature vector. Where H merge W is the eigenvector. merge Let H be the third parameter matrix of the second feedforward neural network. Further, the dimension of the third parameter matrix is ​​L×(3d+X). L is the number of relation sentiment categories; further, when the sentiment labels for relation sentiment include positive, negative, and neutral, L is 3. X is the sum of the dimensions of the entity pair type embedding vector, relation category embedding vector, entity distance embedding vector, and entity pair sentiment embedding vector. `concat()` is a concatenation function used to concatenate the parameters within its parentheses. z b is the concatenated vector obtained by concatenating the whole sentence classification vector, the entity vector corresponding to each sample entity, the type embedding vector of sample entity pairs, the relation type embedding vector of sample entity pairs, the distance embedding vector of sample entity pairs, and the sentiment embedding vector of sample entity pairs. merge Let be the third bias vector of the second feedforward neural network. Furthermore, the dimension of the third bias vector is d×1.

[0059] In some embodiments, the sample entity pairs in the sample text are a pair, that is, the sample entity includes a first sample entity and a second sample entity, then the electronic device calculates H. z =H cls H entity1′ H entity2′ Embed RelType Embed TypePair Embed Dist Embed sentPair This yields a concatenated vector containing the entire sentence classification vector, the first sample entity, the second sample entity, the sample entity pair type embedding vector, the sample entity pair relation type embedding vector, the sample entity pair distance embedding vector, and the sample entity pair sentiment embedding vector. Where H... entity1′ H is the entity vector corresponding to the first sample entity. entity2′ This is the entity vector corresponding to the second sample entity. RelType Embed a vector for the sample relationship category. TypePair Embed is the type embedding vector for sample entity pairs. Dist This is the embedding vector for the distance between sample entities. sentPairThis is the sentiment embedding vector for the sample entity pair. Then, by calculating H... merge =W merge [concat(H z )]+b merge The concatenated vectors are fused to obtain feature vectors. The electronic device uses a pre-defined second algorithm to probabilize the feature vectors, obtaining the predicted sentiment probability corresponding to each sentiment tag of the entity pair in the sample text. The electronic device determines the sentiment tag corresponding to the maximum predicted sentiment probability as the predicted sentiment of the sample entity pair in the sample text. The electronic device obtains the entity pair sentiment analysis model based on the predicted sentiment and the sample sentiment tag.

[0060] Optionally, the electronic device obtains an entity pair sentiment analysis model based on feature vectors, including: the electronic device probabilizing the feature vectors using a preset second algorithm to obtain the predicted sentiment probability corresponding to each sentiment tag of the sample entity pair in the sample text; the electronic device determining the sentiment tag corresponding to the maximum predicted sentiment probability as the predicted sentiment of the sample entity pair in the sample text; and the electronic device obtaining an entity pair sentiment analysis model based on the predicted sentiment and the sample sentiment tags. Here, the predicted sentiment of the sample entity pair in the sample text is the predicted relational sentiment of the sample entity pair. Further, the electronic device uses a preset second feedforward neural network and a preset first algorithm to fuse the whole sentence classification vector, the entity vector corresponding to each sample entity, the sample entity pair type embedding vector, the sample entity pair relation type embedding vector, the sample entity pair distance embedding vector, and the sample entity pair sentiment embedding vector in the concatenated feature vector to obtain feature vectors. Thus, by probabilizing the feature vectors, the predicted sentiment probability corresponding to each sentiment tag of the sample entity pair in the sample text can be obtained, so that the sentiment tag corresponding to the maximum predicted sentiment probability can be determined as the predicted sentiment of the sample entity pair in the sample text, thereby obtaining an entity pair sentiment analysis model based on the predicted sentiment and the sample sentiment tags. In this way, the obtained entity pair sentiment analysis model can make the predicted sentiment more closely match the sentiment labels of the samples, thereby improving the accuracy of the entity pair sentiment analysis model in analyzing the sentiment of entity pairs.

[0061] Furthermore, the electronic device uses a pre-defined second algorithm to probabilize the feature vector, obtaining the predicted sentiment probability corresponding to each sentiment tag of the sample entity pair in the sample text, including: the electronic device calculates p = soft max(H merge This function obtains the predicted sentiment probability corresponding to each sentiment label of the sample entity pair in the sample text. Here, p is the predicted sentiment probability corresponding to each sentiment label of the sample entity pair in the sample text. soft max() is an activation function used to transform the data within the parentheses to the (0,1) interval.

[0062] Optionally, the electronic device obtains an entity pair sentiment analysis model based on the predicted sentiment and sample sentiment labels, including: the electronic device obtaining the loss between the predicted sentiment and the sample sentiment labels; the electronic device obtaining candidate entity pair sentiment analysis models corresponding to the loss; and the electronic device adjusting the parameters in the candidate entity pair sentiment analysis models using a preset third algorithm based on the loss to obtain the entity pair sentiment analysis model. The preset third algorithm includes algorithms such as backpropagation gradient descent. In this way, by adjusting the parameters in the candidate entity pair sentiment analysis models corresponding to the loss based on the loss between the predicted sentiment and the sample sentiment labels, the adjusted entity pair sentiment analysis model better matches the sample text, thereby improving the accuracy of obtaining the relational sentiment of entity pairs using this entity pair sentiment analysis model.

[0063] Further adjustments can be made to the following parameters: W cls b cls W entity b entity W merge b merge The dimensions of the sample entity pair type embedding matrix, the sample relationship category embedding matrix, the sample entity distance embedding matrix, and the sample entity pair sentiment embedding matrix are all included.

[0064] Furthermore, the electronic device obtains the loss between the predicted sentiment and the sample sentiment label, including: the electronic device obtains the loss between the predicted sentiment and the sample sentiment label through the cross-entropy loss function.

[0065] Combination Figure 2 As shown, this disclosure provides a method for training an entity-pair sentiment analysis model, comprising:

[0066] Step S201: The electronic device acquires the sample text to be analyzed. The sample text is preceded by a complete sentence classification identifier.

[0067] In step S202, the electronic device obtains the sample entity pairs to be analyzed from the sample text.

[0068] Step S203: The electronic device acquires the sample entity pair type, sample entity pair relationship type, sample entity pair distance, and sample entity pair sentiment of the sample entity pair.

[0069] Step S204: Use sample text, sample entity pairs, sample entity pair types, sample entity pair relationship types, sample entity pair distances, and sample entity pair sentiments as training samples.

[0070] Step S205: The electronic device acquires the sample sentiment labels of the sample entity pairs.

[0071] In step S206, the electronic device inputs the sample text and sample entity pairs into a preset BERT model to obtain the entity hidden layer output vector corresponding to each sample entity in the sample entity pair and the label vector corresponding to the whole sentence classification label information; it inputs the sample entity pair type, sample entity pair relationship type, sample entity pair distance and sample entity pair sentiment into a preset embedding vector network to obtain the sample entity pair type embedding vector, sample entity pair relationship type embedding vector, sample entity pair distance embedding vector and sample entity pair sentiment embedding vector.

[0072] In step S207, the electronic device obtains the whole sentence classification vector corresponding to the sample text based on the identifier vector.

[0073] In step S208, the electronic device obtains the entity vector corresponding to each sample entity based on the hidden layer output vector of each entity.

[0074] In step S209, the electronic device obtains the whole sentence classification vector corresponding to the sample text and the entity vector corresponding to each sample entity based on the hidden layer output matrix.

[0075] In step S210, the electronic device concatenates the whole sentence classification vector, the entity vector corresponding to each sample entity, the type embedding vector of the sample entity pair, the relationship type embedding vector of the sample entity pair, the distance embedding vector of the sample entity pair, and the sentiment embedding vector of the sample entity pair to obtain the concatenated feature vector.

[0076] In step S211, the electronic device uses a preset first algorithm to fuse the whole sentence classification vector, the entity vector corresponding to each sample entity, the type embedding vector of the sample entity pair, the relationship type embedding vector of the sample entity pair, the distance embedding vector of the sample entity pair, and the sentiment embedding vector of the sample entity pair in the spliced ​​feature vector to obtain the feature vector corresponding to the sample text.

[0077] In step S212, the electronic device uses a preset second algorithm to probabilize the feature vector to obtain the predicted sentiment probability corresponding to each sentiment tag of the sample entity pair in the sample text.

[0078] In step S213, the electronic device determines the sentiment label corresponding to the maximum predicted sentiment probability as the predicted sentiment of the entity pair in the sample text.

[0079] In step S214, the electronic device obtains an entity-pair sentiment analysis model based on the predicted sentiment and the sample sentiment labels.

[0080] The method for analyzing entity pair sentiment provided in this disclosure involves obtaining sample entity pairs from sample text, and acquiring their entity pair type, entity pair relationship type, entity pair distance, and entity pair sentiment. Then, the sample text with sample sentiment tags, the entity pairs, entity pair types, entity pair relationship types, entity pair distances, and entity pair sentiments are input into a preset neural network model for training, obtaining the predicted sentiment probability corresponding to each sentiment tag of the entity pair in the sample text. The sentiment corresponding to the maximum predicted sentiment probability is determined as the predicted sentiment of the entity pair in the sample text, and an entity pair sentiment analysis model is obtained based on the predicted sentiment and sample sentiment tags. In this way, the entity relationship embedding matrix corresponding to the entity pair reflects the entity relationship between entities within the entity pair, considering the influence of entity relationships on sentiment polarity, thereby improving the ability of the trained entity pair sentiment analysis model to more accurately obtain the relationship sentiment of entity pairs based on entity relationships.

[0081] Furthermore, after obtaining the entity pair sentiment analysis model, the model is trained again for a predetermined number of rounds to obtain the entity pair sentiment analysis model after each round of training. The loss between the predicted sentiment and the sample sentiment label for each entity pair sentiment analysis model is then obtained. The entity pair sentiment analysis model with the minimum loss is determined as the optimal model. This optimal model is then designated as the final entity pair sentiment analysis model. The electronic device uses this final entity pair sentiment analysis model to analyze the relational sentiment of the entity pairs in the text to be analyzed.

[0082] Combination Figure 3 As shown, Figure 3 This is a schematic diagram illustrating the application of an entity-to-sentiment analysis model, such as... Figure 3As shown, the entity pair sentiment analysis model 304 includes a BERT pre-trained model 301, a first feedforward neural network 302, a second feedforward neural network 303, and an embedding vector network 305. The electronic device acquires the text to be analyzed, which has been augmented with whole-sentence classification information. It also acquires the entity pairs to be analyzed from the text. The device acquires the entity pair type, entity pair relation type, entity pair distance, and entity pair sentiment. The electronic device inputs the text to be analyzed and the entity pairs to be analyzed into the BERT pre-trained model 301 of the entity pair sentiment analysis model, and acquires the entity hidden layer output vectors corresponding to each entity in the entity pair and the label vectors corresponding to the whole-sentence classification information output by the BERT pre-trained model 301. Based on the label vectors, it acquires the whole-sentence classification vectors corresponding to the text to be analyzed, and based on the hidden layer output vectors of each entity, it acquires the entity vectors corresponding to each entity. The electronic device inputs the label vectors into the first feedforward neural network 302 to obtain the whole-sentence classification vectors corresponding to the text to be analyzed. The electronic device inputs the entity vectors corresponding to each entity into the first feedforward neural network 302 to obtain the entity vectors corresponding to each entity. The electronic device inputs the entity pair type, entity pair relation type, entity pair distance, and entity pair sentiment of the entity pair to be analyzed into an embedding vector network 305, and obtains the entity pair type embedding vector, entity pair relation type embedding vector, entity pair distance embedding vector, and entity pair sentiment embedding vector output by the embedding vector network 305. The electronic device inputs the whole sentence classification vector, the entity vectors corresponding to each entity, the entity pair type embedding vector, the entity pair relation type embedding vector, the entity pair distance embedding vector, and the entity pair sentiment embedding vector into a second feedforward neural network 303, triggering the second feedforward neural network to fuse the whole sentence classification vector, the entity vectors corresponding to each entity, the entity pair type embedding vector, the entity pair relation type embedding vector, the entity pair distance embedding vector, and the entity pair sentiment embedding vector using a preset first algorithm, to obtain the feature vector corresponding to the text to be analyzed, and uses the softmax() function to probabilize the feature vector, outputting the predicted sentiment probability corresponding to each sentiment label of the entity pair to be analyzed in the text to be analyzed. The sentiment label corresponding to the maximum predicted sentiment probability is determined as the relation sentiment of the entity pair to be analyzed. For example, the text to be analyzed is: "Wan Cao Ji is a brand that I pity and resent. Every time I try to give domestic skincare products a chance, I'm likely to be disappointed, until I used its Yuejiu Freeze-Dried Mask. This product completely shattered my preconceived notions." Here, "Wan Cao Ji" is the brand entity, and "Yuejiu Freeze-Dried Mask" is the product entity related to "Wan Cao Ji." The sentiment of the brand entity "Wan Cao Ji" is negative, while the sentiment of the product entity "Yuejiu Freeze-Dried Mask" is positive. The electronic device obtains the entity pair type, entity pair relationship type, entity pair distance, and entity pair sentiment corresponding to the entity pair "Wan Cao Ji - Yuejiu Freeze-Dried Mask".The electronic device inputs the text to be analyzed, the entity pairs to be analyzed, the entity pair type, the entity pair relationship type, the entity pair distance, and the entity pair sentiment into the final entity pair sentiment analysis model. The model processes the text and outputs the predicted sentiment probabilities for each sentiment tag of the entity pair “Wan Cao Ji - Yue Jiu Freeze-Dried Mask”: “Positive: 0.6”, “Neutral: 0.2”, and “Negative: 0.2”. The maximum predicted sentiment probability is 0.6. The sentiment tag corresponding to the maximum predicted sentiment probability of 0.6 is positive. Therefore, the relationship sentiment of the entity pair “Wan Cao Ji - Yue Jiu Freeze-Dried Mask” is positive.

[0083] Combination Figure 4 As shown in the embodiments of this disclosure, an apparatus for analyzing entity pair relationship sentiment is provided, including a text acquisition module 1, an entity pair acquisition module 2, an entity pair relationship acquisition module 3, and an acquisition module 4. The text acquisition module 1 is configured to acquire text to be analyzed. The entity pair acquisition module 2 is configured to acquire entity pairs to be analyzed from the text to be analyzed. The entity pair relationship acquisition module 3 is configured to acquire the entity pair type, entity pair relationship type, entity pair distance, and entity pair sentiment of the entity pairs to be analyzed. The acquisition module 4 is configured to acquire the relationship sentiment of the entity pairs to be analyzed based on the text to be analyzed, the entity pairs to be analyzed, the entity pair type, the entity pair relationship type, the entity pair distance, and the entity pair sentiment.

[0084] The apparatus for analyzing entity pair relationship sentiment provided in this disclosure obtains entity pairs to be analyzed from the text to be analyzed, and acquires the entity pair type, entity pair relationship type, entity pair distance, and entity pair sentiment. Then, it obtains the relationship sentiment of the entity pairs based on the text to be analyzed, the entity pairs, the entity pair type, the entity pair relationship type, the entity pair distance, and the entity pair sentiment. In this way, the entity pair type, entity pair relationship type, entity pair distance, and entity pair sentiment reflect the entity relationships between entities within an entity pair, and consider the influence of the entity pair type, entity pair relationship type, entity pair distance, and entity pair sentiment on the sentiment polarity of the entity pairs, thereby improving the accuracy of obtaining the relationship sentiment of entity pairs.

[0085] Furthermore, the entity pair relationship acquisition module 2 is configured to acquire the entity pair type, entity pair relationship type, entity pair distance, and entity pair sentiment of the entity pair to be analyzed through the following methods: Acquire the entity type of each entity in the entity pair to be analyzed, and obtain the entity pair type based on the entity types of each entity in the entity pair to be analyzed. Acquire the relationship type between each entity in the entity pair to be analyzed, and determine the relationship type between each entity in the entity pair to be analyzed as the entity pair relationship type. Acquire the distance between the entities in the entity pair to be analyzed in the text to be analyzed, and determine the distance between the entities in the entity pair to be analyzed in the text to be analyzed as the entity pair distance. Acquire the entity sentiment of each entity in the entity pair to be analyzed, and obtain the entity pair sentiment based on the entity sentiment of each entity in the entity pair to be analyzed.

[0086] Furthermore, the acquisition module is configured to improve the following method for acquiring the relational sentiment of entity pairs based on the text to be analyzed, the entity pairs to be analyzed, the entity pair type, the entity pair relationship type, the entity pair distance, and the entity pair sentiment: input the text to be analyzed, the entity pairs to be analyzed, the entity pair type, the entity pair relationship type, the entity pair distance, and the entity pair sentiment into a preset entity pair sentiment analysis model to acquire the relational sentiment of the entity pairs to be analyzed.

[0087] Combination Figure 5 As shown in the embodiments of this disclosure, an apparatus for analyzing entity pair relationship sentiment is provided, further comprising: a model training module 5, configured to acquire sample text to be analyzed; the sample text is labeled with whole-sentence classification information. The apparatus acquires sample entity pairs to be analyzed from the sample text. It acquires the sample entity pair type, sample entity pair relationship type, sample entity pair distance, and sample entity pair sentiment. The sample text, sample entity pairs, sample entity pair type, sample entity pair relationship type, sample entity pair distance, and sample entity pair sentiment are used as training samples. The apparatus acquires sample sentiment tags for the sample entity pairs. The training samples with sample sentiment tags are input into a preset neural network model for training to obtain an entity pair sentiment analysis model. The preset neural network model includes a preset BERT model and a preset embedding vector network.

[0088] Text acquisition module 1 is configured to acquire the text to be analyzed, which includes sentence classification information, and send it to the entity pair acquisition module and the input module. Entity pair acquisition module 2 is configured to extract entity pairs from the text to be analyzed and send them to the entity pair relationship acquisition module. Entity pair relationship acquisition module 3 is configured to acquire the entity pair type, entity pair relationship type, entity pair distance, and entity pair sentiment of each entity pair, and send these information to the input module 4. Model training module 5 is configured to acquire sample text to be analyzed, which includes sentence classification information. The module acquires sample entity pairs from the sample text. It also acquires the sample entity pair type, sample entity pair relationship type, sample entity pair distance, and sample entity pair sentiment. The module uses the sample text, sample entity pairs, sample entity pair type, sample entity pair relationship type, sample entity pair distance, and sample entity pair sentiment as training samples. Finally, it acquires the sample sentiment tags for the sample entity pairs. Training samples with sentiment labels are input into a pre-defined neural network model for training to obtain an entity pair sentiment analysis model. The pre-defined neural network model includes a pre-defined BERT model and a pre-defined embedding vector network. The acquisition module 4 is configured to input the text to be analyzed, the entity pair to be analyzed, the entity pair type, the entity pair relationship type, the entity pair distance, and the entity pair sentiment into the pre-defined entity pair sentiment analysis model to obtain the relationship sentiment of the entity pair to be analyzed.

[0089] The apparatus for analyzing entity pair sentiment provided in this disclosure obtains entity pairs to be analyzed from the text to be analyzed, and acquires the entity pair type, entity pair relationship type, entity pair distance, and entity pair sentiment of the entity pairs. Then, the text to be analyzed, the entity pairs to be analyzed, the entity pair type, entity pair relationship type, entity pair distance, and entity pair sentiment are input into a preset entity pair sentiment analysis model to obtain the relationship sentiment of the entity pairs to be analyzed. In this way, the entity pair type, entity pair relationship type, entity pair distance, and entity pair sentiment reflect the entity relationships between entities within an entity pair, and consider the influence of the entity pair type, entity pair relationship type, entity pair distance, and entity pair sentiment on the sentiment polarity of the entity pairs to be analyzed, thereby improving the accuracy of obtaining the relationship sentiment of the entity pairs to be analyzed.

[0090] Furthermore, the model training module is configured to train a pre-defined neural network model by inputting training samples with sample sentiment labels as follows: During training, sample text and sample entity pairs are input into the pre-defined BERT model to obtain the entity hidden layer output vectors corresponding to each sample entity in the sample entity pair and the label vectors corresponding to the whole sentence classification label information; the sample entity pair type, sample entity pair relation type, sample entity pair distance, and sample entity pair sentiment are input into a pre-defined embedding vector network to obtain the sample entity pair type embedding vector, sample entity pair relation type embedding vector, sample entity pair distance embedding vector, and sample entity pair sentiment embedding vector. The whole sentence classification vector corresponding to the sample text is obtained based on the label vectors. The entity vector corresponding to each sample entity is obtained based on the hidden layer output vectors of each entity. The entity pair sentiment analysis model is obtained based on the whole sentence classification vector, the entity vector corresponding to each sample entity, the sample entity pair type embedding vector, the sample entity pair relation type embedding vector, the sample entity pair distance embedding vector, the sample entity pair sentiment embedding vector, and the sample sentiment label.

[0091] Furthermore, the model training module is configured to obtain the entity-to-sentiment analysis model based on the whole sentence classification vector, the entity vectors corresponding to each sample entity, the type embedding vectors of sample entity pairs, the type embedding vectors of sample entity pairs, the distance embedding vectors of sample entity pairs, the sentiment embedding vectors of sample entity pairs, and the sentiment labels of the samples, using the following method: The whole sentence classification vector, the entity vectors corresponding to each sample entity, the type embedding vectors of sample entity pairs, the type embedding vectors of sample entity pairs, the distance embedding vectors of sample entity pairs, and the sentiment embedding vectors of sample entity pairs are concatenated to obtain a concatenated feature vector. A preset first algorithm is used to fuse the whole sentence classification vector, the entity vectors corresponding to each sample entity, the type embedding vectors of sample entity pairs, the type embedding vectors of sample entity pairs, the distance embedding vectors of sample entity pairs, and the sentiment embedding vectors of sample entity pairs in the concatenated feature vector to obtain the feature vectors corresponding to the sample text. The entity-to-sentiment analysis model is then obtained based on the feature vectors.

[0092] Furthermore, the model training module is configured to obtain the entity pair sentiment analysis model based on the feature vectors using the following method: The feature vectors are probabilistically transformed using a pre-defined second algorithm to obtain the predicted sentiment probability corresponding to each sentiment tag of the sample entity pair in the sample text. The sentiment tag corresponding to the maximum predicted sentiment probability is determined as the predicted sentiment of the sample entity pair in the sample text. The entity pair sentiment analysis model is then obtained based on the predicted sentiment and the sample sentiment tags.

[0093] Combination Figure 6As shown, this disclosure provides an apparatus for analyzing entity sentiment regarding relationships, including a processor 100 and a memory 101. Optionally, the apparatus may further include a communication interface 102 and a bus 103. The processor 100, communication interface 102, and memory 101 can communicate with each other via the bus 103. The communication interface 102 can be used for information transmission. The processor 100 can invoke logical instructions stored in the memory 101 to execute the method for analyzing entity sentiment regarding relationships described in the above embodiment.

[0094] Furthermore, the logic instructions in the aforementioned memory 101 can be implemented as software functional units and, when sold or used as independent products, can be stored in a computer-readable storage medium.

[0095] The memory 101, as a storage medium, can be used to store software programs and computer-executable programs, such as program instructions / modules corresponding to the methods in the embodiments of this disclosure. The processor 100 executes functional applications and data processing by running the program instructions / modules stored in the memory 101, that is, it implements the method for analyzing entity-to-relationship sentiment in the above embodiments.

[0096] The memory 101 may include a program storage area and a data storage area. The program storage area may store the operating system and applications required for at least one function; the data storage area may store data created based on the use of the terminal device. Furthermore, the memory 101 may include high-speed random access memory and may also include non-volatile memory.

[0097] The apparatus for analyzing entity pair relationship sentiment provided in this embodiment obtains entity pairs to be analyzed from the text to be analyzed, and acquires the entity pair type, entity pair relationship type, entity pair distance, and entity pair sentiment of the entity pairs. Then, the relationship sentiment of the entity pairs is obtained based on the text to be analyzed, the entity pairs to be analyzed, the entity pair type, entity pair relationship type, entity pair distance, and entity pair sentiment. In this way, the entity relationship between entities within an entity pair is reflected through the entity pair type, entity pair relationship type, entity pair distance, and entity pair sentiment, and the influence of the entity pair type, entity pair relationship type, entity pair distance, and entity pair sentiment on the sentiment polarity of the entity pairs is considered, thereby improving the accuracy of obtaining the relationship sentiment of entity pairs.

[0098] This disclosure provides a storage medium storing computer-executable instructions configured to execute the above-described method for analyzing entity-to-relationship sentiment.

[0099] The aforementioned storage media can be either transient computer-readable storage media or non-transitory computer-readable storage media. Non-transitory storage media include 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, and can also be transient storage media.

[0100] The foregoing description and accompanying drawings fully illustrate embodiments of this disclosure to enable those skilled in the art to practice them. Other embodiments may include structural, logical, electrical, procedural, and other changes. The embodiments represent only possible variations. Individual components and functions are optional unless explicitly required, and the order of operation may vary. Parts and features of some embodiments may be included in or replace parts and features of other embodiments. Moreover, the terminology used in this application is for describing embodiments only and is not intended to limit the claims. As used in the description of embodiments and claims, the singular forms “a,” “an,” and “the” are intended to equally include the plural forms unless the context clearly indicates otherwise. Similarly, the term “and / or” as used in this application means including one or more of the associated listed items and all possible combinations thereof. Additionally, when used in this application, the term "comprise" and its variations "comprises" and / or "comprising" refer to the presence of stated features, integrals, steps, operations, elements, and / or components, but do not exclude the presence or addition of one or more other features, integrals, steps, operations, elements, components, and / or groups thereof. Without further limitations, an element defined by the phrase "comprises a..." does not exclude the presence of other identical elements in the process, method, or apparatus that includes said element. In this document, each embodiment may focus on the differences from other embodiments, and similar or identical parts between embodiments can be referred to mutually. For methods, products, etc., disclosed in the embodiments, if they correspond to the method section disclosed in the embodiments, the relevant parts can be referred to the description of the method section.

[0101] Those skilled in the art will recognize that the units and algorithm steps of the various examples described in conjunction with the embodiments disclosed herein can be implemented in electronic hardware, or a combination of computer software and electronic hardware. Whether these functions are implemented in hardware or software depends on the specific application and design constraints of the technical solution. Those skilled in the art can use different methods to implement the described functions for each specific application, but such implementation should not be considered beyond the scope of the embodiments of this disclosure. Those skilled in the art will clearly understand that, for the sake of convenience and brevity, the specific working processes of the systems, devices, and units described above can be referred to the corresponding processes in the foregoing method embodiments, and will not be repeated here.

[0102] The flowcharts and block diagrams in the accompanying drawings illustrate the architecture, functionality, and operation of possible implementations of systems, methods, and computer program products according to embodiments of this disclosure. 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. In some alternative implementations, the functions marked in the blocks may occur in a different order than that shown in the drawings. For example, two consecutive blocks may actually be executed substantially in parallel, and they may sometimes be executed in reverse order, depending on the functions involved. In the descriptions corresponding to the flowcharts and block diagrams in the accompanying drawings, the operations or steps corresponding to different blocks may also occur in a different order than disclosed in the description, and sometimes there is no specific order between different operations or steps. For example, two consecutive operations or steps may actually be executed substantially in parallel, and they may sometimes be executed in reverse order, depending on the functions involved. Each block in a block diagram and / or flowchart, and combinations of blocks in a block diagram and / or flowchart, can be implemented using a dedicated hardware-based system that performs the specified function or action, or using a combination of dedicated hardware and computer instructions.

Claims

1. A method for analyzing entity-to-relationship sentiment, characterized in that, include: Obtain the text to be analyzed; Obtain the entity pairs to be analyzed from the text to be analyzed; Obtain the entity pair type, entity pair relationship type, entity pair distance, and entity pair sentiment of the entity pair to be analyzed; the entity pair distance is the distance between the entities in the entity pair to be analyzed in the text to be analyzed; The entity pair to be analyzed, the entity pair to be analyzed, the entity pair type, the entity pair relationship type, the entity pair distance, and the entity pair sentiment are input into a preset entity pair sentiment analysis model to obtain the relationship sentiment of the entity pair to be analyzed. The preset entity pair sentiment analysis model is obtained through the following methods: obtaining sample text to be analyzed; the sample text is labeled with whole-sentence classification information; obtaining sample entity pairs to be analyzed from the sample text; obtaining the sample entity pair type, sample entity pair relationship type, sample entity pair distance, and sample entity pair sentiment of the sample entity pairs; using the sample text, the sample entity pairs, the sample entity pair type, the sample entity pair relationship type, the sample entity pair distance, and the sample entity pair sentiment as training samples; obtaining the sample sentiment labels of the sample entity pairs; inputting the training samples with the sample sentiment labels into a preset neural network model for training to obtain the entity pair sentiment analysis model; the preset neural network model includes a preset BERT model and a preset embedding vector network.

2. The method according to claim 1, characterized in that, Obtain the entity pair type, entity pair relation type, entity pair distance, and entity pair sentiment of the entity pair to be analyzed, including: Obtain the entity type of each entity in the entity pair to be analyzed, and obtain the entity pair type based on the entity type of each entity in the entity pair to be analyzed; Obtain the relationship type between each entity in the entity pair to be analyzed, and determine the relationship type between each entity in the entity pair to be analyzed as the entity pair relationship type; Obtain the distance between entities in the entity pair to be analyzed and the text to be analyzed, and determine the distance between entities in the entity pair to be analyzed and the text to be analyzed as the entity pair distance; Obtain the entity sentiment of each entity in the entity pair to be analyzed, and obtain the entity pair sentiment based on the entity sentiment of each entity in the entity pair to be analyzed.

3. The method according to claim 1, characterized in that, Training samples bearing the aforementioned sentiment labels are input into a pre-defined neural network model for training, including: During training, the sample text and the sample entity pairs are input into the preset BERT model to obtain the entity hidden layer output vector corresponding to each sample entity in the sample entity pair and the label vector corresponding to the whole sentence classification label information; the sample entity pair type, the sample entity pair relation type, the sample entity pair distance, and the sample entity pair sentiment are input into the preset embedding vector network to obtain the sample entity pair type embedding vector, the sample entity pair relation type embedding vector, the sample entity pair distance embedding vector, and the sample entity pair sentiment embedding vector. The whole sentence classification vector corresponding to the sample text is obtained based on the identifier vector; The entity vector corresponding to each sample entity is obtained based on the hidden layer output vector of each entity. The entity pair sentiment analysis model is obtained based on the whole sentence classification vector, the entity vector corresponding to each sample entity, the sample entity pair type embedding vector, the sample entity pair relation type embedding vector, the sample entity pair distance embedding vector, the sample entity pair sentiment embedding vector, and the sample sentiment label.

4. The method according to claim 3, characterized in that, The entity pair sentiment analysis model is obtained based on the whole sentence classification vector, the entity vector corresponding to each sample entity, the sample entity pair type embedding vector, the sample entity pair relation type embedding vector, the sample entity pair distance embedding vector, the sample entity pair sentiment embedding vector, and the sample sentiment label, including: The whole sentence classification vector, the entity vector corresponding to each sample entity, the sample entity pair type embedding vector, the sample entity pair relation type embedding vector, the sample entity pair distance embedding vector, and the sample entity pair sentiment embedding vector are concatenated to obtain the concatenated feature vector; The first preset algorithm is used to fuse the whole sentence classification vector, the entity vector corresponding to each sample entity, the sample entity pair type embedding vector, the sample entity pair relation type embedding vector, the sample entity pair distance embedding vector, and the sample entity pair sentiment embedding vector in the spliced ​​feature vector to obtain the feature vector corresponding to the sample text. The entity pair sentiment analysis model is obtained based on the feature vector.

5. The method according to claim 4, characterized in that, The entity pair sentiment analysis model is obtained based on the feature vector, including: The feature vector is probabilistically transformed using a pre-defined second algorithm to obtain the predicted sentiment probability corresponding to each sentiment tag of the sample entity pair in the sample text. The sentiment label corresponding to the maximum predicted sentiment probability is determined as the predicted sentiment of the sample entity pair in the sample text; The entity pair sentiment analysis model is obtained based on the predicted sentiment and the sample sentiment labels.

6. An apparatus for analyzing the relational sentiment of entities, characterized in that, include: The text acquisition module is configured to acquire the text to be analyzed. The entity pair acquisition module is configured to acquire entity pairs to be analyzed from the text to be analyzed. The entity pair relationship acquisition module is configured to acquire the entity pair type, entity pair relationship type, entity pair distance, and entity pair sentiment of the entity pair to be analyzed; the entity pair distance is the distance between the entities in the entity pair to be analyzed and the text to be analyzed. The acquisition module is configured to input the text to be analyzed, the entity pairs to be analyzed, the entity pair types, the entity pair relationship types, the entity pair distances, and the entity pair sentiments into a preset entity pair sentiment analysis model to acquire the relationship sentiments of the entity pairs to be analyzed. The preset entity pair sentiment analysis model is acquired through the following methods: acquiring sample text to be analyzed; the sample text has whole-sentence classification information added; acquiring sample entity pairs to be analyzed from the sample text; acquiring the sample entity pair types, sample entity pair relationship types, sample entity pair distances, and sample entity pair sentiments of the sample entity pairs; using the sample text, the sample entity pairs, the sample entity pair types, the sample entity pair relationship types, the sample entity pair distances, and the sample entity pair sentiments as training samples; acquiring the sample sentiment tags of the sample entity pairs; and inputting the training samples with the sample sentiment tags into a preset neural network model for training to obtain the entity pair sentiment analysis model. The preset neural network model includes a preset BERT model and a preset embedding vector network.

7. An apparatus for analyzing entity-to-relationship sentiment, comprising a processor and a memory storing program instructions, characterized in that, The processor is configured to, when executing the program instructions, perform the method for analyzing entity-to-relationship sentiment as described in any one of claims 1 to 5.

8. A storage medium storing program instructions, characterized in that, When the program instructions are executed, they perform the method for analyzing entity-to-relationship sentiment as described in any one of claims 1 to 5.

Citation Information

Patent Citations

  • Emotion analysis method and device and storage medium

    CN110287405A

  • Text sentiment analysis method and system

    CN111324739A