A specific target sentiment analysis method and device based on multi-level semantic coding
Through a multi-level semantic encoding method, using the transformer model and dependency syntax tree, combined with the graph attention mechanism, the problems of grammatical information loss and model instability in specific target sentiment classification are solved, and the accuracy and effect of sentiment classification are improved.
Patent Information
- Application Number
- CN202210851412.0
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2022-07-19
- Publication Date
- 2025-10-10
- Estimated Expiration
- 2042-07-19
AI Technical Summary
Existing specific target sentiment classification methods lose grammatical information when encoding text, and the attention mechanism and graph model have semantic overlap or instability problems, resulting in poor sentiment classification results.
A multi-level semantic encoding method is adopted, the transformer model is used for word vector encoding, and the dependency syntactic tree and graph attention mechanism are combined to enhance the recognition and feature representation of specific target emotional context through the syntactic attention component.
It improves the accuracy and effectiveness of specific target sentiment classification, solves the problems of grammatical information loss and model instability, and provides new ideas for natural language processing tasks.
Smart Images

Figure CN115221321B_ABST
Abstract
Description
Technical Field
[0001] The present application relates to the technical field of specific target sentiment analysis, and specifically to a specific target sentiment analysis method and device based on multi-level semantic coding. Background Art
[0002] Target-specific sentiment analysis, one of the most active research areas in natural language processing, aims to summarize and mine public opinion, sentiment, and attitudes toward entities such as products, services, or organizations, thereby enabling accurate decision-making for organizers or potential users. Target-specific sentiment analysis consists of three subtasks: target extraction, sentiment polarity extraction, and target-specific sentiment classification.
[0003] Currently, common target-specific sentiment classification methods include: 1) using RNNs, LSTMs, and their variants to model text semantics, relying on neural networks to learn the semantic relationship between the target and its context. However, this sequential encoding of contextual semantic features ignores the text's syntactic structure. Furthermore, due to its biased nature, the model often favors the representation of words at the end of the text. 2) Using attention mechanisms to strengthen the implicit association between a target and its sentiment context, extending the attention model to increase the attention contribution of the sentiment context to each target. However, due to the potential semantic overlap between the sentiment polarity contexts of multiple targets in a text, these methods struggle to capture and quantify the impact of the target's sentiment context using only the attention mechanism. 3) Introducing parse trees to model the text's structural information and leveraging graph theory to encode dependencies between phrases at different levels within the text. However, the tree construction process introduces additional noise and unstable long-range dependencies between tree nodes, posing new challenges to text semantic modeling.
[0004] In view of this, the present invention proposes an improved fine-grained specific target sentiment classification method, which can effectively perform specific target sentiment classification. Summary of the Invention
[0005] In order to solve the problem that existing specific target sentiment classification methods all encode text sequentially and then use attention mechanisms or graphs to associate specific targets and sentiment contexts, but sequential encoding often loses some grammatical information, and attention mechanisms and graphs also face problems such as semantic overlap or graph noise and instability, the present application provides a specific target sentiment analysis method and device based on multi-level semantic encoding to solve the above technical defects.
[0006] According to one aspect of the present invention, a specific target sentiment analysis method based on multi-level semantic coding is proposed, the method comprising the following steps:
[0007] The embodiment of the application provides a specific target sentiment analysis method based on multi-level semantic coding, comprising the following steps:
[0008] S1, obtaining a text to be analyzed, and performing word segmentation on the text to be analyzed;
[0009] S2, using a syntax analysis tool to analyze the word segmentation result, generating a dependency syntax tree, and constructing a syntax cover matrix according to the dependency syntax tree;
[0010] S3, converting the word segmentation result of the text to be analyzed into a word vector two-dimensional matrix, using a transformer model to code the word vector two-dimensional matrix, and obtaining shallow semantic features of the text to be analyzed;
[0011] S4, inputting the syntax cover matrix and the shallow semantic features into a syntax attention network to obtain deep semantic features; and
[0012] S5, calculating a specific target text representation vector according to the deep semantic features, and finally obtaining a specific target sentiment classification.
[0013] Through the above technical solution, the recognition and feature representation of the model on the specific target sentiment context can be strengthened, and the effect of the specific target sentiment classification task can be improved.
[0014] In specific embodiments, in step S2, the word segmentation result is analyzed using a syntax analysis tool to generate a dependency syntax tree, and a syntax cover matrix is constructed according to the dependency syntax tree, specifically comprising:
[0015] S21, using a syntax analysis tool to analyze the syntax structure of the text to be analyzed, and constructing a dependency syntax tree according to the word segmentation result of step S1;
[0016] S22, abstracting the dependency syntax tree into an undirected graph G = <V, E>, V is a set of all nodes, E is a set of all edges, and an edge in the undirected graph represents whether there is a syntax association between two nodes;
[0017] S23, representing the undirected graph as a syntax cover matrix M syn , and the elements in the syntax cover matrix M syn are represented as:
[0018]
[0019] Wherein, e ij = 1 represents that there is a syntax association between the node v i and the node v j , and m ij represents an element in the syntax cover matrix M syn .
[0020] In specific embodiments, in step S3, the word segmentation result of the text to be analyzed is converted into a word vector two-dimensional matrix, including: converting each word in the text to be analyzed into a fixed-length dense vector through a word vector model.
[0021] Through the above scheme, the vectorization of the text can be realized.
[0022] In specific embodiments, in step S3, the transformer model is used to encode the word vector two-dimensional matrix to obtain the shallow semantic features of the text to be analyzed, including:
[0023] S31, obtaining a key matrix K, a query matrix Q and a value matrix V of the word vector two-dimensional matrix through linear transformation;
[0024] S32, calculating the key matrix K, the query matrix Q and the value matrix V using a multi-head attention layer and a feedforward network layer to obtain first semantic features; using residual and normalization operations between the multi-head attention layer and the feedforward network layer to constrain the distribution of the first semantic features to obtain the shallow semantic features of the text to be analyzed:
[0025]
[0026]
[0027] wherein A s is the first semantic feature matrix, K T is the transpose matrix of the key matrix K, d k is the length of the feature vector after linear transformation, represents the feature representation obtained by the i-th self-attention head, H is the shallow semantic feature matrix, m is the number of self-attention heads, W s is the weight to be learned by the model, and || represents the splicing operation;
[0028] S33, repeating steps S31 and S32 until the encoding of the word vector two-dimensional matrix is completed.
[0029] In specific embodiments, in step S4, the syntax masking matrix and the shallow semantic features are input into a syntax attention network to obtain deep semantic features, including:
[0030] S41, calculating the scores between all nodes in the dependency syntax tree two by two, the scores representing the original attention weights between the nodes:
[0031]
[0032] wherein u ij represents the original attention weight between the nodes, h i and h jRepresent the feature vectors of node i and node j respectively, and W u These are weights that need to be learned during model training;
[0033] S42. Determine the neighborhood of the node in the dependency syntax tree according to the syntax cover matrix obtained in step S2, calculate the attention weight of the neighboring nodes of any node to the node, and encode the syntax cover matrix and shallow semantic features:
[0034] A g =graphatt(U,H,M syn )=softmax(U+M syn )W u H s
[0035] Among them, A g is the second semantic feature matrix, U is the original attention weight matrix between all nodes in the undirected graph, u ij ∈U,M syn is the syntactic cover matrix, W u is the weight that needs to be learned during model training, H s is the shallow semantic feature obtained in step S3;
[0036] S43. Use the feedforward network layer to strengthen the unique representation of the node itself, and use residual and normalization operations to constrain the distribution of the second semantic feature matrix:
[0037]
[0038] Among them, H is the deep semantic feature matrix, W g is the weight parameter that needs to be learned during model training, n is the number of self-attention heads, Represents the feature representation obtained by the i-th self-attention head.
[0039] In a specific embodiment, in step S5, a text representation vector of a specific target is calculated based on deep semantic features, and finally a sentiment classification of the specific target is obtained, including:
[0040] S51. Locating a specific target word in the word segmentation results of the text to be analyzed;
[0041] S52. According to the position of the specific target word, a target mask vector of the same length as the word segmentation array is constructed.
[0042] S53, according to the target cover vector And deep semantic features calculate the text representation vector of a specific target:
[0043]
[0044] Among them, H g It is the deep semantic feature obtained in step S4.
[0045] By connecting the text representation vector obtained in step S53 to the classification layer, it can be used for a specific target sentiment classification task.
[0046] In a second aspect, the present application provides a specific target sentiment analysis device based on multi-level semantic coding, the device comprising:
[0047] The word segmentation module obtains the text to be analyzed and performs word segmentation on the text to be analyzed;
[0048] The parsing module uses the syntactic parsing tool to parse the word segmentation results, generate a dependency syntactic tree, and construct a syntactic cover matrix based on the dependency syntactic tree;
[0049] The shallow semantic feature acquisition module converts the word segmentation results of the text to be analyzed into a two-dimensional word vector matrix, encodes the two-dimensional word vector matrix using the transformer model, and obtains the shallow semantic features of the text to be analyzed; and
[0050] The deep semantic feature acquisition module inputs the syntactic mask matrix and shallow semantic features into the syntactic attention network to obtain deep semantic features; and
[0051] The sentiment classification module calculates the text representation vector of a specific target based on deep semantic features and ultimately obtains the sentiment classification of the specific target.
[0052] In a specific embodiment, the parsing module includes:
[0053] Build a dependency syntax tree module, use the syntax parsing tool to parse the syntactic structure of the text to be analyzed, and build a dependency syntax tree based on the word segmentation results in the parsing module;
[0054] Undirected graph conversion module, abstracts the dependency syntax tree into an undirected graph G=<V,E> , V is the set of all nodes, E is the set of all edges, and the edges in an undirected graph indicate whether there is a syntactic association between any two nodes;
[0055] Undirected graph representation module, which represents the undirected graph as a syntactic cover matrix M syn The form of syntactic cover matrix M syn The elements in are represented as:
[0056]
[0057] Among them, e ij =1 indicates node v i With node v jThere is a syntactic relationship between ij Represents the syntactic cover matrix M syn An element in .
[0058] In a specific embodiment, the deep semantic feature acquisition module includes:
[0059] The original attention weight calculation module calculates the scores between all nodes in the dependency syntax tree. The scores represent the original attention weights between the nodes:
[0060]
[0061] Among them, u ij represents the original attention weight between nodes, h i and h j Represent the feature vectors of node i and node j respectively, and W u These are weights that need to be learned during model training;
[0062] The second semantic feature matrix acquisition module determines the neighborhood of nodes in the dependency syntax tree based on the syntactic cover matrix obtained by the shallow semantic feature acquisition module, calculates the attention weight of any node's neighboring nodes to the node, and encodes the syntactic cover matrix and shallow semantic features:
[0063] A g =graphatt(U,H,M syn )=softmax(U+M syn )W u H s
[0064] Among them, A g is the second semantic feature matrix, U is the original attention weight matrix between all nodes in the undirected graph, u ij ∈U,M syn is the syntactic cover matrix, W u is the weight that needs to be learned during model training, H s is the shallow semantic feature obtained in step S3;
[0065] The constraint module uses the feedforward network layer to strengthen the unique representation of the node itself, and uses residual and normalization operations to constrain the distribution of the second semantic feature matrix:
[0066]
[0067] Among them, H is the deep semantic feature matrix, W g is the weight parameter that needs to be learned during model training, n is the number of self-attention heads, Represents the feature representation obtained by the i-th self-attention head.
[0068] In a third aspect, the present application provides a computer-readable storage medium, in which a computer program is stored. When the computer program is executed by a processor, any of the above methods is implemented.
[0069] Compared with the prior art, the present invention has the following advantages:
[0070] This paper proposes an improved fine-grained specific target sentiment classification method. First, the transformer model is used to encode the word vectors of the text. Secondly, a dependency syntax tree is introduced to explicitly represent the abstract syntactic structure of the text, and a graph attention mechanism is used to capture the grammatical associations between words. Finally, through the syntactic attention component, the model's recognition and feature representation of specific target sentiment context are enhanced, thereby improving the effect of specific target sentiment classification tasks. BRIEF DESCRIPTION OF THE DRAWINGS
[0071] Other features, objects and advantages of the present application will become more apparent from the detailed description of non-limiting embodiments made with reference to the following drawings:
[0072] Figure 1 is a flowchart of a specific target sentiment analysis method based on multi-level semantic coding according to the present application;
[0073] Figure 2 Schematic diagram of the main framework of the specific target sentiment analysis method based on multi-level semantic coding according to the present application;
[0074] Figure 3 is a schematic diagram of a dependency syntax tree according to an embodiment of the present application;
[0075] Figure 4 is a schematic diagram of a specific target sentiment analysis device based on multi-level semantic coding according to the present application;
[0076] Figure 5 It is a structural diagram of a computer system suitable for implementing the electronic device of the embodiment of the present application. DETAILED DESCRIPTION
[0077] The present application will be further described in detail below with reference to the accompanying drawings and examples. It should be understood that the specific embodiments described herein are merely for the purpose of explaining the relevant invention and are not intended to limit the invention. It should also be noted that, for ease of description, only portions relevant to the relevant invention are shown in the accompanying drawings.
[0078] It should be noted that, in the absence of conflict, the embodiments and features of the embodiments in this application can be combined with each other. The present application will be described in detail below with reference to the accompanying drawings and in combination with the embodiments.
[0079] Figure 1 A flowchart of the specific target sentiment analysis method based on multi-level semantic coding of the present application is shown; Figure 2 The main framework diagram of the specific target sentiment analysis method based on multi-level semantic coding according to the present application is shown. Figure 1 and Figure 2 , the method comprises the following steps:
[0080] S1. Obtain the text to be analyzed and perform word segmentation on the text to be analyzed.
[0081] In this embodiment, the word segmentation results are stored in the form of an array, which is formally described as W = {w1, w2, ···, w n}, where n is the length of the array.
[0082] S2. Use a syntactic parsing tool to parse the word segmentation results, generate a dependency syntactic tree, and construct a syntactic covering matrix based on the dependency syntactic tree.
[0083] In this embodiment, the following sub-steps are specifically included:
[0084] S21. Use a syntactic parsing tool to parse the syntactic structure of the text to be analyzed, and construct a dependency syntactic tree based on the word segmentation result of step S1. Figure 3 A schematic diagram of a dependency syntax tree according to an embodiment of the present application is shown, please refer to it.
[0085] S22. Abstract the dependency syntax tree into an undirected graph G =<V,E> , V is the set of all nodes, E is the set of all edges, and the edges in an undirected graph represent whether there is a syntactic relationship between any two nodes. It should be understood that each node in an undirected graph corresponds to a word in the text.
[0086] S23. Represent the undirected graph as a syntactic cover matrix M syn The form of syntactic cover matrix M syn The elements in are represented as:
[0087]
[0088] Among them, e ij =1 indicates node v i With node v j There is a syntactic relationship between ij Represents the syntactic cover matrix M syn An element in .
[0089] S3. Convert the word segmentation results of the text to be analyzed into a two-dimensional word vector matrix, use the transformer model to encode the two-dimensional word vector matrix, and obtain the shallow semantic features of the text to be analyzed.
[0090] Among them, the word segmentation results of the text to be analyzed are converted into a two-dimensional matrix of word vectors. This step requires pre-training a word vector model. Through the word vector model, each word in the text to be analyzed can be converted into a dense vector of a fixed length to achieve text vectorization. The word vector of the text to be analyzed can be abstracted as where d w is the length of the word vector.
[0091] In this embodiment, the following sub-steps are specifically included:
[0092] S31, obtain the key matrix K, query matrix Q, and value matrix V of the word vector two-dimensional matrix through linear transformation; wherein the initial two-dimensional feature matrix is the word vector X of the text to be analyzed obtained in step S3;
[0093] S32. Use the multi-head attention layer and the feedforward network layer to calculate the key matrix K, the query matrix Q, and the value matrix V to obtain the first semantic feature; wherein the calculation process is the process of extracting the low-level semantic features of the text to be analyzed.
[0094] The residual and normalization operations are used between the multi-head attention layer and the feedforward network layer to constrain the distribution of the first semantic feature and obtain the shallow semantic features of the text to be analyzed. The process can be abstracted as follows:
[0095]
[0096]
[0097] Among them, A s is the first semantic feature matrix, K T is the transposed matrix of the key matrix K, d k is the length of the eigenvector after linear transformation, represents the feature representation obtained by the i-th self-attention head, H is the shallow semantic feature matrix, m is the number of self-attention heads, and W s is the weight that the model needs to learn, || represents the splicing operation;
[0098] S33. Repeat steps S31 and S32 until the encoding of the word vector two-dimensional matrix is completed.
[0099] S4. Input the syntactic masking matrix and shallow semantic features into the syntactic attention network to obtain deep semantic features.
[0100] In this embodiment, the following sub-steps are specifically included:
[0101] S41. Calculate the scores between all nodes in the dependency syntax tree respectively. The scores represent the original attention weights between the nodes:
[0102]
[0103] Among them, u ij represents the original attention weight between nodes, h i and h j Represent the feature vectors of node i and node j respectively, and W u These are weights that need to be learned during model training;
[0104] S42. Determine the neighborhood of the node in the dependency syntax tree according to the syntax cover matrix obtained in step S2, calculate the attention weight of the neighboring nodes of any node to the node, and encode the syntax cover matrix and shallow semantic features:
[0105] A g =graphatt(U,H,M syn )=softmax(U+M syn )W u H s
[0106] Among them, A g is the second semantic feature matrix, U is the original attention weight matrix between all nodes in the undirected graph, u ij ∈U,M syn is the syntactic cover matrix, W u is the weight that needs to be learned during model training, H s is the shallow semantic feature obtained in step S3;
[0107] S43. Use the feedforward network layer to strengthen the unique representation of the node itself, and use residual and normalization operations to constrain the distribution of the second semantic feature matrix:
[0108]
[0109] Among them, H is the deep semantic feature matrix, W g is the weight parameter that needs to be learned during model training, n is the number of self-attention heads, Represents the feature representation obtained by the i-th self-attention head.
[0110] S5. Calculate the text representation vector of the specific target based on the deep semantic features, and finally obtain the sentiment classification of the specific target.
[0111] In this embodiment, the following sub-steps are specifically included:
[0112] S51. According to the characteristics of the specific target sentiment classification task, locate the specific target word in the word segmentation results of the text to be analyzed; its formal description is T = {t1, t2, ···, t k}, where k is the length of a specific target word, k∈[1,n];
[0113] S52. According to the position of the specific target word, a target mask vector of the same length as the word segmentation array is constructed. The position of the specific target word is the subscript of the specific target word in the word segmentation array, the element at the subscript is set to 1, and the elements at other positions are set to 0;
[0114] S53, according to the target cover vector And deep semantic features calculate the text representation vector of a specific target:
[0115]
[0116] Among them, H g It is the deep semantic feature obtained in step S4.
[0117] By connecting the text representation vector obtained in step S53 to the classification layer, it can be used for a specific target sentiment classification task.
[0118] The current mainstream specific target sentiment classification methods all encode the text sequentially, and then use attention mechanisms or graphs to associate specific targets and sentiment contexts. However, sequential encoding often loses some grammatical information, and attention mechanisms and graphs also face problems such as semantic overlap or graph noise and instability. In response to the above situation, the present invention proposes a specific target sentiment analysis method based on multi-level semantic encoding. The method is implemented through a multi-layer syntactic attention model. The model uses transformer as a shallow feature extractor. On this basis, a graph attention mechanism is introduced to parse the dependency syntax tree, and the parsing network is integrated into the transformer framework to construct a new component to enhance the model's ability to represent deep semantics. The model proposed in the present invention is effective in specific target sentiment classification tasks. At the same time, the scalability of the syntactic attention component also provides new ideas for other tasks in the field of natural language processing.
[0119] Further references Figure 4 As an implementation of the above method, this application provides an embodiment of a device for specific target sentiment analysis based on multi-level semantic coding. This device embodiment corresponds to the method embodiment shown in Figure 1. The system can be specifically applied to various electronic devices. The device 200 includes the following modules:
[0120] The word segmentation module 210 obtains the text to be analyzed and performs word segmentation on the text to be analyzed;
[0121] The parsing module 220 uses a syntactic parsing tool to parse the word segmentation results, generate a dependency syntactic tree, and construct a syntactic cover matrix based on the dependency syntactic tree;
[0122] A shallow semantic feature acquisition module 230 converts the word segmentation results of the text to be analyzed into a two-dimensional word vector matrix, encodes the two-dimensional word vector matrix using a transformer model, and obtains shallow semantic features of the text to be analyzed; and
[0123] A deep semantic feature acquisition module 240 inputs the syntactic cover matrix and shallow semantic features into a syntactic attention network to acquire deep semantic features; and
[0124] The sentiment classification module 250 calculates the text representation vector of the specific target based on the deep semantic features, and finally obtains the sentiment classification of the specific target.
[0125] In a specific embodiment, the parsing module 220 includes:
[0126] A dependency syntax tree construction module 221 uses a syntax parsing tool to parse the syntax structure of the text to be analyzed, and constructs a dependency syntax tree based on the word segmentation results in the parsing module;
[0127] Undirected graph conversion module 222, abstracts the dependency syntax tree into an undirected graph G=<V,E> , V is the set of all nodes, E is the set of all edges, and the edges in an undirected graph indicate whether there is a syntactic association between any two nodes;
[0128] Undirected graph representation module 223, represents the undirected graph as a syntactic cover matrix M syn The form of syntactic cover matrix M syn The elements in are represented as:
[0129]
[0130] Among them, e ij =1 indicates node v i With node v j There is a syntactic relationship between ij Represents the syntactic cover matrix M syn An element in .
[0131] In a specific embodiment, the deep semantic feature acquisition module 240 includes:
[0132] The original attention weight calculation module 241 calculates the scores between all nodes in the dependency syntax tree respectively. The scores represent the original attention weights between the nodes:
[0133]
[0134] Among them, u ij represents the original attention weight between nodes, h i and h j Represent the feature vectors of node i and node j respectively, and W u These are weights that need to be learned during model training;
[0135] The second semantic feature matrix acquisition module 242 determines the neighborhood of the nodes in the dependency syntax tree based on the syntactic cover matrix obtained by the shallow semantic feature acquisition module, calculates the attention weight of the neighboring nodes of any node to the node, and encodes the syntactic cover matrix and shallow semantic features:
[0136] A g =graphatt(U,H,M syn )=softmax(U+M syn )W u H s
[0137] Among them, A g is the second semantic feature matrix, U is the original attention weight matrix between all nodes in the undirected graph, u ij ∈U,M syn is the syntactic cover matrix, W u is the weight that needs to be learned during model training, H s is the shallow semantic feature obtained in step S3;
[0138] The constraint module 243 uses a feedforward network layer to strengthen the unique representation of the node itself, and uses residual and normalization operations to constrain the distribution of the second semantic feature matrix:
[0139]
[0140] Among them, H is the deep semantic feature matrix, W g is the weight parameter that needs to be learned during model training, n is the number of self-attention heads, Represents the feature representation obtained by the i-th self-attention head.
[0141] The present application also provides a computer-readable storage medium having a computer program stored thereon. When the computer program is executed by a processor, it implements any of the above methods.
[0142] like Figure 5As shown, the computer system 500 includes a central processing unit (CPU) 501, which can perform various appropriate actions and processes according to a program stored in a read-only memory (ROM) 502 or a program loaded from a storage unit 508 into a random access memory (RAM) 503. Various programs and data required for the operation of the system 500 are also stored in the RAM 503. The CPU 501, ROM 502, and RAM 503 are connected to each other via a bus 504. An input / output (I / O) interface 505 is also connected to the bus 504.
[0143] The following components are connected to the I / O interface 505: an input section 506 including a keyboard, a mouse, and the like; an output section 507 including a liquid crystal display (LCD), a speaker, and the like; a storage section 508 including a hard disk and the like; and a communication section 509 including a network interface card such as a LAN card or a modem. The communication section 509 performs communication processing via a network such as the Internet. A drive 510 is also connected to the I / O interface 505 as needed. A removable medium 511, such as a magnetic disk, an optical disk, a magneto-optical disk, or a semiconductor memory, is installed in the drive 510 as needed, so that a computer program read therefrom can be installed in the storage section 508 as needed.
[0144] In particular, the processes described above with reference to the flowcharts can be implemented as a computer software program according to embodiments of the present disclosure. For example, embodiments of the present disclosure include a computer program product comprising a computer program carried on a computer readable medium, the computer program comprising program code for performing the methods illustrated by the flowcharts. In such embodiments, the computer program can be downloaded and installed from a network via the communication section 509, and / or installed from the removable medium 511. When the computer program is executed by the central processing unit (CPU) 501, the above-described functions defined in the methods of the present application are performed. It should be noted that the computer readable medium described in the present application can be a computer readable signal medium or a computer readable storage medium or any combination of the two. The computer readable medium may, for example, be but is not limited to an electronic, magnetic, optical, electromagnetic, infrared, or semiconductor system, apparatus or device, or any suitable combination of the above. More specific examples of the computer readable medium can include, but are not limited to, an electrical connection having one or more wires, a portable computer diskette, a hard disk, a random access memory (RAM), a read-only memory (ROM), an erasable programmable read-only memory (EPROM or flash memory), an optical fiber, a portable compact disc read-only memory (CD-ROM), an optical storage device, a magnetic storage device, or any suitable combination of the above. In the present application, the computer readable medium can be any tangible medium that contains or stores a program that can be used by or in connection with an instruction execution system, apparatus or device. In the present application, the computer readable signal medium can include a data signal carried in a baseband or as part of a carrier wave, in which the computer readable program code is carried. Such a propagated data signal can take a variety of forms, including but not limited to an electromagnetic signal, an optical signal or any suitable combination of the above. The computer readable signal medium can also be any computer readable medium that can send, propagate or transfer the program for use by or in connection with an instruction execution system, apparatus or device. The program code contained on the computer readable medium can be transmitted by any suitable medium, including but not limited to wireless, wire, optical cable, RF or the like, or any suitable combination of the above.
[0145] Computer program code for performing the operations of the present application can be written in one or more programming languages, or a combination thereof, including object-oriented programming languages such as Java, Smalltalk, C++, and conventional procedural programming languages such as "C" or similar programming languages. The program code can be executed entirely on the user's computer, partially on the user's computer, as a stand-alone software package, partially on the user's computer and partially on a remote computer, or entirely on a remote computer or server. In cases involving a remote computer, the remote computer can be connected to the user's computer through any type of network, including a local area network (LAN) or a wide area network (WAN), or can be connected to an external computer (e.g., through the Internet using an Internet service provider).
[0146] The flow charts and block diagrams in the accompanying drawings illustrate the possible architecture, functions and operations of the systems, methods and computer program products according to various embodiments of the present application. In this regard, each box in the flow chart or block diagram can represent a module, program segment or a part of code, and the module, program segment or a part of code contains one or more executable instructions for realizing the specified logical function. It should also be noted that in some alternative implementations, the functions marked in the box can also occur in a different order than that marked in the accompanying drawings. For example, two boxes represented in succession can actually be executed substantially in parallel, and they can sometimes be executed in the opposite order, depending on the functions involved. It should also be noted that each box in the block diagram and / or flow chart, and the combination of the boxes in the block diagram and / or flow chart can be implemented by a dedicated hardware-based system that performs the specified function or operation, or can be implemented by a combination of dedicated hardware and computer instructions.
[0147] The modules described in the embodiments of this application may be implemented in software or hardware. The modules described may also be provided in a processor. For example, a processor may be described as including an acquisition module, an analysis module, and an output module. The names of these modules do not, in some cases, limit the modules themselves.
[0148] The above description is merely a preferred embodiment of the present application and an illustration of the technical principles employed. Those skilled in the art should understand that the scope of the invention involved in this application is not limited to the technical solutions formed by the specific combination of the above-mentioned technical features, but also encompasses other technical solutions formed by any combination of the above-mentioned technical features or their equivalents without departing from the above-mentioned inventive concept. For example, a technical solution formed by replacing the above-mentioned features with (but not limited to) technical features with similar functions disclosed in this application.
Claims
1. A specific target sentiment analysis method based on multi-level semantic coding, characterized in that: The following steps are involved: S1. Obtain a text to be analyzed and perform word segmentation on the text to be analyzed; S2. Parsing the word segmentation result using a syntax parsing tool to generate a dependency syntax tree, and constructing a syntax cover matrix based on the dependency syntax tree; S3. Convert the word segmentation result of the text to be analyzed into a two-dimensional word vector matrix, encode the two-dimensional word vector matrix using a transformer model, and obtain shallow semantic features of the text to be analyzed; S4: Inputting the syntactic cover matrix and the shallow semantic features into the syntactic attention network to obtain deep semantic features, specifically including the following sub-steps: S41. Calculate the scores between all nodes in the dependency syntax tree respectively, where the scores represent the original attention weights between the nodes: Among them, u ij represents the original attention weight between nodes, h i and h j Represent the feature vectors of node i and node j respectively, and W u These are weights that need to be learned during model training; S42. Determine the neighborhood of the node in the dependency syntax tree according to the syntax cover matrix obtained in step S2, calculate the attention weight of the neighboring nodes of any node to the node, and encode the syntax cover matrix and the shallow semantic features: A g =graphatt(U,H,M syn )=softmax(U+M syn )W u H s Among them, A g is the second semantic feature matrix, U is the original attention weight matrix between all nodes in the undirected graph, u ij ∈U,M syn is the syntactic cover matrix, W u is the weight that needs to be learned during model training, H s is the shallow semantic feature obtained in step S3; S43: Use a feedforward network layer to strengthen the unique representation of the node itself, and use residual and normalization operations to constrain the distribution of the second semantic feature matrix: Among them, H is the deep semantic feature matrix, W g is the weight parameter that needs to be learned during model training, n is the number of self-attention heads, represents the feature representation obtained by the i-th self-attention head; and S5. Calculate the text representation vector of the specific target based on the deep semantic features, and finally obtain the sentiment classification of the specific target.
2. The specific target sentiment analysis method based on multi-level semantic coding according to claim 1 is characterized in that In step S2, a syntactic parsing tool is used to parse the word segmentation results to generate a dependency syntactic tree, and a syntactic cover matrix is constructed based on the dependency syntactic tree, which includes the following sub-steps: S21, using the syntactic parsing tool to parse the syntactic structure of the text to be analyzed, and constructing a dependency syntax tree based on the word segmentation result of step S1; S22, abstracting the dependency syntax tree into an undirected graph G=<V,E> , V is the set of all nodes, E is the set of all edges, and the edges in the undirected graph indicate whether there is a syntactic association between any two nodes; S23, representing the undirected graph as a syntactic cover matrix M syn The syntax covers the matrix M in the form of syn The elements in are represented as: Among them, e ij =1 indicates node v i With node v j There is a syntactic relationship between ij Represents the syntactic cover matrix M syn An element in .
3. The specific target sentiment analysis method based on multi-level semantic coding according to claim 1 is characterized in that In step S3, the word segmentation result of the text to be analyzed is converted into a two-dimensional matrix of word vectors, including: converting each word in the text to be analyzed into a dense vector of fixed length through a word vector model.
4. The specific target sentiment analysis method based on multi-level semantic coding according to claim 1 is characterized in that In step S3, the transformer model is used to encode the word vector two-dimensional matrix to obtain the shallow semantic features of the text to be analyzed, including the following sub-steps: S31, obtaining the key matrix K, query matrix Q, and value matrix V of the word vector two-dimensional matrix through linear transformation; S32. Use a multi-head attention layer and a feedforward network layer to calculate the key matrix K, the query matrix Q, and the value matrix V to obtain a first semantic feature; use residual and normalization operations between the multi-head attention layer and the feedforward network layer to constrain the distribution of the first semantic feature to obtain the shallow semantic feature of the text to be analyzed: Among them, A s is the first semantic feature matrix, K T is the transposed matrix of the key matrix K, d k is the length of the eigenvector after linear transformation, represents the feature representation obtained by the i-th self-attention head, H is the shallow semantic feature matrix, m is the number of self-attention heads, and W s is the weight that the model needs to learn, || represents the splicing operation; S33. Repeat steps S31 and S32 until the encoding of the word vector two-dimensional matrix is completed.
5. The specific target sentiment analysis method based on multi-level semantic coding according to claim 1 is characterized in that In step S5, a text representation vector of a specific target is calculated based on the deep semantic features, and finally a sentiment classification of the specific target is obtained, which includes the following sub-steps: S51, locating a specific target word in the word segmentation results of the text to be analyzed; S52: Construct a target cover vector of the same length as the word segmentation array according to the position of the specific target word. S53, according to the target covering vector And the deep semantic features are used to calculate the text representation vector of the specific target: Among them, H g It is the deep semantic feature obtained in step S4.
6. A specific target sentiment analysis device based on multi-level semantic coding, characterized in that: The device comprises: A word segmentation module, which obtains the text to be analyzed and performs word segmentation on the text to be analyzed; A parsing module, which uses a syntactic parsing tool to parse the word segmentation results, generate a dependency syntactic tree, and construct a syntactic cover matrix based on the dependency syntactic tree; A shallow semantic feature acquisition module converts the word segmentation results of the text to be analyzed into a two-dimensional word vector matrix, encodes the two-dimensional word vector matrix using a transformer model, and obtains shallow semantic features of the text to be analyzed; and The deep semantic feature acquisition module inputs the syntactic cover matrix and the shallow semantic features into the syntactic attention network to obtain deep semantic features, specifically including: The original attention weight calculation module calculates the scores between all nodes in the dependency syntax tree respectively. The scores represent the original attention weights between the nodes: Among them, u ij represents the original attention weight between nodes, h i and h j Represent the feature vectors of node I and node j respectively, and W u These are weights that need to be learned during model training; The second semantic feature matrix acquisition module determines the neighborhood of the node in the dependency syntax tree according to the syntactic cover matrix obtained by the shallow semantic feature acquisition module, calculates the attention weight of the neighboring nodes of any node to the node, and encodes the syntactic cover matrix and the shallow semantic features: A g =graphatt(U,H,M syn )=softmax(U+M syn )W u H s Among them, A g is the second semantic feature matrix, U is the original attention weight matrix between all nodes in the undirected graph, u ij ∈U,M syn is the syntactic cover matrix, W u is the weight that needs to be learned during model training, H s is the shallow semantic feature obtained in step S3; The constraint module uses a feedforward network layer to strengthen the unique representation of the node itself and uses residual and normalization operations to constrain the distribution of the second semantic feature matrix: Among them, H is the deep semantic feature matrix, W g is the weight parameter that needs to be learned during model training, n is the number of self-attention heads, represents the feature representation obtained by the i-th self-attention head; and The sentiment classification module calculates the text representation vector of a specific target based on the deep semantic features, and finally obtains the sentiment classification of the specific target.
7. The specific target sentiment analysis device based on multi-level semantic coding according to claim 6 is characterized in that The parsing module includes: Constructing a dependency syntax tree module, using the syntax parsing tool to parse the syntax structure of the text to be analyzed, and constructing a dependency syntax tree based on the word segmentation results in the parsing module; Undirected graph conversion module, abstracting the dependency syntax tree into an undirected graph G=<V,E> , V is the set of all nodes, E is the set of all edges, and the edges in the undirected graph indicate whether there is a syntactic association between any two nodes; Undirected graph representation module, which represents the undirected graph as a syntactic cover matrix M syn The syntax covers the matrix M in the form of syn The elements in are represented as: Among them, e ij =1 indicates node v i With node v j There is a syntactic relationship between ij Represents the syntactic cover matrix M syn An element in .
8. A computer-readable storage medium, wherein a computer program is stored in the medium, and when the computer program is executed by a processor, the method according to any one of claims 1 to 5 is implemented.
Citation Information
Patent Citations
Part-of-speech and self-attention mechanism fused sentiment tendency classification method and system
CN110569508A
Text named entity information identification method based on syntactic guidance
CN112989796A