Natural language text triple extraction method and system based on attention mechanism
Through the natural language text triple extraction method based on the attention mechanism, combined with the dual-channel encoding and the bidirectional attention mechanism, the problem of insufficient information and multi-stage task error transmission is solved, and more efficient information extraction and accuracy are achieved. Suitable for multivariate information extraction tasks.
Patent Information
- Application Number
- CN202111060637.6
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2021-09-10
- Publication Date
- 2024-10-22
- Estimated Expiration
- Not applicable · inactive patent
AI Technical Summary
The information extracted by the existing technology from natural language text is not comprehensive enough, and usually only involves one or two of
A natural language text triple extraction method based on the attention mechanism is adopted. Through dual-channel encoding and bidirectional attention mechanism, combined with bidirectional long short-term memory network and graph convolution network, the loss function is optimized to improve the directness and accuracy of information extraction. .
It achieves more efficient key information extraction, reduces error propagation, improves the effect of triple extraction tasks, and incorporates the correlation matrix into the optimization goal to give it interpretability, making it suitable for multivariate information extraction tasks.
Smart Images

Figure CN113869059B_ABST
Abstract
Description
Technical Field
[0001] The present invention relates to the field of natural language processing technology, specifically, a method for extracting<aspect,opinion,sentiment> The present invention relates to a triplet method and system, specifically to a natural language text triplet extraction method and system based on an attention mechanism. Background Art
[0002] Deep learning is a method that uses computers to imitate the way human neural networks process information. After the 2010s, it has made major breakthroughs in image processing, natural language processing and other fields. The attention mechanism in deep learning draws on a brain information processing mechanism that is unique to human vision. Generally speaking, when humans observe the external environment, they will quickly scan the entire scene, and then quickly lock the target area of focus based on the processing of brain signals, and finally form a focus of attention. This mechanism can help humans screen out target areas with important valuable information from a large number of irrelevant background areas under limited resources, helping humans to process visual information more efficiently. In the field of natural language processing, the attention mechanism is used to locate key words to achieve the purpose of efficiently and accurately processing text information. Sentiment analysis is a technology that uses computers to process human natural language to obtain relevant emotional tendencies from it. Fine-grained sentiment analysis aims to obtain more information corresponding to emotions on the basis of obtaining emotional tendencies. Triple sentiment analysis is a type of fine-grained sentiment analysis, which aims to extract from natural language texts.<aspect,opinion,sentiment> Aspect is the object of emotion expression, which is a specific object, usually a noun, pronoun, etc.; opinion is a keyword that reflects emotion, usually an adjective, modal particle, etc.; sentiment is the specific emotion polarity, usually positive, negative, and neutral.
[0003] The existing technical solutions are:
[0004] 1. The dictionary-based fine-grained sentiment analysis method first marks the sentiment words, determines the sentiment tendency, then processes the sentiment reversal words and transition words, and finally summarizes the sentiment scores using certain rules.
[0005] 2. A fine-grained sentiment analysis method based on supervised learning uses a syntactic spanning tree to generate a feature set of associated evaluation objects, and then uses a machine learning method for training.
[0006] 3. Fine-grained sentiment analysis method based on deep learning: First, obtain the word embedding of each vocabulary, and then use structures such as recurrent networks or convolutional networks to extract relevant information in multiple stages.
[0007] Traditional fine-grained sentiment analysis methods usually face two problems:
[0008] 1. The extracted information is not comprehensive enough, usually only involving<aspect,opinion,sentiment> One or both of;
[0009] 2. The method of extracting more comprehensive information usually extracts different information in multiple stages. Therefore, the mutual assistance and improvement effect between multiple tasks is indirect, and there is a problem of error transmission;
[0010] Therefore, we propose a triplet sentiment analysis method based on attention mechanism to solve the problems raised above. Summary of the invention
[0011] The present invention provides a natural language text triple extraction method and system based on an attention mechanism to solve the problems raised in the above background technology, such as insufficient comprehensiveness of information extraction, indirect mutual promotion effect between multiple information, and error transmission of multi-stage tasks.
[0012] The technical solution adopted by the method of the present invention is: a natural language text triple extraction method based on an attention mechanism, comprising the following steps:
[0013] Step 1: Dual-path encoding of the input;
[0014] Assume the input is W = {w1,w2,…,w n}, where w i is the word embedding of the i-th word; the input is encoded in two ways, including aspect way and opinion way;
[0015] For the aspect path, the input W is processed by a two-layer bidirectional long short-term memory network (BiLSTM) to obtain the preliminary encoding of the aspect path fa' = {fa'1, fa'2, ..., fa' n}, where fa' i is the result of two-layer BiLSTM processing corresponding to the i-th word;
[0016] For the opinion path, the input W is first processed by a graph convolutional network (GCN), where the adjacency matrix of the graph convolutional network is determined by the dependency analysis tree of the input sentence. This step obtains the text structure information required for the opinion information extraction process; then the result of the graph convolution is processed by BiLSTM and CRF in turn to obtain the encoding result f of the opinion encoding path. p ;
[0017] Step 2: Process the result of dual-path encoding using a bidirectional attention mechanism;
[0018] The result of the two-way encoding is processed by a two-way attention mechanism, and the information extracted from the aspect path and the information extracted from the opinion path are processed by a two-way attention mechanism. After processing, the two-way information of the aspect path and the opinion path is recorded as h a 、h p ;
[0019] Step 3: The loss function is calculated by combining the results of steps 1 and 2, and the stochastic gradient descent method is used to perform iterative training to reduce the value of the loss function and optimize the parameters involved in the training.
[0020] Step 4: According to the parameters obtained after training, the correlation matrix obtained by the bidirectional attention mechanism is processed to obtain the triple result<aspect,opinion,sentiment> .
[0021] The technical solution adopted by the system of the present invention is: a natural language text triple extraction system based on attention mechanism, including the following system, including the following modules:
[0022] Module 1, for two-way encoding of input;
[0023] Assume the input is W = {w1,w2,…,w n}, where w i is the word embedding of the i-th word; the input is encoded in two ways, including aspect way and opinion way;
[0024] For the aspect path, the input W is processed by a two-layer bidirectional long short-term memory network (BiLSTM) to obtain the preliminary encoding of the aspect path fa' = {fa'1, fa'2, ..., fa' n}, where fa' i is the result of two-layer BiLSTM processing corresponding to the i-th word;
[0025] For the opinion path, the input W is first processed by a graph convolutional network (GCN), where the adjacency matrix of the graph convolutional network is determined by the dependency analysis tree of the input sentence. This step obtains the text structure information required for the opinion information extraction process; then the result of the graph convolution is processed by BiLSTM and CRF in turn to obtain the encoding result f of the opinion encoding path. p ;
[0026] Module 2 is used to process the results of dual-path encoding using a bidirectional attention mechanism;
[0027] The result of the two-way encoding is processed by a two-way attention mechanism, and the information extracted from the aspect path and the information extracted from the opinion path are processed by a two-way attention mechanism. After processing, the two-way information of the aspect path and the opinion path is recorded as h a 、h p ;
[0028] Module 3 is used to calculate the loss function LOSS by integrating the results in modules 1 and 2, and to perform iterative training using the stochastic gradient descent method to reduce the value of the loss function LOSS, thereby optimizing the parameters involved in the training.
[0029] Module 4 is used to process the correlation matrix obtained by the bidirectional attention mechanism according to the parameters obtained after the training to obtain the triple result<aspect,opinion,sentiment> .
[0030] Compared with the prior art, the beneficial effects of the present invention are: the triplet sentiment analysis method based on the attention mechanism is divided into two-way encoding, introduces auxiliary tasks and a two-way attention mechanism, and extracts key information more efficiently from multiple angles.
[0031] The correlation matrix in the attention mechanism is incorporated into the optimization objective, giving the correlation matrix a certain interpretability meaning, and transforming the triplet extraction task from a multi-stage task to a one-stage task, solving the error propagation problem and improving the effect.
[0032] At the same time, the method of incorporating the correlation matrix in the attention mechanism into the optimization objective is not only applicable to the triple sentiment extraction task, but can also be extended to a variety of multi-information extraction tasks. BRIEF DESCRIPTION OF THE DRAWINGS
[0033] Figure 1 The figure is a flow chart of a method according to an embodiment of the present invention.
[0034] Figure 2 Schematic diagram of dual-path encoding according to an embodiment of the present invention.
[0035] Figure 3 Schematic diagram of the bidirectional attention mechanism of an embodiment of the present invention.
[0036] Figure 4 Schematic diagram of triplet processing according to an embodiment of the present invention. DETAILED DESCRIPTION
[0037] In order to facilitate ordinary technicians in the field to understand and implement the present invention, the present invention is further described in detail below in conjunction with the accompanying drawings and embodiments. It should be understood that the implementation examples described herein are only used to illustrate and explain the present invention, and are not used to limit the present invention.
[0038] Please see Figure 1 The present invention provides a method for extracting triples of natural language text based on an attention mechanism, comprising the following steps:
[0039] Step 1: Dual-path encoding of the input;
[0040] Please see Figure 2 In this embodiment, the input is assumed to be W = {w1, w2, ..., w n}, where w i is the word embedding of the ith word; the input is encoded in two ways, including aspect path and opinion path; it includes three auxiliary tasks, namely: the sentiment consistency auxiliary task to ensure the consistency of sentiment labels belonging to the same aspect, the aspect pre-labeling task to ensure the quality of information extraction in the aspect encoding path, and the opinion pre-labeling task to ensure the quality of information extraction in the opinion encoding path.
[0041] For the aspect path, the input W is processed by a two-layer bidirectional long short-term memory network (BiLSTM) to obtain the preliminary encoding of the aspect path fa' = {fa'1, fa'2, ..., fa' n}, where fa' i is the result of two-layer BiLSTM processing corresponding to the i-th word;
[0042] In this embodiment, in order to ensure the consistency of the emotion labels belonging to the same aspect, the emotion consistency auxiliary task is used to optimize the encoding process; in order to ensure the quality of information extraction of the opinion encoding path, the opinion pre-labeling task is used to optimize the encoding process;
[0043] The sentiment consistency auxiliary task uses the following formula to process fa' into fa" considering sentiment consistency:
[0044]
[0045] Among them, ☉ represents bitwise multiplication; g i is the gate vector for controlling sentiment consistency, W g is the weight matrix of the sentiment consistency module, b g is the bias vector of the emotion consistency module, σ() represents the nonlinear activation function; fa” is processed by the conditional random field (CRF) to obtain the aspect path encoding result f a ;
[0046] Then f aPerform softmax processing to obtain a preliminary aspect prediction, and use the cross entropy function to calculate the loss aspect pre-label loss with the BIOS label of the actual aspect road label. Among them, each word is marked, and each word has four possible labels: B, I, O, and S, which are begin, inside, other, and single, respectively representing the beginning part of the keyword, the inside of the keyword, the outside of the keyword, and a single-word keyword.
[0047] For the opinion path, the input W is first processed by a graph convolutional network (GCN), where the adjacency matrix of the graph convolutional network is determined by the dependency analysis tree of the input sentence. This step obtains the text structure information required for the opinion information extraction process; then the result of the graph convolution is processed by BiLSTM and CRF in turn to obtain the encoding result f of the opinion encoding path. p ;
[0048] In this embodiment, in order to ensure the quality of opinion coding information extraction, the opinion pre-label task is used to optimize the coding process; p Perform softmax processing to obtain a preliminary opinion prediction, and use the cross entropy function to calculate the loss of the opinion pre-labeling task with the BIOS label of the actual opinion path.
[0049] Step 2: Process the result of dual-path encoding using a bidirectional attention mechanism;
[0050] The result of the two-way encoding is processed by a two-way attention mechanism, and the information extracted from the aspect path and the information extracted from the opinion path are processed by a two-way attention mechanism. After processing, the two-way information of the aspect path and the opinion path is recorded as h a 、h p After processing, the aspect path and opinion path information will influence each other to achieve the purpose of mutual assistance and promotion.
[0051] Please see Figure 3 The specific implementation of step 2 of this embodiment includes the following sub-steps:
[0052] Step 2.1: Get the multi-head attention tensor αa→p;
[0053]
[0054] Among them, G a , G pare all three-dimensional tensors of (k, 2d, 2d), randomly initialized and participate in the training process; f a 、f p They are the encoding of the aspect path and the encoding of the opinion path, and their dimensions are both (n, 2d), where n is the length of the sentence and 2d is the dimension of the aspect encoding vector and the opinion encoding vector; as shown in the formula, we get a vector with dimension k α ij is an element of the set α;
[0055] Step 2.2: Convert the attention tensor α a→p Calculated as the correlation matrix A a→p ;
[0056]
[0057] Among them, v is a randomly initialized k-dimensional vector that participates in the training process. The purpose is to weight and aggregate the information generated by multiple attention heads;
[0058] The information generated by multiple attention heads can be weighted and aggregated;
[0059] Step 2.3: Get the correlation matrix A p→a : A p→a =(A a→p ) T ;
[0060] Step 2.4: Get the final code h a With h p ;
[0061] h a =h a +softmax r (A a→p )h p ;
[0062] h p =h p +softmax r (A p→a )h a ;
[0063] Among them, softmax r Perform softmax operation on the rows of the matrix.
[0064] Step 3: The loss function is calculated by combining the results of steps 1 and 2, and the stochastic gradient descent method is used to perform iterative training with the purpose of reducing the value of the loss function, and the various parameters involved in the training in the optimization method are optimized.
[0065] In this embodiment, the loss function is calculated by combining the results in steps 1 and 2. Here, the correlation matrix in the attention mechanism is creatively incorporated into the optimization target, giving the correlation matrix a certain interpretable meaning;
[0066] In this embodiment, the specific implementation of step 3 includes the following sub-steps:
[0067] Step 3.1: Set h a Through the cross entropy loss of the softmax layer and the aspect's BIOS label with sentiment classification, we get Among them, each word is labeled, and each label is divided into two parts. The first part is BIOS. When the first part is B / I / S, the tail label exists and has three possibilities: NEG, POS, and NAT, which represent negative sentiment, positive sentiment, and neutral sentiment respectively;
[0068] Step 3.2: h p Through the cross entropy loss of the softmax layer and the opinion BIOS label, we get
[0069] Step 3.3: Construct the guidance matrix G a→p and G p→a ;
[0070]
[0071] G p→a =(G a→p ) T ;
[0072] Step 3.4: Calculate the relevant loss function LossA;
[0073] Loss A =||A a→ p ☉ G a→p ||=||A p→a ☉ G p→a ||;
[0074] Step 3.5: Add the five loss functions to get the final loss function LOSS in the training process;
[0075]
[0076] Step 3.6: Iteratively optimize the parameters involved in the training of the method with the goal of minimizing the value of the loss function LOSS.
[0077] Step 4: According to the parameters obtained after training, the correlation matrix obtained by the bidirectional attention mechanism is processed to obtain the triple result<aspect,opinion,sentiment> .
[0078] Please see Figure 4 In this embodiment, the triple result is obtained in step 4<aspect,opinion,sentiment> The specific process is:
[0079] First, according to h a The aspect prediction label obtained by the softmax layer is used to obtain the BIOS label of the aspect with emotion. Parse the aspect-sentiment pair sequence aspect-pairs from it: {<aspect1,sentiment1>,<aspect2,sentiment2>,…,<aspect m ,sentiment m >}Each aspect i The corresponding word sequence is words i : where n i is the subscript sequence of the word group corresponding to the i-th aspect, |n i | indicates the length of the subscript sequence;
[0080] A necessary example: from the emotional BIOS tag sequence {O, O, B-POS, I-NAT}, an aspect-sentiment pair <{word3, word4}, positive emotion> can be parsed. It is worth noting that even if the emotional consistency auxiliary task is applied, the second half of the last three tags in the tag sequence is not consistent (ideally, since the words corresponding to these three tags belong to the same aspect, their emotional tags should be consistent). In this case, the majority principle is used to select the majority from the emotional tags as the final label of the aspect. If there is more than one emotional label with the largest number, the emotional label corresponding to the B label is selected as the final label of the aspect (such as in this example).
[0081] Next, get the aspect i The corresponding anchor subscript of the opinion phrase:
[0082]
[0083] Where n is the number of words in the input sentence;
[0084] Next in the sentence from the word wordJi Start and search left until you reach:
[0085]
[0086] Similarly, search rightward until:
[0087]
[0088] Among them, l is the subscript for searching words to the left, r is the subscript for searching words to the right, and λ is a preset parameter, which is a real number between 0 and 1 and is generally set to 0.6. In this way, the opinion phrase corresponding to the i-th aspect-sentiment pair is obtained, that is, the phrase consisting of the words with subscripts from l to r.
[0089] In fine-grained sentiment analysis, dual-path encoding is used to extract information with different focuses; auxiliary tasks are introduced to improve the effect of information extraction; the bidirectional attention mechanism is used to enable the extraction processes of aspect and opinion to promote each other; the correlation matrix in the attention mechanism is taken into optimization consideration to give it interpretable meaning, and a unified model is explicitly constructed to improve the triple extraction effect.
[0090] It should be understood that the above description of the preferred embodiment is relatively detailed and cannot be regarded as limiting the scope of patent protection of the present invention. Under the enlightenment of the present invention, ordinary technicians in this field can also make substitutions or modifications without departing from the scope of protection of the claims of the present invention, which all fall within the scope of protection of the present invention. The scope of protection requested for the present invention shall be based on the attached claims.
Claims
1. A method for extracting triples from natural language text based on attention mechanism, It is characterized in that The following steps are involved: Step 1: Dual-pass encode the input; Assume the input is W = {w 1 ,w 2 ,…,w n }, where w i is the word embedding of the i-th word; Perform dual-path encoding on the input, including aspect path and opinion path; For the aspect path, the input W is processed by a two-layer bidirectional long short-term memory network to obtain the preliminary encoding of the aspect path fa' = {fa′ 1 ,fa' 2 ,…,fa' n }, where fa′ i is the result of two-layer BiLSTM processing corresponding to the i-th word; For the opinion path, the input W is first processed by a graph convolutional network, where the adjacency matrix of the graph convolutional network is determined by the dependency analysis tree of the input sentence. This step obtains the text structure information required for the opinion information extraction process. Next, the result obtained by the graph convolution is processed by BiLSTM and CRF in turn to obtain the encoding result f of the opinion encoding path. p ; Step 2: Process the result of dual-path encoding using a bidirectional attention mechanism; The result of the two-way encoding is processed by a two-way attention mechanism, and the information extracted from the aspect path and the information extracted from the opinion path are processed by a two-way attention mechanism. After processing, the two-way information of the aspect path and the opinion path is recorded as h a 、h p ; The specific implementation of step 2 includes the following sub-steps: Step 2.1: Get the multi-head attention tensor α a→p ; Among them, G a , G p are all (k, 2d, 2d) three-dimensional tensors, randomly initialized and participate in the training process; f a 、f p They are the encoding of the aspect path and the encoding of the opinion path, and their dimensions are both (n, 2d), where n is the length of the sentence and 2d is the dimension of the aspect encoding vector and the opinion encoding vector; as shown in the formula, we get a vector with dimension k i, j∈(1,n); α ij is an element of the set α; Step 2.2: Convert the attention tensor α a→p Calculated as the correlation matrix A a→p ; Among them, v is a randomly initialized k-dimensional vector that participates in the training process. The purpose is to weight and aggregate the information generated by multiple attention heads; Step 2.3: Get the correlation matrix A p→a : A p→a =(A a→p ) T ; Step 2.4: Get the final code h a With h p ; h a =h a +softmax r (A a→p )h p ; h p =h p +softmax r (A p→a )h a ; Among them, softmax r To perform softmax operation on the rows of the matrix; Step 3: The loss function is calculated by combining the results of steps 1 and 2, and the stochastic gradient descent method is used to perform iterative training to reduce the value of the loss function and optimize the parameters involved in the training. Step 4: According to the parameters obtained after training, the correlation matrix obtained by the bidirectional attention mechanism is processed to obtain the triple result<aspect,opinion,sentiment> ; The triple result is obtained<aspect,opinion,sentiment> , the specific implementation process is: First, according to h a The aspect prediction label obtained by the softmax layer is used to obtain the BIOS label of the aspect with emotion. Parse the aspect-sentiment pair sequence aspect-pairs from it: <aspect 1 ,sentiment 1 >, <aspect 2 ,sentiment 2 >,…, <aspect m ,sentiment m >} Each aspect i The corresponding word sequence is words i : Where n i is the subscript sequence of the word group corresponding to the i-th aspect, |n i | indicates the length of the subscript sequence; Next, get the aspect i The corresponding anchor subscript of the opinion phrase: Where n is the number of words in the input sentence; Next in the sentence from the word Start and search left until you reach: Similarly, search rightward until: Among them, l is the subscript for searching words to the left, and r is the subscript for searching words to the right. The initial values of both are J. i ; λ is a parameter of preset value, which is a real number between 0 and 1; thus, the phrase between l and r is the opinion phrase corresponding to the i-th aspect-sentiment pair extracted in the above process.
2. The method for extracting triples of natural language text based on the attention mechanism according to claim 1, Features: In step 1, in order to ensure the consistency of the sentiment labels belonging to the same aspect, the sentiment consistency auxiliary task is used to optimize the encoding process; in order to ensure the quality of information extraction in the opinion encoding path, the opinion pre-labeling task is used to optimize the encoding process; First, fa′ is processed into fa″ considering sentiment consistency using the following formula: Among them, ☉ represents bitwise multiplication; g i is the gate vector for controlling sentiment consistency, W g is the weight matrix of the sentiment consistency module, b g is the bias vector of the emotion consistency module, σ() represents the nonlinear activation function; fa" is processed by the conditional random field to obtain the aspect path encoding result fa; Then f a Perform softmax processing to obtain a preliminary aspect prediction, and use the cross entropy function to calculate the loss aspect pre-label loss with the BIOS label of the actual aspect road label. Among them, each word is marked, and each word has four possible labels: B, I, O, and S, which are begin, inside, other, and single, respectively representing the beginning part of the keyword, the inside of the keyword, the outside of the keyword, and a single-word keyword.
3. The method for extracting triples of natural language text based on the attention mechanism according to claim 2, Features: In step 1, in order to ensure the quality of information extraction of opinion encoding path, the opinion pre-labeling task is used to optimize the encoding process; fp is processed by softmax to obtain a preliminary opinion prediction, and the loss of the opinion pre-labeling task is calculated using the cross entropy function with the BIOS label of the real opinion path.
4. The method for extracting triples of natural language text based on the attention mechanism according to claim 3, It is characterized in that The specific implementation of step 3 includes the following sub-steps: Step 3.1: Set h a Through the cross entropy loss of the softmax layer and the aspect's BIOS label with sentiment classification, we get Among them, each word is labeled, and each label is divided into two parts. The first part is BIOS. When the first part is B / I / S, the tail label exists and has three possibilities: NEG, POS, and NAT, which represent negative sentiment, positive sentiment, and neutral sentiment respectively; Step 3.2: h p Through the cross entropy loss of the softmax layer and the opinion BIOS label, we get Step 3.3: Construct the guidance matrix G a→p and G p→a ; G p→a =(G a→p ) T ; Step 3.4: Calculate the relevant loss function Loss A ; Loss A =||A a→p ☉G a→p ||=||A p→a ☉G p→a ||; Step 3.5: Add the five loss functions to get the final loss function LOSS in the training process; Step 3.6: Iteratively optimize the parameters involved in the training of the method with the goal of minimizing the value of the loss function LOSS.
5. A natural language text triple extraction system based on attention mechanism, It is characterized in that Including the following systems, Includes the following modules: Module 1, for two-way encoding of input; Assume the input is W = {w 1 ,w 2 ,…,w n }, where w i is the word embedding of the i-th word; Perform dual-path encoding on the input, including aspect path and opinion path; For the aspect path, the input W is processed by a two-layer bidirectional long short-term memory network to obtain the preliminary encoding of the aspect path fa' = {fa′ 1 ,fa' 2 ,…,fa' n }, where fa′ i is the result of two-layer BiLSTM processing corresponding to the i-th word; For the opinion path, the input W is first processed by a graph convolutional network, where the adjacency matrix of the graph convolutional network is determined by the dependency analysis tree of the input sentence. This step obtains the text structure information required for the opinion information extraction process. Next, the result obtained by the graph convolution is processed by BiLSTM and CRF in turn to obtain the encoding result f of the opinion encoding path. p ; Module 2 is used to process the results of dual-path encoding using a bidirectional attention mechanism; The result of the two-way encoding is processed by a two-way attention mechanism, and the information extracted from the aspect path and the information extracted from the opinion path are processed by a two-way attention mechanism. After processing, the two-way information of the aspect path and the opinion path is recorded as h a 、h p ; The specific implementation of module 2 includes the following submodules: Module 2.1, used to obtain the multi-head attention tensor α a→p ; Among them, G a , G p are all (k, 2d, 2d) three-dimensional tensors, randomly initialized and participate in the training process; f a 、f p They are the encoding of the aspect path and the encoding of the opinion path, and their dimensions are both (n, 2d), where n is the length of the sentence and 2d is the dimension of the aspect encoding vector and the opinion encoding vector; as shown in the formula, we get a vector with dimension k i, j∈(1,n); α ij is an element of the set α; Module 2.2 is used to convert the attention tensor α a→p Calculated as the correlation matrix A a→p ; Among them, v is a randomly initialized k-dimensional vector that participates in the training process. The purpose is to weight and aggregate the information generated by multiple attention heads; Module 2.3, used to obtain the correlation matrix A p→a : A p→a =(A a→p ) T ; Module 2.4 is used to obtain the final encoding h a With h p ; h a =h a +softmax r (A a→p )h p ; h p =h p +softmax r (A p→a )h a ; Among them, softmax r To perform softmax operation on the rows of the matrix; Module 3 is used to calculate the loss function by integrating the results of modules 1 and 2, and to perform iterative training using the stochastic gradient descent method to reduce the value of the loss function, thereby optimizing the parameters involved in the training. Module 4 is used to process the correlation matrix obtained by the bidirectional attention mechanism according to the parameters obtained after the training to obtain the triple result<aspect,opinion,sentiment> ; The triple result is obtained<aspect,opinion,sentiment> , the specific implementation process is: First, according to h a The aspect prediction label obtained by the softmax layer is used to obtain the BIOS label of the aspect with emotion. Parse the aspect-sentiment pair sequence aspect-pairs from it: <aspect 1 ,sentiment 1 >, <aspect 2 ,sentiment 2 >,…, <aspect m ,sentiment m >} Each aspect i The corresponding word sequence is words i : Where n i is the subscript sequence of the word group corresponding to the i-th aspect, |n i | indicates the length of the subscript sequence; Next, get the aspect i The corresponding anchor subscript of the opinion phrase: Where n is the number of words in the input sentence; Next in the sentence from the word Start and search left until you reach: Similarly, search rightward until: Among them, l is the subscript for searching words to the left, and r is the subscript for searching words to the right. The initial values of both are J. i ; λ is a parameter of preset value, which is a real number between 0 and 1; thus, the phrase between l and r is the opinion phrase corresponding to the i-th aspect-sentiment pair extracted in the above process.
