A text sentiment classification method and device
By extracting the character semantics and syntactic structure information in the text, the problem of inaccurate text sentiment classification in the existing technology is solved, and more accurate sentiment category determination is achieved.
Patent Information
- Application Number
- CN202211053227.3
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2022-08-31
- Publication Date
- 2025-09-12
- Estimated Expiration
- 2042-08-31
AI Technical Summary
Existing technologies have difficulty in accurately classifying the emotional categories expressed in text, especially in the absence of sufficient syntactic structure information, resulting in inaccurate classification results.
By extracting the character semantic information and syntactic structure information of each character in the text to be classified and combining it with the preset emotion category, the emotion category expressed by the text is determined.
The accuracy of text sentiment classification is improved by comprehensively considering character semantics and syntactic structure, reducing ambiguity and providing more accurate classification results.
Smart Images

Figure CN115309904B_ABST
Abstract
Description
Technical Field
[0001] The present invention relates to the field of data processing technology, and in particular to a text sentiment classification method and device. Background Art
[0002] In social networks, it is often necessary to determine the emotional category of the emotions expressed in the text posted by users. For example, for a product on the market, a user will comment on the product. The above comments are in text format. In order to determine whether the user is satisfied with the product from the above comments, the emotional category of the emotion expressed in the comment posted by the user can be determined. If the emotional category corresponding to the comment is a positive category, it can be considered that the user is relatively satisfied with the product. If the emotional category corresponding to the comment is a negative category, it can be considered that the user is dissatisfied with the product.
[0003] Therefore, in order to determine the sentiment category of the sentiment expressed in the text, it is necessary to provide a text sentiment classification method. Summary of the Invention
[0004] The purpose of the embodiments of the present invention is to provide a method and apparatus for text sentiment classification, so as to classify the sentiment categories of the sentiment expressed in the text. The specific technical solution is as follows:
[0005] In a first aspect, an embodiment of the present invention provides a text sentiment classification method, the method comprising:
[0006] For each character in the text to be classified, extracting character semantic information representing the semantics of the character according to the character and the position of the character in the text to be classified;
[0007] Acquiring syntactic structure information representing the syntactic structure of the text to be classified based on the position of each character in the text to be classified;
[0008] According to the character semantic information of each character and the syntactic structure information, a target emotion category to which the emotion expressed by the to-be-classified text belongs is determined from preset emotion categories.
[0009] In a second aspect, an embodiment of the present invention provides a text sentiment classification device, comprising:
[0010] A first information acquisition module is configured to extract, for each character in the text to be classified, character semantic information representing the semantics of the character based on the character and its position in the text to be classified;
[0011] a second information acquisition module, configured to acquire syntactic structure information representing the syntactic structure of the text to be classified based on the position of each character in the text to be classified;
[0012] The emotion category determination module is used to determine the target emotion category to which the emotion expressed by the to-be-classified text belongs from preset emotion categories based on the character semantic information of each character and the syntactic structure information.
[0013] In a third aspect, an electronic device includes a processor, a communication interface, a memory, and a communication bus, wherein the processor, the communication interface, and the memory communicate with each other via the communication bus;
[0014] Memory for storing computer programs;
[0015] The processor is configured to implement any one of the method steps of the first aspect when executing a program stored in the memory.
[0016] In a fourth aspect, a computer-readable storage medium is provided, wherein a computer program is stored in the computer-readable storage medium, and when the computer program is executed by a processor, any method step of the first aspect is implemented.
[0017] Beneficial effects of the embodiments of the present invention:
[0018] An embodiment of the present invention provides a text sentiment classification method, which extracts character semantic information representing the semantics of each character in the text to be classified based on the character and its position in the text to be classified; obtains syntactic structure information representing the syntactic structure of the text to be classified based on the position of each character in the text to be classified; and determines the target emotion category to which the emotion expressed in the text to be classified belongs from preset emotion categories based on the character semantic information and the syntactic structure information of each character.
[0019] As can be seen from the above, first, the character semantic information of each character in the above text to be classified and the syntactic structure information of the above text to be classified are obtained. The above character semantic information can represent the semantics of each character in the above text to be classified, and the above syntactic structure information can represent the syntactic structure of the above text to be classified. The combination of the two can represent the semantics and syntactic structure of the text to be classified as a whole, so that the target emotion category to which the text to be classified belongs can be analyzed based on the semantics and syntactic structure of the text to be classified, that is, the emotion expressed in the text can be classified through the embodiment of the present invention. Moreover, the solution provided by the embodiment of the present invention refers to both the semantics of each character in the text to be classified and the syntactic structure of the text to be classified when performing emotion classification. There is more reference information, so that the classification result obtained is more accurate. BRIEF DESCRIPTION OF THE DRAWINGS
[0020] In order to more clearly illustrate the embodiments of the present invention or the technical solutions in the prior art, the following briefly introduces the drawings required for use in the embodiments or the description of the prior art. Obviously, the drawings described below are only some embodiments of the present invention. For ordinary technicians in this field, other drawings can also be obtained based on these drawings.
[0021] Figure 1 A schematic diagram of a flow chart of a first text sentiment classification method provided by an embodiment of the present invention;
[0022] Figure 2A A schematic diagram of the structure of a dependency syntax tree provided by an embodiment of the present invention;
[0023] Figure 2B A schematic diagram of a text structure diagram provided by an embodiment of the present invention;
[0024] Figure 2C A schematic diagram of a flow chart of a second text sentiment classification method provided by an embodiment of the present invention;
[0025] Figure 3 A schematic diagram of a flow chart of a third text sentiment classification method provided in an embodiment of the present invention;
[0026] Figure 4 A schematic diagram of a fourth text sentiment classification method provided in an embodiment of the present invention;
[0027] Figure 5 A schematic structural diagram of a first text sentiment classification device provided by an embodiment of the present invention;
[0028] Figure 6 A schematic diagram of the structure of a second text sentiment classification device provided by an embodiment of the present invention;
[0029] Figure 7 A schematic diagram of the structure of a third text sentiment classification device provided by an embodiment of the present invention;
[0030] Figure 8 A schematic structural diagram of an electronic device provided in an embodiment of the invention. DETAILED DESCRIPTION
[0031] The following will be combined with the accompanying drawings in the embodiments of the present invention to clearly and completely describe the technical solutions in the embodiments of the present invention. Obviously, the embodiments described are only part of the embodiments of the present invention, not all of the embodiments. Based on the embodiments of the present invention, all other embodiments obtained by ordinary technicians in this field based on this application are within the scope of protection of the present invention.
[0032] In order to classify the emotion categories of emotions expressed in text, an embodiment of the present invention provides a text emotion classification method and device.
[0033] An embodiment of the present invention provides a text sentiment classification method, which:
[0034] For each character in the text to be classified, extracting character semantic information representing the semantics of the character based on the character and the position of the character in the text to be classified;
[0035] Based on the position of each character in the text to be classified, obtaining syntactic structure information representing the syntactic structure of the text to be classified;
[0036] According to the character semantic information of each character and the above syntactic structure information, the target emotion category to which the emotion expressed by the above text to be classified belongs is determined from preset emotion categories.
[0037] As can be seen from the above, first, the character semantic information of each character in the above text to be classified and the syntactic structure information of the above text to be classified are obtained. The above character semantic information can represent the semantics of each character in the above text to be classified, and the above syntactic structure information can represent the syntactic structure of the above text to be classified. The combination of the two can represent the semantics and syntactic structure of the text to be classified as a whole, so that the target emotion category to which the text to be classified belongs can be analyzed based on the semantics and syntactic structure of the text to be classified, that is, the emotion expressed in the text can be classified through the embodiment of the present invention. Moreover, the solution provided by the embodiment of the present invention refers to both the semantics of each character in the text to be classified and the syntactic structure of the text to be classified when performing emotion classification. There is more reference information, so that the classification result obtained is more accurate.
[0038] First, it should be noted that the present invention does not limit the language of the text to be classified, that is, the language of the text to be classified can be Chinese, English or other languages.
[0039] Figure 1 The flowchart of the first text sentiment classification method provided by the embodiment of the present invention is as follows: Figure 1 As shown, the following steps may be included: S101-S103.
[0040] Step S101: for each character in the text to be classified, extract character semantic information representing the semantics of the character according to the character and its position in the text to be classified.
[0041] Specifically, for each character in the text to be classified, after obtaining the character, the position of the character in the text to be classified can also be obtained. Since the positions of the obtained characters in the text to be classified are different, the character may represent different semantics. Therefore, the semantics that the character may represent in the text to be classified can be jointly determined according to the character and the position of the character in the text to be classified.
[0042] Among them, the position of the character in the text to be classified can be represented by the order of the character among all characters in the text to be classified. When the language of the text to be classified is Chinese, each character can be a Chinese character. When the language of the text to be classified is English, each character can be a word.
[0043] Next, the implementation methods of obtaining the characters in the text to be classified and the positions of the characters in the text to be classified will be described.
[0044] In one embodiment of the present invention, each character in the text to be classified is traversed to determine the position of the character in the text to be classified, and then the character and its position in the text are spliced by brackets, parentheses or other means to obtain the character semantic information of the character.
[0045] For example: the text to be classified is: "Text segmentation". Traverse the above classification text. When traversing to the character "文", the character is in the 0th position in the above classification text. Then the character and its position in the above classification text can be spliced by parentheses to obtain: ("文", 0), as the character semantic information of the character "文". Similarly, when traversing to the character "本", the character is in the 1st position in the above classification text, and ("本", 1) can be obtained as the character semantic information of the character "本". When traversing to the character "分", the character is in the 2nd position in the above classification text, and ("分", 2) can be obtained as the character semantic information of the character "分". When traversing to the character "字", the character is in the 3rd position in the above classification text, and ("字", 3) can be obtained as the character semantic information of the character "字". Through the above method, the character semantic information of each character in the text to be classified can be obtained. In addition, the obtained character semantic information of each character can be stored in a list, text or other ways.
[0046] In another embodiment of the present invention, each character in the text to be classified can be traversed first, and each obtained character is stored in a text, list or other ways to obtain character information. Then each character in the above character information is traversed to determine the position of the character in the text to be classified, and the character position information representing the above position is stored in a text, list or other ways to obtain the overall position information of the text to be classified.
[0047] For example, the text to be classified is: "Text character segmentation". By traversing the above classified text, each obtained character can be stored in the form of a list, that is, a list in the form of ["文", "本", "分", "字"] is obtained, and the above list is used as character information. Then, by traversing the above list, the character "文" is located at the 0th position in the above text to be classified, the character "本" is located at the 1st position in the above text to be classified, the character "分" is located at the 2nd position in the above text to be classified, and the character "字" is located at the 3rd position in the above text to be classified. Similarly, the character position information of each character can be stored in the form of a list, that is, a list in the form of [0, 1, 2, 3] is obtained, and the above list is used as the position information of the text to be classified.
[0048] In addition, the following describes the specific implementation method for determining the character semantic information of a character based on the character and its position in the text to be classified.
[0049] First, it should be noted that whether it is a Chinese character, an English character, or a character in other languages, the character needs to be converted into a digital form so that the computer can recognize it.
[0050] In an embodiment of the present invention, through a pre-trained model, such as: BERT (Bidirectional Encoder Representations from Transformer, bidirectional encoder) model, ELMO (Embedding from Language Model, embedding from language model) model, etc., or by a method of random generation, a character tensor E representing each character in the text to be classified and a position tensor P representing the position of each character in the text to be classified in the text to be classified can be obtained.
[0051] Among them, the character tensor E can be expressed as:
[0052] E = [e0, e1,..., e i ,..., e n
[0053] First, i is the number of the character in the text to be classified, n is the total number of characters in the text to be classified, and the above e i is: the character vector of the i-th character in the text to be classified, e0 is: the character vector of the 0th character in the text to be classified, e1 is: the character vector of the 1st character in the text to be classified, and e n ]is: the character vector of the nth character in the text to be classified.
[0054] For example, if the text to be classified has 3 characters, the character tensor E can be expressed as: E = [e0, e1, e2].
[0055] Secondly, the dimension of the above character tensor E is: The above R represents a set of real numbers, and the above N represents the number of characters contained in the text to be classified. For example, if the text to be classified has 5 characters, then the above N is 5; if the text to be classified has 30 characters, then the above N is 30; the above d e Represents: The length of each character vector. The length of the character vector for each character in the text to be classified is the same.
[0056] The position tensor P can be expressed as:
[0057] P=[p0,p1,…,p i ,…p n ]
[0058] First, i is the number of the characters in the text to be classified, n is the total number of characters in the text to be classified, and the above p i is the position vector of the position of the i-th character in the text to be classified, p0 is the position vector of the position of the 0-th character in the text to be classified, p1 is the position vector of the position of the 1-th character in the text to be classified, p n is: the position vector of the position of the nth character in the text to be classified.
[0059] For example, if the text to be classified has 3 characters, the two-dimensional tensor P can be expressed as: P = [p0, p1, p2].
[0060] Secondly, the dimensions of the position tensor P above are: The above R represents a set of real numbers, and the above N represents the number of characters contained in the text to be classified. If the text to be classified has 5 characters, then the above N is 5; if the text to be classified has 30 characters, then the above N is 30; the above d p Represents: The length of the position vector of a character. The length of the position vector of each character in the text to be classified is the same.
[0061] In one embodiment of the present invention, a character semantics acquisition model can be pre-trained, and the character vector E and position vector P of the above-mentioned text to be classified can be used as the input of the above-mentioned pre-trained character speech acquisition model. The output result of the above-mentioned character semantics acquisition model is the character semantic information of each character in the text to be classified.
[0062] For example, a BERT model can be pre-trained as a character semantics acquisition model, and then the above character tensor E and position tensor P can be input into the pre-trained BERT model to obtain the character semantic information of each character.
[0063] The above process can be expressed as:
[0064] H=BERT(E||P)
[0065] The expression (E||P) above represents the concatenation of each character vector in the character tensor E and each position vector in the character tensor P. For example, if the length of a character vector in the character tensor E is m and the length of a position vector in the character tensor P is n, the length of the concatenated character vector and position vector is m + n. The concatenated result is then used as the input to the BERT model, resulting in the semantic tensor H.
[0066] Specifically, i is the number of the character in the text to be classified, n is the total number of characters in the text to be classified, H = [h0,h1,…,h i ,…,h n ], the above h i is the character semantic information of the i-th character in the text to be classified, the above h0 is the character semantic information of the 0-th character in the text to be classified, the above h1 is the character semantic information of the 1st character in the text to be classified, and the above h n is: the semantic information of the nth character in the text to be classified.
[0067] The dimensions of H are: The above R represents a real number set, the above N represents: the number of characters contained in the text to be classified, the above d h Represents: the vector length of the semantic vector of each character. After obtaining the semantic tensor H, the semantic vector of each character contained in the semantic tensor H can be used as the character semantic information of each character.
[0068] Step S102: Based on the position of each character in the text to be classified, syntactic structure information representing the syntactic structure of the text to be classified is obtained.
[0069] Among them, the above-mentioned syntactic structure is the structural relationship between the various syntactic costs represented by the characters in the text to be classified. For example, the above-mentioned syntactic components include subject, predicate, object, attributive, adverbial, complement, etc. The above-mentioned syntactic structure can include subject-predicate structure, verb-object structure, attributive structure, joint structure, supplementary structure, etc.
[0070] Specifically, because each character's position in the text to be classified is different, the syntactic component it serves in the text to be classified may also be different. For example, if the text to be classified is Chinese, the character representing the subject of the text to be classified may be located at the beginning of the text to be classified, while the character representing the predicate of the text to be classified may be located adjacent to the character representing the subject of the text to be classified. Therefore, based on the position of each character in the text to be classified, syntactic structure information representing the syntactic structure of the text to be classified can be obtained.
[0071] In one embodiment of the present invention, the above step S102 can be implemented by following step A, which will not be described in detail here.
[0072] Step S103: According to the character semantic information of each character and the syntactic structure information, the target emotion category to which the emotion expressed by the text to be classified belongs is determined from preset emotion categories.
[0073] Specifically, common sense indicates that for any text, if the semantics of each character in the text and the syntactic structure of the text can be determined, the semantics of the text can be determined, and further, the emotional category of the emotion expressed by the text can be determined. Therefore, based on the character semantic information representing the semantics of each character in the text to be classified and the syntactic structure information representing the syntactic structure of the text to be classified, the semantics of the text to be classified can be determined, and further, the emotional category to which the emotion expressed by the text to be classified belongs can be determined.
[0074] In addition, the above-mentioned preset emotion categories may include: positive emotion category, neutral emotion category, negative emotion category, etc.
[0075] In one embodiment of the present invention, Figure 2C Steps S103A to S103C in the above embodiment implement the above step S103, which will not be described in detail here.
[0076] In another embodiment of the present invention, the above step S103 may also be implemented by following steps B-C, which will not be described in detail here.
[0077] As can be seen from the above, first, the character semantic information of each character in the above text to be classified and the syntactic structure information of the above text to be classified are obtained. The above character semantic information can represent the semantics of each character in the above text to be classified, and the above syntactic structure information can represent the syntactic structure of the above text to be classified. The combination of the two can represent the semantics and syntactic structure of the text to be classified as a whole, so that the target emotion category to which the text to be classified belongs can be analyzed based on the semantics and syntactic structure of the text to be classified, that is, the emotion expressed in the text can be classified through the embodiment of the present invention. Moreover, the solution provided by the embodiment of the present invention refers to both the semantics of each character in the text to be classified and the syntactic structure of the text to be classified when performing emotion classification. There is more reference information, so that the classification result obtained is more accurate.
[0078] In addition, in order to classify the emotions expressed in the text to be classified, the prior art uses a pre-trained language model to directly encode the text to be classified. Although the above method can determine the semantic information of each character in the text to be classified, it cannot determine the syntactic structure of the text to be classified. According to common sense, even if the semantics of each character in the text to be classified can be determined, if the syntactic structure of the text to be classified is different, the semantics expressed in the text to be classified may also be different, and then the emotion category of the emotion expressed in the text to be classified may also be different. Therefore, the prior art cannot accurately classify the emotions expressed in the text to be classified. The embodiment of the present invention simultaneously determines the target emotion category to which the emotion expressed in the text to be classified belongs based on the character semantic information of each character and the syntactic structure information of the text to be classified. Therefore, compared with the prior art, the embodiment of the present invention can more accurately classify the emotion category of the emotion expressed in the text to be classified.
[0079] Secondly, since there are usually not too many characters in the text to be classified, the text to be classified contains less background information used to modify the text besides the text trunk. For example, the text trunk can be the subject, predicate, and object contained in the text, and the background information can be adverbials, attributives, complements, etc. When the semantics of some characters in the text to be classified are determined only based on the text trunk, ambiguity may occur, which in turn leads to ambiguity in determining the semantics of the text to be classified. For example: the text to be classified contains two characters "stock", but since the text to be classified has fewer characters, it is impossible to determine whether the content expressed in the text to be classified is indeed related to stocks, and it is also impossible to determine whether the semantics expressed by the characters "stock" in the text to be classified is related to stocks.
[0080] The embodiment of the present invention can obtain the character semantic information of the above-mentioned text to be classified based on a pre-trained character semantic acquisition model. The above-mentioned character semantic acquisition model is obtained by training a large amount of text to be classified. Therefore, even if the characters in the above-mentioned text to be classified are relatively short, the character semantic acquisition model can also accurately obtain the character semantic information representing the semantics of each character in the above-mentioned text to be classified.
[0081] In one embodiment of the present invention, the above step S102 can be implemented by following step A.
[0082] Step A: Based on the position of each character in the text to be classified, a dependency syntax tree of the text to be classified is constructed as the syntax structure information of the text to be classified.
[0083] Among them, each node in the above-mentioned dependency syntax tree corresponds to a character of the above-mentioned text to be classified, the character corresponding to the third node of any two interconnected nodes in the above-mentioned dependency syntax tree is used to modify the character corresponding to the fourth node, and the above-mentioned third node in the above-mentioned dependency syntax tree points to the fourth node.
[0084] Specifically, for each character in the above-mentioned text to be classified, the syntactic component of the character in the above-mentioned text to be classified can be determined based on the position of the character in the above-mentioned text to be classified, and then, based on the syntactic component that each determined character plays in the above-mentioned text to be classified, a dependency syntactic tree that can represent the syntactic structure information of the above-mentioned text to be classified can be constructed.
[0085] The dependency syntax tree is a tree-shaped data structure, and each node in the dependency syntax tree corresponds to a character of the text to be classified. That is, if the text to be classified contains 10 characters, the dependency syntax tree contains 10 nodes.
[0086] In addition, the character corresponding to the third node of any two nodes connected to each other in the dependency syntax tree is used to modify the character point corresponding to the fourth node. For example: Figure 2A , is a schematic diagram of the structure of a dependency syntax tree provided by an embodiment of the present invention. The dependency syntax tree contains three nodes, which respectively correspond to three characters in the text to be classified. The text to be classified is: "Cat eats fish". The character "cat" and the character "eat" have a subject-predicate relationship, that is, the character "cat" acts as a subject to modify the character "eat". Therefore, the second node corresponding to the character "cat" is connected to the first node corresponding to the character "eat". The character "eat" and the character "fish" have a verb-object relationship, that is, the character "fish" acts as an object to modify the character "eat". Therefore, the first node corresponding to the character "eat" in the dependency syntax tree is connected to the third node corresponding to the character "fish". Therefore, the dependency syntax tree can represent the syntactic structure of the text to be classified, that is, the dependency syntax tree can be used as the syntactic structure information of the text to be classified.
[0087] In one embodiment of the present invention, a dependency syntax tree of the text to be classified may be constructed based on tools such as spacy as the syntax structure information of the text to be classified.
[0088] From the above, it can be seen that the syntactic component of each character in the text to be classified can be determined based on the position of the character in the text to be classified. Then, based on the syntactic component of each character in the text to be classified, it is possible to determine whether there is a syntactic relationship between any two characters, and construct a dependency syntactic tree based on whether there is a syntactic relationship between the two characters. Therefore, the dependency syntactic tree can represent the syntactic structure information of the text to be classified.
[0089] In another embodiment of the present invention, the above step S103 can also be implemented by the following steps B-C.
[0090] Step B: Constructing a text structure diagram of the text to be classified based on the character semantic information of each character and the syntactic structure information.
[0091] Each node in the text structure diagram corresponds to a character in the text to be classified.
[0092] Specifically, the above text structure graph is an undirected graph data structure, and each node in the above text structure graph corresponds to a character of the above text to be classified, that is, if the above text to be classified contains 10 characters, then the above text structure graph contains 10 nodes.
[0093] In addition, the node value of each node is the character semantic information of the character corresponding to the node. The character corresponding to the first node of any two interconnected nodes in the above text structure diagram is used to modify the character corresponding to the second node. In the above text structure diagram, the above first node points to the second node.
[0094] In one embodiment of the present invention, a text structure graph of the text to be classified can be constructed based on the character semantic information represented by the semantic tensor and the syntactic structure information represented by the dependency structure tree. The constructed text structure graph can be represented by G = (A, H), where A∈{0,1} N×N is the adjacency matrix obtained through the above dependency syntax tree, N is the number of characters contained in the text to be classified, H is the above semantic tensor, h i ∈H, and the above h iThe semantic vector of the character corresponding to the i-th node in the above text structure diagram is obtained by using the above dependency syntax tree. It is an existing technology and will not be described in detail here. The detailed information of the above semantic tensor and the above dependency syntax tree has been described in detail above and will not be repeated here.
[0095] See also Figure 2B , which is a structural diagram of a text structure diagram provided by an embodiment of the present invention.
[0096] Figure 2B is Figure 2A The syntactic structure of the representation is obtained based on Figure 2B Each of Figure 2A Each node in corresponds one to one, and Figure 2B and Figure 2A The connection relationship between each node in is the same as Figure 2A The difference is, Figure 2B The node value of each node in is the character semantic information of the character corresponding to the node.
[0097] Step C: According to the above text structure diagram, determine the target emotion category to which the emotion expressed by the above text to be classified belongs from preset emotion categories.
[0098] Specifically, the node value of each node in the above text structure diagram is the character semantic information of the character corresponding to the node, and the connection relationship between the nodes in the above text structure diagram represents the syntactic structure of the text to be classified. Therefore, the semantics of each character in the above text to be classified and the grammatical structure of the above text to be classified can be determined from the above text structure diagram, and then the target emotion category to which the emotion expressed by the above text to be classified belongs can be determined.
[0099] In one embodiment of the present invention, a graph neural network model for determining the sentiment category of a text can be pre-trained, and the above-mentioned text structure graph is used as the input of the above-mentioned graph neural network model. Based on the output result of the above-mentioned graph neural network model, the target sentiment category to which the sentiment expressed by the above-mentioned text to be classified belongs is determined.
[0100] From the above, it can be seen that the embodiment of the present invention can construct a text structure diagram of the above-mentioned text to be classified. The node value of each node in the above-mentioned text structure diagram is the character semantic information of the character corresponding to the node, and the connection relationship between the nodes in the above-mentioned text structure diagram represents the syntactic structure of the text to be classified. Therefore, the semantics of each character in the above-mentioned text to be classified and the grammatical structure of the above-mentioned text to be classified can be determined from the above-mentioned text structure diagram, and then the target emotion category to which the emotion expressed in the above-mentioned text to be classified belongs can be determined.
[0101] Figure 2CThe flow chart of the second text sentiment classification method provided by the embodiment of the present invention is shown in FIG2. Figure 1 Compared with the embodiment shown, the above step S103 may include the following steps: S103A-S103C.
[0102] Step S103A: extracting text semantic information representing the semantics of the text to be classified based on the character semantic information of each character and the syntactic structure information.
[0103] Specifically, for the text to be classified, if the semantics of each character in the text to be classified and the syntactic structure of the text to be classified can be determined, the semantics expressed by the text to be classified can be determined. Therefore, the text semantic information representing the semantics of the above-mentioned text to be classified can be extracted based on the character semantic information representing the semantics of the characters in the text to be classified and the syntactic structure information representing the syntactic structure of the text to be classified.
[0104] In one embodiment of the present invention, text semantic information representing the semantics of the above-mentioned text to be classified can be extracted based on the character semantic information represented by the semantic tensor and the syntactic structure information represented by the text structure graph, wherein the method for obtaining the above-mentioned semantic tensor and the above-mentioned text structure graph has been described in detail above and will not be repeated here.
[0105] In another embodiment of the present invention, the above step S103A can be performed by Figure 3 The step S103A1 in FIG. 1 is implemented and will not be described in detail here.
[0106] Step S103B: obtaining each first classification information based on the extracted text semantic information.
[0107] Each piece of first classification information corresponds to a preset emotion category, and each piece of first classification information indicates the possibility that the emotion expressed by the text to be classified belongs to the preset emotion category corresponding to the first classification information.
[0108] Specifically, because the extracted text semantic information can represent the semantics expressed by the above-mentioned text to be classified, the probability that the above-mentioned text to be classified may express each preset emotion category can be analyzed separately according to the semantics expressed by the above-mentioned text to be classified as each first classification information.
[0109] In addition, each first classification information corresponds to a preset emotion category. For example, if the above-mentioned preset emotion categories include: positive category, negative category and neutral category, then three first classification information can be obtained, among which the first first classification information can indicate: the possibility that the emotion expressed by the above-mentioned text to be classified belongs to the positive category, the second first classification information can indicate: the possibility that the emotion expressed by the above-mentioned text to be classified belongs to the negative category, and the third first classification information can indicate: the possibility that the emotion expressed by the above-mentioned text to be classified belongs to the neutral category.
[0110] In one embodiment of the present invention, the above-mentioned first classification information can be represented by any numerical value between 0 and 1. The closer the value of the above-mentioned first classification information is to 1, the higher the possibility that the emotion expressed in the above-mentioned text to be classified belongs to the preset emotion category corresponding to the first classification information. The closer the value of the above-mentioned first classification information is to 0, the lower the possibility that the emotion expressed in the above-mentioned text to be classified belongs to the preset emotion category corresponding to the first classification information.
[0111] Step S103C: Based on the obtained first classification information, determine the target emotion category to which the emotion expressed by the text to be classified belongs from preset emotion categories.
[0112] Specifically, because for each first classification information obtained, the first classification information represents the possibility that the emotion expressed in the text to be classified belongs to the preset emotion category corresponding to the first classification information, the first classification information with the highest representation possibility can be determined based on the various first classification information obtained, and then the preset emotion category corresponding to the first classification information can be determined as the target emotion category to which the emotion expressed in the above-mentioned text to be classified belongs.
[0113] In one embodiment of the present invention, if the above-mentioned first classification information can be represented by any numerical value between 0 and 1, for example: two first classification information are obtained, wherein the first first classification information represents the possibility that the emotion expressed by the above-mentioned text to be classified belongs to the positive category, and the second first classification information represents the possibility that the emotion expressed by the above-mentioned text to be classified belongs to the negative category, if the value of the above-mentioned first first classification information is greater than the value of the above-mentioned second first classification information, it can be determined that the target emotion category expressed by the text to be classified is the positive category; if the value of the above-mentioned first first classification information is less than the value of the above-mentioned second first classification information, it can be determined that the target emotion category expressed by the text to be classified is the negative category.
[0114] From the above, it can be seen that first, the text semantic information of the text to be classified can be extracted based on the character semantic information representing the characters in the text to be classified and the syntactic structure information of the text to be classified. Because the text semantic information can represent the semantics expressed by the text to be classified, and then based on the semantics expressed by the text to be classified, the possibility of the emotion of the classified text being each preset emotion category can be determined. Therefore, based on the text semantic information, each first classification information can be obtained, and then based on each first classification information, the target emotion category expressed by the text to be classified can be determined.
[0115] Figure 3 The flowchart of the third text sentiment classification method provided by the embodiment of the present invention is as follows: Figure 3 As shown, Figure 2C Compared with the embodiment shown, the above step S103A can be implemented by the following step S103A1, and the above step S103C can be implemented by the following step S103C1.
[0116] Step S103A1: Input the character semantic information of each character and the above-mentioned syntactic structure information into a pre-trained text sentiment classification model, and obtain the low-level output result of the low-level network output contained in the above-mentioned text sentiment classification model as the text semantic information representing the semantics of the above-mentioned text to be classified.
[0117] Among them, each low-level output node of the above-mentioned low-level network outputs a low-level output result respectively, and the above-mentioned text sentiment analysis network also includes a high-level network. Each high-level output node contained in the above-mentioned high-level network corresponds to a preset sentiment category, and the above-mentioned text sentiment classification model is obtained based on sample text training.
[0118] Specifically, the above-mentioned text sentiment classification model includes a low-level network and a high-level network. The above-mentioned low-level network is used to determine the semantics expressed by the above-mentioned text to be classified, and the above-mentioned high-level network determines the possibility that the above-mentioned text to be classified belongs to each preset emotion category based on the low-level output results output by the above-mentioned low-level network.
[0119] Furthermore, there is no limit on the number of low-level output nodes in the aforementioned low-level network. Each low-level output node can output a low-level output result, and each low-level output result can represent the semantics of the text to be classified. In other words, the low-level network provided by the embodiments of the present invention can generate a variety of different output results after analyzing the semantics of the text to be classified. Specifically, the low-level output result represents the semantics of the text to be classified, but does not include the semantics represented by the background information in the text to be classified.
[0120] Each high-level output node contained in the above high-level network corresponds to a preset emotion category, that is, if the preset emotion category includes: positive emotion, negative emotion and neutral emotion, then the above high-level network contains 3 high-level output nodes.
[0121] In one embodiment of the present invention, the above-mentioned text sentiment classification model is a graph attention capsule network model, which includes: a low-level capsule network layer and a high-level capsule network layer. The above-mentioned low-level capsule network layer serves as the above-mentioned low-level network, which contains multiple low-level output nodes. The above-mentioned high-level capsule network layer serves as the above-mentioned high-level network, and each high-level output node contained therein corresponds to a preset emotion category.
[0122] In another embodiment of the present invention, if the text sentiment classification model is a graph attention capsule network model, and a text structure graph is used to represent the character semantic information of the characters in the text to be classified and the syntactic structure information of the text to be classified, the lower-level capsule network layer can be based on the graph attention mechanism and sequentially map each node in the text structure graph using the following formula:
[0123]
[0124]
[0125]
[0126] Among them, the above l is the number of times the low-level output node processes data, g is the number of the low-level output node, i and j are the numbers of the nodes in the text structure diagram, the i-th node is connected to the j-th node in the text structure diagram, the above LeakeyReLU is the activation function, and the above Represents: the attention weight of the lth data processing of the gth low-level output node in the above low-level capsule network layer, the above The g-th low-level output node is the i-th node h in the above text structure diagram. i and the jth node h in the above text structure diagram j The above a is calculated l,g and the above W g are the pre-trained parameters of the above-mentioned graph attention capsule network model. ij Represents: the attention weight between the i-th node and the j-th node in the above text structure diagram, the above x ij is obtained based on the adjacency matrix in the above text structure diagram. ij It can be expressed as:
[0127]
[0128] The above aij Means: The above adjacency matrix is in the i-th row and j-th column element, It means: the g-th low-level output node in the above-mentioned low-level capsule network layer is based on the result of the l-th data processing of the i-th node in the text structure graph. The g-th low-level output node in the above-mentioned low-level capsule network layer is based on each node in the text structure graph. After the l-th data processing, it will output a result. The g-th low-level output node in the above-mentioned low-level capsule network layer can splice the output results to get u y|g , the above u y|g A low-level output result that can represent the semantics of the text to be classified is generated by the g-th low-level output node and input to the y-th high-level output node.
[0129] Step S103C1: input all obtained low-level output results into the above-mentioned high-level network to obtain high-level output results of each high-level output node as first classification information corresponding to each preset emotion category.
[0130] The high-level output result output by each high-level output node represents the possibility that the emotion expressed by the text to be classified belongs to the preset emotion category corresponding to the high-level output node.
[0131] Specifically, each low-level output node in the above-mentioned low-level network will output a low-level output result, and then all the obtained low-level output results will be input into each high-level output node in the above-mentioned high-level network in turn, and each low-level output result can represent the semantics represented by the above-mentioned text to be classified. Therefore, each high-level output node in the above-mentioned high-level network can output the high-level output result as the first classification information by obtaining the overall situation of the semantics represented by each low-level output result.
[0132] In one embodiment of the present invention, the above-mentioned text sentiment classification model is a graph attention capsule network model, which includes: a low-level capsule network layer and a high-level capsule network layer. The low-level capsule network layer contains multiple low-level output nodes, and each high-level output node contained in the high-level capsule network layer corresponds to a preset emotion category.
[0133] In the case where the above-mentioned text sentiment classification model is a graph attention capsule network model, the output of each high-level output node in the above-mentioned high-level capsule network layer can be calculated according to the dynamic routing algorithm. This process can be expressed by the following formula:
[0134] c ij =exp(b ij ) / Σ k exp(b ik )
[0135] sj =Σ k c ij u j|i
[0136]
[0137] Among them, i is the number of the low-level output node, j is the number of the high-level output node, and b ij It represents the similarity between the i-th low-level output node and the j-th high-level output node, exp() is an exponential function with the natural constant e as the base, b ij The calculation process is as follows:
[0138] b ij =b ij +u j|i ·v j
[0139] c ij It means: the coupling coefficient between the i-th low-level output node and the j-th high-level output node, and the above c is calculated. ij The process is a normalization process, the above k is the number of the above low-level output nodes, the above u j|i is the low-level output result output by the i-th low-level output node to the j-th high-level output node. The above v j It is the high-level output result output by the j-th high-level output node above.
[0140] It can be seen from the above that the embodiment of the present invention determines the target emotion category to which the above-mentioned text to be classified belongs based on the text emotion classification model. The above-mentioned text emotion classification model includes a high-level network and a low-level network. The above-mentioned low-level network can output a low-level output result representing the semantics expressed by the above-mentioned text to be classified based on the character semantic information of the characters representing the above-mentioned text to be classified and the above-mentioned syntactic structure information. The above-mentioned high-level network can determine the various first classification information corresponding to the above-mentioned text to be classified based on the above-mentioned low-level output result, and then determine the target emotion category to which the emotion expressed by the text to be classified belongs based on the first classification information.
[0141] In addition, the above-mentioned low-level network includes multiple low-level output nodes, and each of the above-mentioned low-level output nodes can input low-level output results to each high-level output node in the high-level network, and the high-level output nodes in the above-mentioned high-level network can output high-level output results based on the overall situation of multiple low-level output results. Therefore, even if the low-level output results output by some low-level output nodes may have some deviations, the overall situation of multiple low-level output results may not deviate much. Therefore, the high-level output node may still output high-level output results more accurately based on the overall situation of multiple low-level output results. That is to say, the embodiment of the present invention can enhance the robustness of the text sentiment classification model.
[0142] Secondly, the embodiment of the present invention first simplifies the more complex text to be classified based on a top-down approach, that is, obtains the semantics of each character in the above text to be classified and the syntactic structure of the above text to be classified, and then obtains more complex information based on the simple information based on a bottom-up approach, that is, based on the character semantic information representing the semantics of each character in the above text to be classified and the syntactic structure information representing the syntactic structure of the above text to be classified, obtains text semantic information representing the semantics of the above text to be classified. Based on this combination of top-down and bottom-up approaches, the embodiment of the present invention can more accurately classify the emotion categories of the emotions expressed in the text to be classified.
[0143] Figure 4 The flowchart of the fourth text sentiment classification method provided by the embodiment of the present invention is as follows: Figure 4 As shown, Figure 3 Compared with the embodiment shown, after the above step S103C1, it further includes: S104-S105.
[0144] Step S104: Based on the obtained first classification information, second classification information is constructed to indicate the possibility that the emotion expressed in the text to be classified belongs to each preset emotion category.
[0145] Specifically, after obtaining each piece of first classification information, the first classification information may be converted into second classification information, so that the target classification emotion to which the to-be-classified text belongs may be directly determined according to the second classification information.
[0146] In one embodiment of the present invention, if the first classification information is obtained by the graph attention capsule network model, the j-th first classification information can be represented by the vector v j It means that the above-mentioned multiple first classification information can be converted into the second classification information v0 by matrix transformation, where: R represents a real number set, O represents the number of the above high-level output nodes, that is, the number of preset emotion categories, and the above d v Represents: v representing the jth first classification information j The length of the vector.
[0147] Step S105: Based on the second classification information, determine the target emotion category to which the emotion expressed in the text to be classified belongs from preset emotion categories.
[0148] Specifically, because the second classification information can be used to determine the possibility that the emotion expressed in the text to be classified belongs to each preset emotion category
[0149] As can be seen from the above, each high-level output node can output a high-level output result, and each high-level output result can be used as a first classification information. Then, it is necessary to determine the target emotion category to which the above-mentioned text to be classified belongs based on each first classification information. The embodiment of the present invention can convert the above-mentioned multiple first classification information into a second classification information. The above-mentioned second classification information can indicate the possibility that the emotion expressed in the above-mentioned text to be classified belongs to each preset emotion category. Therefore, the target emotion category to which the emotion expressed in the above-mentioned text to be classified belongs can be directly determined based on the above-mentioned second classification information.
[0150] In addition, when classifying the emotions of the text to be classified, it is necessary to train a text emotion classification model in advance, and then determine the target emotion category to which the emotion expressed by the text to be classified belongs based on the text emotion classification model.
[0151] When training the above-mentioned text sentiment classification model, a regularization algorithm can be used to reduce the loss of the above-mentioned text sentiment classification model so that the trained text sentiment classification model will not be overfitted. For example, the L2 regularization algorithm can be used. The specific process is as follows:
[0152] loss=T0max(0,m + -||v0||) 2 +λ1(1-T0)max(0,||v0||-m - )+λ2||Θ||2
[0153] Among them, loss is the loss of the text sentiment classification model, T0=1 indicates that the classification result obtained based on the above text sentiment classification model is accurate, T0=0 indicates that the classification result obtained based on the above text sentiment classification model is inaccurate, the above v0 is the above second classification information containing a first classification information, ‖v0‖ is the modulus of v0, m + and m - is an empirical parameter, generally m + 0.9, m - is 0.1, λ1 and λ2 are hyperparameters, Θ is all the weight parameters in the above text sentiment classification model, ‖Θ‖ is modulo Θ, and the subscript 2 of ‖Θ‖2 indicates that the norm of Θ is the Euclidean norm.
[0154] In addition, when training the above-mentioned text sentiment classification model, it is also necessary to pre-set network parameters. The above-mentioned network parameters include the character length of the above-mentioned text to be classified, the length of the character vector, the length of the hidden vector in the text sentiment classification model, hyperparameters, etc. Secondly, when training the above-mentioned text sentiment classification model, algorithms such as SGD (Stochastic Gradient Descent) algorithm and adam (Adaptive Moment Estimate) algorithm can be used to optimize the above-mentioned text sentiment classification model, and methods such as early stopping and parameter search can be used to prevent the above-mentioned text sentiment classification model from overfitting.
[0155] Finally, after completing the training of the above-mentioned text sentiment classification model, the sentiment of the above-mentioned text to be classified can be judged. For example, the probability information of the above-mentioned text to be classified belonging to each preset classification sentiment can be obtained, and then the above-mentioned probability information can be saved as a file such as json (JavaScript Object Notation, a lightweight data exchange format based on JavaScript language) for calling other interfaces.
[0156] Figure 5 This is a structural diagram of a first text sentiment classification device provided by an embodiment of the present invention. The device may include the following modules: 501-503.
[0157] The first information acquisition module 501 is configured to extract, for each character in the text to be classified, character semantic information representing the semantics of the character based on the character and its position in the text to be classified;
[0158] The second information acquisition module 502 is configured to acquire syntactic structure information representing the syntactic structure of the text to be classified based on the position of each character in the text to be classified;
[0159] The emotion category determination module 503 is configured to determine the target emotion category to which the emotion expressed by the to-be-classified text belongs from preset emotion categories based on the character semantic information and the syntactic structure information of each character.
[0160] As can be seen from the above, first, the character semantic information of each character in the above text to be classified and the syntactic structure information of the above text to be classified are obtained. The above character semantic information can represent the semantics of each character in the above text to be classified, and the above syntactic structure information can represent the syntactic structure of the above text to be classified. The combination of the two can represent the semantics and syntactic structure of the text to be classified as a whole, so that the target emotion category to which the text to be classified belongs can be analyzed based on the semantics and syntactic structure of the text to be classified, that is, the emotion expressed in the text can be classified through the embodiment of the present invention. Moreover, the solution provided by the embodiment of the present invention refers to both the semantics of each character in the text to be classified and the syntactic structure of the text to be classified when performing emotion classification. There is more reference information, so that the classification result obtained is more accurate.
[0161] In one embodiment of the present invention, the emotion category determination module 503 is specifically configured to:
[0162] Constructing a text structure graph of the text to be classified based on the character semantic information of each character and the syntactic structure information, wherein each node in the text structure graph corresponds to a character in the text to be classified, the node value of each node is the character semantic information of the character corresponding to the node, and the character corresponding to the first of any two interconnected nodes in the text structure graph is used to modify the character corresponding to the second node;
[0163] According to the text structure diagram, a target emotion category to which the emotion expressed by the to-be-classified text belongs is determined from preset emotion categories.
[0164] From the above, it can be seen that the embodiment of the present invention can construct a text structure diagram of the above-mentioned text to be classified. The node value of each node in the above-mentioned text structure diagram is the character semantic information of the character corresponding to the node, and the connection relationship between the nodes in the above-mentioned text structure diagram represents the syntactic structure of the text to be classified. Therefore, the semantics of each character in the above-mentioned text to be classified and the grammatical structure of the above-mentioned text to be classified can be determined from the above-mentioned text structure diagram, and then the target emotion category to which the emotion expressed in the above-mentioned text to be classified belongs can be determined.
[0165] In another embodiment of the present invention, the second information acquisition module 502 is specifically configured to:
[0166] Based on the position of each character in the text to be classified, a dependency syntax tree of the text to be classified is constructed as the syntactic structure information of the text to be classified, wherein each node in the dependency syntax tree corresponds to a character of the text to be classified, and the character corresponding to the third node of any two interconnected nodes in the dependency syntax tree is used to modify the character corresponding to the fourth node.
[0167] From the above, it can be seen that the syntactic component of each character in the text to be classified can be determined based on the position of the character in the text to be classified. Then, based on the syntactic component of each character in the text to be classified, it is possible to determine whether there is a syntactic relationship between any two characters, and construct a dependency syntactic tree based on whether there is a syntactic relationship between the two characters. Therefore, the dependency syntactic tree can represent the syntactic structure information of the text to be classified.
[0168] Figure 6 A schematic diagram of the structure of the second text sentiment classification device provided by the embodiment of the present invention, Figure 5 Compared with the embodiment shown, the emotion category determination module 503 may include the following submodules: 503A-503C.
[0169] The third information acquisition submodule 503A is configured to extract text semantic information representing the semantics of the text to be classified based on the character semantic information of each character and the syntactic structure information;
[0170] First classification information acquisition submodule 503B: for acquiring each piece of first classification information based on the extracted text semantic information, wherein each piece of first classification information corresponds to a preset emotion category, and each piece of first classification information indicates the possibility that the emotion expressed in the text to be classified belongs to the preset emotion category corresponding to the first classification information;
[0171] The emotion category determination submodule 503C is configured to determine, based on the obtained first classification information, a target emotion category to which the emotion expressed by the to-be-classified text belongs from preset emotion categories.
[0172] From the above, it can be seen that first, the text semantic information of the text to be classified can be extracted based on the character semantic information representing the characters in the text to be classified and the syntactic structure information of the text to be classified. Because the text semantic information can represent the semantics expressed by the text to be classified, and then based on the semantics expressed by the text to be classified, the possibility of the emotion of the classified text being each preset emotion category can be determined. Therefore, based on the text semantic information, each first classification information can be obtained, and then based on each first classification information, the target emotion category expressed by the text to be classified can be determined.
[0173] Figure 7 A schematic diagram of the structure of the third text sentiment classification device provided by the embodiment of the present invention, Figure 6 Compared with the embodiment shown, the first classification information acquisition submodule 503B includes the following units: 503B1.
[0174] The third information acquisition unit 503B1 is used to input the character semantic information of each character and the syntactic structure information into a pre-trained text sentiment classification model, and obtain the low-level output results output by the low-level network contained in the text sentiment classification model as text semantic information representing the semantics of the text to be classified, wherein each low-level output node of the low-level network outputs a low-level output result respectively, the text sentiment analysis network also includes a high-level network, each high-level output node contained in the high-level network corresponds to a preset sentiment category, and the text sentiment classification model is obtained based on sample text training;
[0175] The first classification information acquisition submodule is specifically used to:
[0176] All the obtained low-level output results are input into the high-level network to obtain the high-level output results of each high-level output node, which are respectively used as the first classification information corresponding to each preset emotion category, wherein the high-level output result output by each high-level output node represents: the possibility that the emotion expressed in the text to be classified belongs to the preset emotion category corresponding to the high-level output node.
[0177] It can be seen from the above that the embodiment of the present invention determines the target emotion category to which the above-mentioned text to be classified belongs based on the text emotion classification model. The above-mentioned text emotion classification model includes a high-level network and a low-level network. The above-mentioned low-level network can output a low-level output result representing the semantics expressed by the above-mentioned text to be classified based on the character semantic information of the characters representing the above-mentioned text to be classified and the above-mentioned syntactic structure information. The above-mentioned high-level network can determine the various first classification information corresponding to the above-mentioned text to be classified based on the above-mentioned low-level output result, and then determine the target emotion category to which the emotion expressed by the text to be classified belongs based on the first classification information.
[0178] In addition, the above-mentioned low-level network includes multiple low-level output nodes, and each of the above-mentioned low-level output nodes can input low-level output results to each high-level output node in the high-level network, and the high-level output nodes in the above-mentioned high-level network can output high-level output results based on the overall situation of multiple low-level output results. Therefore, even if the low-level output results output by some low-level output nodes may have some deviations, the overall situation of multiple low-level output results may not deviate much, and the high-level output nodes can still output high-level output results relatively accurately based on the overall situation of multiple low-level output results. That is to say, the embodiment of the present invention can enhance the robustness of the text sentiment classification model.
[0179] Secondly, the embodiment of the present invention first simplifies the more complex text to be classified based on this top-down approach, that is, obtains the semantics of each character in the above text to be classified and the syntactic structure of the above text to be classified, and then obtains more complex information based on the simple information based on the bottom-up approach, that is, based on the character semantic information representing the semantics of each character in the above text to be classified and the syntactic structure information representing the syntactic structure of the above text to be classified, obtains text semantic information representing the semantics of the above text to be classified. Based on this combination of top-down and bottom-up approaches, the embodiment of the present invention can more accurately classify the emotion categories of the emotions expressed in the text to be classified.
[0180] In one embodiment of the present invention, the above-mentioned text sentiment classification model is a graph attention capsule network model.
[0181] In another embodiment of the present invention, the emotion category determination submodule 503C is specifically configured to:
[0182] Based on the obtained first classification information, second classification information is obtained, indicating the possibility that the emotion expressed by the text to be classified belongs to each preset emotion category;
[0183] Based on the second classification information, a target emotion category to which the emotion expressed by the to-be-classified text belongs is determined from preset emotion categories.
[0184] As can be seen from the above, each high-level output node can output a high-level output result, and each high-level output result can be used as a first classification information. Then, it is necessary to determine the target emotion category to which the above-mentioned text to be classified belongs based on each first classification information. The embodiment of the present invention can convert the above-mentioned multiple first classification information into a second classification information. The above-mentioned second classification information can indicate the possibility that the emotion expressed in the above-mentioned text to be classified belongs to each preset emotion category. Therefore, the target emotion category to which the emotion expressed in the above-mentioned text to be classified belongs can be directly determined based on the above-mentioned second classification information.
[0185] The embodiment of the present invention further provides an electronic device, such as Figure 8 As shown, it includes a processor 801, a communication interface 802, a memory 803 and a communication bus 804, wherein the processor 801, the communication interface 802, and the memory 803 communicate with each other through the communication bus 804.
[0186] Memory 803, used for storing computer programs;
[0187] The processor 801 is configured to implement the steps of any text sentiment classification method in the above method embodiments when executing the program stored in the memory 803 .
[0188] When the electronic device provided by the embodiment of the present invention is used to classify the emotion category of the emotion expressed in the text, the character semantic information of each character in the above-mentioned text to be classified and the syntactic structure information of the above-mentioned text to be classified are first obtained. The above-mentioned character semantic information can represent the semantics of each character in the above-mentioned text to be classified, and the above-mentioned syntactic structure information can represent the syntactic structure of the above-mentioned text to be classified. The combination of the two can represent the semantics and syntactic structure of the text to be classified as a whole, so that the target emotion category to which the text to be classified belongs can be analyzed based on the semantics and syntactic structure of the text to be classified, that is, the emotion expressed in the text can be classified through the embodiment of the present invention. In addition, the solution provided by the embodiment of the present invention refers to both the semantics of each character in the text to be classified and the syntactic structure of the text to be classified when performing emotion classification. The reference information is relatively large, so that the classification result obtained is relatively accurate.
[0189] The communication bus mentioned in the electronic device mentioned above may be a Peripheral Component Interconnect (PCI) bus or an Extended Industry Standard Architecture (EISA) bus. This communication bus can be divided into an address bus, a data bus, a control bus, etc. For ease of illustration, only one thick line is used in the figure, but this does not mean that there is only one bus or only one type of bus.
[0190] The communication interface is used for communication between the above electronic device and other devices.
[0191] The memory may include random access memory (RAM) or non-volatile memory (NVM), such as at least one disk storage. Alternatively, the memory may be at least one storage device located away from the processor.
[0192] The above-mentioned processor can be a general-purpose processor, including a central processing unit (CPU), a network processor (NP), etc.; it can also be a digital signal processor (DSP), an application-specific integrated circuit (ASIC), a field-programmable gate array (FPGA) or other programmable logic devices, discrete gate or transistor logic devices, and discrete hardware components.
[0193] In another embodiment of the present invention, a computer-readable storage medium is provided, which stores a computer program. When the computer program is executed by a processor, the steps of any of the above-mentioned text sentiment classification methods are implemented.
[0194] When applying the computer-readable storage medium provided by the embodiment of the present invention to classify the emotion category of the emotion expressed in the text, first obtain the character semantic information of each character in the above-mentioned text to be classified and the syntactic structure information of the above-mentioned text to be classified. The above-mentioned character semantic information can represent the semantics of each character in the above-mentioned text to be classified, and the above-mentioned syntactic structure information can represent the syntactic structure of the above-mentioned text to be classified. The combination of the two can represent the semantics and syntactic structure of the text to be classified as a whole, so that the target emotion category to which the text to be classified belongs can be analyzed based on the semantics and syntactic structure of the text to be classified, that is, the emotion expressed in the text can be classified through the embodiment of the present invention. In addition, the solution provided by the embodiment of the present invention refers to both the semantics of each character in the text to be classified and the syntactic structure of the text to be classified when performing emotion classification. The reference information is relatively large, so that the classification result obtained is relatively accurate.
[0195] In another embodiment of the present invention, a computer program product including instructions is provided, which, when executed on a computer, enables the computer to execute any of the text sentiment classification methods in the above embodiments.
[0196] When applying the computer program product provided by the embodiment of the present invention to classify the emotion categories of the emotions expressed in the text, first obtain the character semantic information of each character in the above-mentioned text to be classified and the syntactic structure information of the above-mentioned text to be classified. The above-mentioned character semantic information can represent the semantics of each character in the above-mentioned text to be classified, and the above-mentioned syntactic structure information can represent the syntactic structure of the above-mentioned text to be classified. The combination of the two can represent the semantics and syntactic structure of the entire text to be classified, so that the target emotion category to which the text to be classified belongs can be analyzed based on the semantics and syntactic structure of the text to be classified. That is, the emotion expressed in the text can be classified through the embodiment of the present invention. In addition, the solution provided by the embodiment of the present invention refers to both the semantics of each character in the text to be classified and the syntactic structure of the text to be classified when performing emotion classification. The reference information is relatively large, so that the classification result obtained is relatively accurate.
[0197] In the above embodiments, all or part of the embodiments can be implemented by software, hardware, firmware, or any combination thereof. When implemented using software, all or part of the embodiments can be implemented in the form of a computer program product. The computer program product includes one or more computer instructions. When the computer program instructions are loaded and executed on a computer, all or part of the processes or functions described in the embodiments of the present invention are generated. The computer can be a general-purpose computer, a special-purpose computer, a computer network, or other programmable device. The computer instructions can be stored in a computer-readable storage medium or transmitted from one computer-readable storage medium to another computer-readable storage medium. For example, the computer instructions can be transmitted from one website, computer, server, or data center to another website, computer, server, or data center via a wired (e.g., coaxial cable, optical fiber, digital subscriber line (DSL)) or wireless (e.g., infrared, wireless, microwave, etc.) method. The computer-readable storage medium can be any available medium that can be accessed by a computer or a data storage device such as a server or data center that includes one or more available media. The available medium can be a magnetic medium (e.g., a floppy disk, a hard disk, a tape), an optical medium (e.g., a DVD), or a semiconductor medium (e.g., a solid-state drive (SSD)).
[0198] It should be noted that, in this document, relational terms such as first and second, etc., are used only to distinguish one entity or operation from another entity or operation, and do not necessarily require or imply the existence of any such actual relationship or order between these entities or operations. Moreover, the terms "comprises," "comprising," or any other variants thereof are intended to cover non-exclusive inclusion, so that a process, method, article, or device comprising a series of elements includes not only those elements, but also other elements not explicitly listed, or elements inherent to such process, method, article, or device. In the absence of further limitations, an element defined by the phrase "comprising a ..." does not exclude the presence of other identical elements in the process, method, article, or device comprising the element.
[0199] Each embodiment in this specification is described in a related manner. Similar portions between embodiments can be referenced to each other. Each embodiment focuses on the differences between other embodiments. In particular, since the apparatus, electronic device, computer-readable storage medium, and computer program product embodiments are generally similar to the method embodiments, their descriptions are relatively simplified. For related portions, reference can be made to the descriptions of the method embodiments.
[0200] The above description is only a preferred embodiment of the present invention and is not intended to limit the scope of protection of the present invention. Any modifications, equivalent replacements, improvements, etc. made within the spirit and principles of the present invention are included in the scope of protection of the present invention.
Claims
1. A text sentiment classification method, characterized in that: The method comprises: For each character in the text to be classified, according to the character and the position of the character in the text to be classified, obtain a character tensor representing each character in the text to be classified and a position tensor representing the position of each character in the text to be classified in the text to be classified, wherein the character tensor includes a character vector of each character in the text to be classified, and the position tensor includes a position vector of each character in the text to be classified; Performing a splicing operation on each character vector in the character tensor and each position vector in the position tensor in sequence, and using the spliced result as the input of the model to obtain a semantic tensor, wherein the semantic vector of each character contained in the semantic tensor is respectively used as the character semantic information of each character; Acquiring syntactic structure information representing the syntactic structure of the text to be classified based on the position of each character in the text to be classified; Inputting the character semantic information of each character and the syntactic structure information into a pre-trained text sentiment classification model, obtaining a low-level output result output by a low-level network contained in the text sentiment classification model as text semantic information representing the semantics of the text to be classified, wherein each low-level output node of the low-level network outputs a low-level output result respectively, the text sentiment classification model also includes a high-level network, each high-level output node contained in the high-level network corresponds to a preset sentiment category, the text sentiment classification model is obtained based on sample text training, and the low-level network is a graph attention layer based on a graph attention mechanism; Inputting all obtained low-level output results into the high-level network to obtain high-level output results of each high-level output node as first classification information corresponding to each preset emotion category, wherein the high-level output result output by each high-level output node represents: the possibility that the emotion expressed in the text to be classified belongs to the preset emotion category corresponding to the high-level output node; Based on the obtained pieces of first classification information, a target emotion category to which the emotion expressed by the to-be-classified text belongs is determined from preset emotion categories.
2. The method according to claim 1, characterized in that The text sentiment classification model is a graph attention capsule network model.
3. The method according to claim 1, characterized in that The step of determining, based on the obtained first classification information, a target emotion category to which the emotion expressed by the to-be-classified text belongs from preset emotion categories includes: Based on the obtained first classification information, second classification information is obtained, indicating the possibility that the emotion expressed by the text to be classified belongs to each preset emotion category; Based on the second classification information, a target emotion category to which the emotion expressed by the to-be-classified text belongs is determined from preset emotion categories.
4. The method according to claim 1, wherein The step of inputting the character semantic information and the syntactic structure information of each character into a pre-trained text sentiment classification model to obtain a low-level output result of a low-level network output contained in the text sentiment classification model comprises: Constructing a text structure graph of the text to be classified based on the character semantic information of each character and the syntactic structure information, wherein each node in the text structure graph corresponds to a character in the text to be classified, the node value of each node is the character semantic information of the character corresponding to the node, and the character corresponding to the first of any two interconnected nodes in the text structure graph is used to modify the character corresponding to the second node; The text structure graph is input into a pre-trained text sentiment classification model to obtain a low-level output result of a low-level network output contained in the text sentiment classification model.
5. The method according to any one of claims 1 to 4, characterized in that The acquiring, based on the position of each character in the text to be classified, syntactic structure information representing the syntactic structure of the text to be classified includes: Based on the position of each character in the text to be classified, a dependency syntax tree of the text to be classified is constructed as the syntactic structure information of the text to be classified, wherein each node in the dependency syntax tree corresponds to a character of the text to be classified, and the character corresponding to the third node of any two interconnected nodes in the dependency syntax tree is used to modify the character corresponding to the fourth node.
6. A text sentiment classification device, characterized in that: The device comprises: A first information acquisition module is configured to obtain, for each character in the text to be classified, a character tensor representing each character in the text to be classified and a position tensor representing the position of each character in the text to be classified according to the character and the position of the character in the text to be classified, wherein the character tensor contains the character vector of each character in the text to be classified, and the position tensor contains the position vector of each character in the text to be classified; sequentially perform a splicing operation on each character vector in the character tensor and each position vector in the position tensor, and use the spliced result as the input of the model to obtain a semantic tensor, wherein the semantic vector of each character contained in the semantic tensor serves as the character semantic information of each character; a second information acquisition module, configured to acquire syntactic structure information representing the syntactic structure of the text to be classified based on the position of each character in the text to be classified; The emotion category determination module is used to input the character semantic information of each character and the syntactic structure information into a pre-trained text emotion classification model, obtain the low-level output results of the low-level network output contained in the text emotion classification model, as the text semantic information representing the semantics of the text to be classified, wherein each low-level output node of the low-level network outputs a low-level output result respectively, and the text emotion classification model also includes a high-level network, each high-level output node contained in the high-level network corresponds to a preset emotion category, the text emotion classification model is obtained based on sample text training, and the low-level network is a graph attention layer based on a graph attention mechanism; all the obtained low-level output results are input into the high-level network, and the high-level output results of each high-level output node are obtained as the first classification information corresponding to each preset emotion category, wherein the high-level output result output by each high-level output node represents: the possibility that the emotion expressed by the text to be classified belongs to the preset emotion category corresponding to the high-level output node; based on the obtained first classification information, determine the target emotion category to which the emotion expressed by the text to be classified belongs from the preset emotion category.
7. An electronic device, characterized in that: It includes a processor, a communication interface, a memory and a communication bus, wherein the processor, the communication interface and the memory communicate with each other via the communication bus; Memory for storing computer programs; A processor, configured to implement the method steps described in any one of claims 1 to 5 when executing a program stored in a memory.
8. A computer-readable storage medium, characterized in that The computer-readable storage medium stores a computer program, and when the computer program is executed by a processor, the method steps described in any one of claims 1 to 5 are implemented.
Citation Information
Patent Citations
Sentiment classification method and device, storage medium and computer equipment
CN113449110A
A multi-language sentiment classification method, device and equipment based on a capsule network and a storage medium
CN113792143A