Text classification method and device, equipment and storage medium
By calculating the distance between the target word and the aspect word and determining the attenuation coefficient, the problem of low accuracy of emotion classification in the prior art is solved, more accurate emotion analysis is achieved, and user experience is improved.
Patent Information
- Application Number
- CN202410074816.2
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2024-01-18
- Publication Date
- 2025-07-18
AI Technical Summary
The existing text classification methods are difficult to effectively combine text timing information in emotion analysis, resulting in low accuracy of emotional classification, especially the emotional judgment of aspect words is easily affected by words that are far away from aspect words.
By calculating the distance between the target word and the aspect word, determining the attenuation coefficient, using a pre-trained text classification model to predict emotional tendencies, reducing the impact of words that are far away from the aspect word on emotion analysis, and highlighting the role of local context.
It improves the accuracy of emotion classification and enhances the accuracy of emotion analysis, especially in the fine-grained emotion analysis at the aspect level, improving the user experience.
Smart Images

Figure CN120336904A_ABST
Abstract
Description
Technical Field
[0001] The present disclosure relates to the technical field of text classification, and in particular, to a text classification method, apparatus, device, and storage medium. Background Art
[0002] With the development of Internet technology, users can publish text comments on different aspects on the Internet, such as product evaluations and thing comments. Based on such text comments, not only can the emotional tendency of users be understood, but also it can play an auxiliary role in other text application fields.
[0003] In the context of the information society, the number of text comments is huge, and it is impossible to solely rely on human power to judge the emotional tendency contained in the text. Currently, the mainstream and effective method is to implement it based on artificial intelligence. Currently, text classification is mostly achieved through deep networks, such as CNN networks and RNN networks. However, although the CNN network can effectively perform feature extraction, it ignores the temporal information of the text. While the RNN network can exploit the temporal information in the text by virtue of the memory module, it is only limited to the stage of separately modeling the context or aspect words, which is very likely to affect the accuracy of the emotional analysis contained in the text. Summary of the Invention
[0004] To solve the above technical problems, the present disclosure provides a text classification method, apparatus, device, and storage medium, which effectively improve the accuracy of emotional classification.
[0005] In a first aspect, an embodiment of the present disclosure provides a text classification method, including:
[0006] Obtain an input text, where the input text includes an aspect word and an emotion word with an emotional attribute;
[0007] Calculate the distance between a target word included in the input text and the aspect word to obtain a target distance, where the target word is at least part of the words included in the input text, and the at least part of the words includes the emotion word;
[0008] Calculate an attenuation coefficient of the target word based on a preset coefficient corresponding to the magnitude relationship between the target distance and a preset distance, where the attenuation coefficient is used to represent the influence degree of the target word on the emotional judgment of the aspect word;
[0009] Predict an emotional tendency according to the input text and the attenuation coefficient through a pre-trained text classification model, and obtain an emotional type corresponding to the aspect word.
[0010] Optionally, the calculating the distance between a target word included in the input text and the aspect word to obtain a target distance includes:
[0011] Determine the first position of the target word in the input text, and determine the second position according to the position of the aspect word in the input text;
[0012] Calculate the difference between the first position and the second position to obtain a first value;
[0013] Calculate the distance between the target word and the aspect word according to a preset value, the first value, and the number of words included in the aspect word to obtain the target distance.
[0014] Optionally, the determining the second position according to the position of the aspect word in the input text includes:
[0015] In the case where the aspect word includes one word, determine the position of the aspect word in the input text as the second position; or,
[0016] In the case where the aspect word includes multiple words, determine the position of each word in the input text, and calculate the sum value of the positions of each word to obtain a second value; determine the ratio of the second value to the number of the multiple words as the second position.
[0017] Optionally, the calculating the attenuation coefficient of the target word based on the size relationship between the target distance and a preset distance and the corresponding preset coefficient includes:
[0018] Determine the number of preset distances to be obtained according to the number of sentences included in the input text, and form multiple distance ranges according to different numbers of preset distances;
[0019] Set the preset coefficient corresponding to the target distance range in which the target distance is located among the multiple distance ranges as the first coefficient of the target word;
[0020] Calculate the ratio of the difference between a preset threshold and the first value to the preset threshold to obtain the second coefficient of the target word;
[0021] Calculate the attenuation coefficient of the target word according to the first coefficient and the second coefficient.
[0022] Optionally, the multiple distance ranges include a first range and a second range, the preset coefficients include a first threshold corresponding to the first range and a second threshold corresponding to the second range, and the setting the preset coefficient corresponding to the target distance range in which the target distance is located among the multiple distance ranges as the first coefficient of the target word includes:
[0023] In the case where the target distance range is the first range, set the first threshold as the first coefficient of the target word;
[0024] When the target distance range is the second range, set the second threshold to the first coefficient, where the first threshold and the second threshold are different.
[0025] Optionally, calculating the attenuation coefficient of the target word according to the first coefficient and the second coefficient includes:
[0026] Calculating the product of the first coefficient and the second coefficient to obtain the attenuation coefficient of the target word; or,
[0027] Calculating the sum value or weighted sum value of the first coefficient and the second coefficient to obtain the attenuation coefficient.
[0028] Wherein, the text classification model includes a representation module, a description module, and a classification module.
[0029] Optionally, predicting the sentiment tendency according to the input text and the attenuation coefficient through a pre-trained text classification model to obtain the sentiment type corresponding to the aspect word includes:
[0030] Taking the input text as the input of the representation module, and extracting context features through the representation module to generate a representation vector;
[0031] Taking the representation vector and the attenuation coefficient as the input of the description module, and capturing the influence of the sentiment word on the aspect word through the description module to generate a sentence representation of each sentiment type;
[0032] Obtaining the distribution of sentiment polarity based on the sentence representation through the classification module to obtain the sentiment type corresponding to the aspect word.
[0033] Second aspect, an embodiment of the present disclosure provides a text classification device, including:
[0034] An acquisition unit for acquiring an input text, where the input text includes an aspect word and a sentiment word with a sentiment attribute;
[0035] A first calculation unit for calculating the distance between a target word included in the input text and the aspect word to obtain a target distance, where the target word is at least part of the words included in the input text, and the at least part of the words includes the sentiment word;
[0036] A second calculation unit for calculating the attenuation coefficient of the target word based on a preset coefficient corresponding to the magnitude relationship between the target distance and a preset distance, where the attenuation coefficient is used to characterize the influence degree of the target word on the sentiment judgment of the aspect word;
[0037] A prediction unit, configured to predict a sentiment tendency according to the input text and the attenuation coefficient by using a pre-trained text classification model, so as to obtain a sentiment type corresponding to the aspect term.
[0038] In a third aspect, an embodiment of the present disclosure provides an electronic device, including:
[0039] A memory;
[0040] A processor; and
[0041] A computer program;
[0042] wherein the computer program is stored in the memory and is configured to be executed by the processor to implement the text classification method as described above.
[0043] In a fourth aspect, an embodiment of the present disclosure provides a computer-readable storage medium, on which a computer program is stored, and when the computer program is executed by a processor, the steps of the text classification method as described above are implemented.
[0044] An embodiment of the present disclosure provides a text classification method, including: obtaining an input text, where the input text includes an aspect term and a sentiment term with a sentiment attribute; calculating a distance between a target word included in the input text and the aspect term to obtain a target distance, where the target word is at least part of the words included in the input text, and the at least part of the words includes the sentiment term; calculating an attenuation coefficient of the target word based on a preset coefficient corresponding to a magnitude relationship between the target distance and a preset distance, where the attenuation coefficient is used to represent an influence degree of the target word on the sentiment judgment of the aspect term; predicting a sentiment tendency according to the input text and the attenuation coefficient by using a pre-trained text classification model, so as to obtain a sentiment type corresponding to the aspect term. The method provided by the present disclosure determines the attenuation coefficient of each target word in the input text by calculating the semantic relative distance between each target word and the aspect term, reduces the influence of other words far from the aspect term on the aspect term by comparing the attenuation coefficients, highlights the role of local context, improves the accuracy of sentiment analysis, and is also convenient for subsequent users to adjust according to accurate classification results, effectively improving the user experience. BRIEF DESCRIPTION OF THE DRAWINGS
[0045] The drawings herein are incorporated into the specification and constitute a part of the specification, showing embodiments consistent with the present disclosure, and are used together with the specification to explain the principles of the present disclosure.
[0046] In order to more clearly illustrate the technical solutions in the embodiments of the present disclosure or the prior art, the following will briefly introduce the drawings required for use in the description of the embodiments or the prior art. Obviously, for those of ordinary skill in the art, other drawings can also be obtained based on these drawings without creative efforts.
[0047] Figure 1 A flowchart of a text classification method provided by an embodiment of the present disclosure;
[0048] Figure 2 A structural diagram of a text classification model provided by an embodiment of the present disclosure;
[0049] Figure 3 A flowchart of another text classification method provided by an embodiment of the present disclosure;
[0050] Figure 4 A structural diagram of a text classification device provided by an embodiment of the present disclosure;
[0051] Figure 5 A structural diagram of an electronic device provided by an embodiment of the present disclosure. Detailed implementation manners
[0052] In order to more clearly understand the above objects, features, and advantages of the present disclosure, the solutions of the present disclosure will be further described below. It should be noted that, without conflict, the embodiments of the present disclosure and the features in the embodiments may be combined with each other.
[0053] In the following description, many specific details are set forth to facilitate a thorough understanding of the present disclosure, but the present disclosure may be implemented in other ways different from those described herein; obviously, the embodiments in the specification are only a part of the embodiments of the present disclosure, rather than all the embodiments.
[0054] In people's expression habits, they usually describe the mentioned things quickly, so the sentiment words that can affect the mentioned aspect words are almost all near the aspect words. For example, in “The price is reasonable although the service is poor”, when the model wants to judge the sentiment polarity of the aspect word “price”, the sentiment word “reasonable” can better reflect the polarity of “price” compared to words such as “although” and “service”, while the distant “poor” may even have a wrong impact on the classification of “price”, resulting in poor accuracy of artificial intelligence in predicting sentiment categories.
[0055] In view of the above technical problems, the present disclosure provides a text classification method. In a text classification task, when an aspect term appears in a sentence, the adjacent words of the aspect term in the sentence receive more attention than other long-distance words, that is, the adjacent words have a greater emotional impact on the aspect term. Therefore, by calculating the distance between each target word and the aspect term and constructing a position attenuation function to reduce the influence of words far from the aspect term on the aspect term, the role of local context in the text is highlighted. The determination of the local context depends on the semantic relative distance. This position attenuation method can effectively improve the accuracy of sentiment classification. In addition, performing aspect-level fine-grained sentiment analysis on the text is very important for both the improvement of the merchant itself and helping customers make more accurate judgments, effectively improving the user experience. It will be described in detail through at least one of the following embodiments.
[0056] Specifically, the text classification method can be executed by a terminal or a server. Specifically, the terminal or the server can perform sentiment classification on the aspect terms in the input text through a text classification model.
[0057] For example, in an application scenario, the server trains the text classification model. The terminal obtains the trained text classification model from the server, and the terminal performs sentiment classification on the aspect terms in the input text through the trained text classification model. The input text can be obtained by the terminal. Or, the input text is obtained by the terminal from other devices. Or, the input text is the text obtained after the terminal processes a preset text. The preset text can be obtained by the terminal, or the preset text can be obtained by the terminal from other devices. Here, no specific limitation is imposed on other devices.
[0058] In another application scenario, the server trains the text classification model. Further, the server performs sentiment classification on the aspect terms in the input text through the trained text classification model. The way for the server to obtain the input text can be similar to the way for the terminal to obtain the input text as described above, which will not be elaborated here.
[0059] It can be understood that the text classification method provided by the embodiments of the present disclosure is not limited to the above several possible scenarios. Taking the server executing the text classification method as an example below, a text classification method will be introduced. It can be understood that this text classification method is also applicable to the scenario where the terminal performs sentiment classification.
[0060] Figure 1 It is a schematic flowchart of a text classification method provided by an embodiment of the present disclosure, specifically including the following steps S101 to S104 as Figure 1 shown:
[0061] S101. Obtain the input text.
[0062] Among them, the input text includes aspect words and sentiment words with sentiment attributes.
[0063] Understandably, the input text is obtained. The input text can be the text information directly input by the user, or the input text is the information recognized by the server according to at least one of the information of audio, voice, and image input by the user. The specific acquisition method of the input text is not limited and can be determined according to the user's needs. The input text includes multiple words, and the multiple words can be single words or combined words. The multiple words include aspect words, sentiment words with sentiment attributes, and other words. For example, the input text is "The sound system in this car is exceptional, but the fuel efficiency leaves much to be desired". This input text includes two sentences. Among them, in the first sentence, "sound system" is an aspect word, which refers to the aspect of the vehicle audio system. This aspect word is a combined word composed of 2 words, and "exceptional" is a sentiment word. This sentiment word is a single word and is an evaluation word for the audio system. In the second sentence, "fuel efficiency" is an aspect word, which refers to the aspect of the vehicle fuel efficiency, and "desired" is a sentiment word, which is an evaluation word for the fuel efficiency.
[0064] S102. Calculate the distance between the target word included in the input text and the aspect word to obtain the target distance.
[0065] Among them, the target word is at least part of the words included in the input text, and the at least part of the words includes the sentiment word.
[0066] Understandably, on the basis of the above S101, at least one target word is determined in the input text. The target word refers to each word included in the input text, or some words in the input text, or each sentiment word included in the input text. Among them, the aspect word can be distinguished from the context by using an aspect indicator. The specific construction and implementation method of the aspect indicator are not limited. The following embodiments will be described in detail taking each word included in the input text as the target word as an example. Calculate the distance between each target word and the aspect word to obtain the target distance corresponding to each target word, that is, the target word and the target distance are in one-to-one correspondence.
[0067] Optionally, the step of calculating the distance between the target word included in the input text and the aspect word in S102 to obtain the target distance can be specifically implemented through the following steps:
[0068] Determine the first position of the target word in the input text, and determine the second position according to the position of the aspect word in the input text; calculate the difference between the first position and the second position to obtain a first value; calculate the distance between the target word and the aspect word according to a preset value, the first value, and the number of words included in the aspect word to obtain the target distance.
[0069] It can be understood that for each target word, to determine the first position of the target word in the input text, the positions of each word can be determined sequentially starting from 0 in the input text. Based on the above example, the first position of the target word "exceptional" in the input text is 7. Determine the position of each aspect word in the input text, and calculate the second position according to the position of each aspect word. The second position can be understood as the position of the center of the aspect word. It is understandable that the order of determining the first position and the second position is not limited and can be determined according to user needs. Subsequently, calculate the difference between the first position and the second position and take the absolute value to obtain a first value. After determining the first value, count the number of aspect words included in the input text, or count how many single words (words) each aspect word is composed of. Based on the above example, the aspect word "soundsystem" is composed of 2 words "sound" and "system". Calculate the distance between the target word and the aspect word according to the number of words included in the aspect word, the preset value, and the first value to obtain the target distance. After calculating the distance for each target word, multiple target distances can be obtained.
[0070] Optionally, the above-mentioned determining the second position according to the position of the aspect word in the input text can be specifically implemented through the following steps:
[0071] In the case where the aspect word includes one word, determine the position of the aspect word in the input text as the second position; or, in the case where the aspect word includes multiple words, determine the position of each word in the input text, and calculate the sum value of the positions of each word to obtain a second value; determine the ratio of the second value to the number of the multiple words as the second position.
[0072] Understandably, when the aspect word only includes one word, that is, the aspect word is a single word, in this case, directly determine the position of the aspect word in the input text as the first position. When the aspect word includes multiple words, that is, the aspect word is a compound word, in this case, determine the position of each word in the multiple words in the input text, and calculate the sum value of each word position to obtain the second value. Based on the above example, the position of "sound" in the input text is 1, and the position of "system" in the input text is 2. Calculate the sum value of the positions of the 2 words as 3, that is, the second value is 3. Subsequently, calculate the second position according to the second value and the number of multiple words. Based on the above example, the number of multiple words is 2, and the ratio of the second value to the number of multiple words can be calculated to obtain the second value, that is, the calculated second position is 3 / 2 = 1.5. The calculation formula for the second position is (1 + 2) / 2 = 1.5. Specifically, the calculation formula for the target distance is as shown in formula (1).
[0073] dst = |i - aspect| - |lengh / 2| Formula (1)
[0074] In the formula, dst is the target distance, i refers to the position of the target word in the input text, that is, the first position, aspect is the position of the center of the aspect word, that is, the second position, lengh is the number of words included in the aspect word, and 2 is a preset value.
[0075] Exemplarily, the distance between the target word "exceptional" and the aspect word "sound system" based on the calculation result of formula (1) is: dst = |7 - (1 + 2) / 2| - |2 / 2| = 4.5, that is, the target distance is 4.5.
[0076] S103. Calculate the attenuation coefficient of the target word according to the preset coefficient corresponding to the magnitude relationship between the target distance and the preset distance.
[0077] Among them, the attenuation coefficient is used to characterize the influence degree of the emotional judgment of the target word on the aspect word.
[0078] Understandably, based on S102 above, obtain the preset distance. The preset distance can be input by the user or randomly set before predicting the emotional type. Subsequently, calculate the attenuation coefficient of each target word according to the target distance and the second value calculated above. The following embodiments will be used for detailed description.
[0079] S104. Predict the emotional tendency according to the input text and the attenuation coefficient through a pre-trained text classification model to obtain the emotional type corresponding to the aspect word.
[0080] It is understandable that, based on the above S103, the input text is used as the input of the text classification model, and the attenuation coefficient is calculated through the above steps inside the text classification model, or after separately calculating the attenuation coefficient, the input text and the attenuation coefficient are jointly used as the input of the text classification model. Subsequently, the text classification model predicts the sentiment tendency based on the input text and the attenuation coefficient, that is, predicts the sentiment polarity commented on by the input text for the aspect word, and outputs the predicted sentiment type. The model prediction effect is relatively good through the position attenuation strategy, where the sentiment type or sentiment tendency includes positive, neutral, and negative. Other refined sentiment tendencies are not elaborated here and can be determined according to user needs.
[0081] Among them, the text classification model includes a representation module, a description module, and a classification module.
[0082] Optionally, in the above S104, predicting the sentiment tendency based on the input text and the attenuation coefficient through a pre-trained text classification model to obtain the sentiment type corresponding to the aspect word can be specifically implemented through the following steps:
[0083] Taking the input text as the input of the representation module, extracting context features through the representation module to generate a representation vector; taking the representation vector and the attenuation coefficient as the input of the description module, capturing the influence of the sentiment word on the aspect word through the description module to generate a sentence representation for each sentiment type; obtaining the distribution of sentiment polarities based on the sentence representation through the classification module to obtain the sentiment type corresponding to the aspect word.
[0084] Exemplarily, referring to Figure 2 , Figure 2 is a schematic structural diagram of a text classification model provided by an embodiment of the present disclosure. The text classification model includes a representation module, a description module, and a classification model. Among them, the representation module includes an input module and a context representation module. The input module consists of a word embedding vector (Word Embedding) and an embedding vector of an aspect indicator (AspectIndicator Embedding). The embedding of the aspect indicator is used to distinguish the aspect word from the context, and this vector is randomly initialized. The final input representation is: Among them, is the word embedding vector, is the embedding vector of the aspect indicator. The context representation module (Bi-GRU) can use a bidirectional GRU to generate the context representation. Since the input representation output by the input module already includes the vector information of the aspect word, the context representation of a specific aspect can be obtained by concatenating the hidden states in two directions, that is The representation vector representing the module output includes the input representation xt and the context representation ht. The text classification model also includes a position decay module (Decay Function), which is used to calculate the decay coefficient of the input text through the above steps, or the text classification model obtains the decay coefficient from the position decay module. The description module (CRF) can use multiple linear-chain CRFs to centrally combine structural dependencies to capture the corresponding opinion spans of one aspect. In particular, a potential label z ∈ {Yes, No} is set to indicate whether each context word belongs to a part of the opinion range. For a sentence expression x, the definition of the CRF is shown in formulas (2) and (3):
[0085]
[0086]
[0087] In the formula, T is a transition matrix, denotes the transition score from label z t to z t+1 . denotes the emission score of label z t at the t-th position. The score is obtained from a linear layer that takes h t1 as input and returns a vector of the size of the label. The potential label introduced in the CRF layer shows whether the target word affects the sentiment of a specific aspect. It can be understood that the marginal probability on the "1" label represents the influence of the target word on the sentiment of the aspect word. By using the forward-backward algorithm, the marginal distribution of the potential label is calculated. According to the marginal distribution, the sentence representation s is obtained as shown in formula (4):
[0088]
[0089] It can be understood that by concatenating the sentence representations of all CRFs, where a is the number of CRFs, the final representation (sentence representation) of the sentiment classification q is q = [s1; s2;...; s a .
[0090] It can be understood that after obtaining the sentence representation, the sentence representation q is passed to the sentiment classifier to obtain the distribution of sentiment polarities, as shown in formula (5):
[0091] P(y|q) = Softmax(W q + b) Formula (5)
[0092] In the formula, P is the output result of the model, the specific sentiment type, y represents the specific aspect word, W and b are learnable parameters, and the model parameters of the text classification model can be learned by minimizing the negative log-likelihood.
[0093] The text classification method provided by the embodiments of the present disclosure calculates the distance between each target word and the central position of the aspect word, and calculates the attenuation coefficient by using different attenuation strategies based on the distance, highlighting the local context features in the text and effectively improving the accuracy of sentiment classification regarding the aspect word.
[0094] Based on the above embodiments, Figure 3 FIG. is a schematic flowchart of another text classification method provided by the embodiments of the present disclosure. Optionally, calculating the attenuation coefficient of the target word based on the preset coefficient corresponding to the size relationship between the target distance and the preset distance specifically includes the following steps S301 to S304 as Figure 3 shown:
[0095] S301. Determine the number of preset distances to be obtained according to the number of sentences included in the input text, and form multiple distance ranges according to different numbers of preset distances.
[0096] It can be understood that to determine the number of sentences included in the input text, based on the above example, the input text includes 2 sentences “The sound system in this car is exceptional” and “but the fuel efficiency leaves much to be desired”. Based on the number of sentences, determine the number of preset distances to be obtained. For example, in the case of including 2 sentences, 1 preset distance can be obtained, and this preset distance can be input by the user. Or, the user can determine the number of preset distances by themselves and input specific preset distances. After determining the number of preset distances and each preset distance, divide multiple distance ranges according to the size of each preset distance. Based on the above example, if the preset distance is 5, 2 distance ranges can be divided, that is, 0 - 5 and 5 - the maximum target distance. It can be understood that the number and specific values of the preset distances can be adjusted by the user according to the sentiment classification results later.
[0097] S302. Set the preset coefficient corresponding to the target distance range in which the target distance is located among the multiple distance ranges as the first coefficient of the target word.
[0098] It can be understood that based on the above S301, the first attenuation strategy is to judge the relationship between the target distance and multiple distance ranges, that is, to judge the target distance range in which the target distance is located. Different distance ranges correspond to different attenuation coefficients (preset coefficients), and the preset coefficients can be set by the user themselves. Specifically, use the preset coefficient corresponding to the target distance range in which the target distance is located as the first coefficient.
[0099] Among them, the multiple distance ranges include a first range and a second range, and the preset coefficients include a first threshold corresponding to the first range and a second threshold corresponding to the second range.
[0100] Optionally, setting the preset coefficient corresponding to the target distance range in which the target distance in the multiple distance ranges is located as the first coefficient of the target word in S302 above can be specifically implemented through the following steps:
[0101] When the target distance range is the first range, set the first threshold as the first coefficient of the target word; when the target distance range is the second range, set the second threshold as the first coefficient, where the first threshold and the second threshold are different.
[0102] It is understandable that taking the setting of 1 preset distance as an example, taking 0 - 5 as the first range and 5 - the maximum target distance as the second range. When the target distance is within the first range, that is, when the target distance is less than or equal to the preset distance 5, set the first coefficient of the target word as the first threshold corresponding to the first range, indicating that the target word is relatively close to the aspect word and has a greater impact on the aspect word. When the target distance is within the second range, that is, when the target distance is greater than the preset distance 5, set the first coefficient of the target word as the second threshold corresponding to the second range, indicating that the target word is relatively far from the aspect word. Specifically, for each target word, the determination method of the first coefficient is shown in formula (6):
[0103]
[0104] In the formula, p1 is the first coefficient, dst is the target distance, limit is the preset distance, 1 is the first threshold, and 0 is the second threshold.
[0105] Exemplarily, when the preset distance is 5, the first coefficients P1 of all words included in the input text are [1, 1, 1, 1, 1, 1, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0].
[0106] S303. Calculate the ratio of the difference between the preset threshold and the first value to the preset threshold to obtain the second coefficient of the target word.
[0107] It is understandable that on the basis of the above example, the second attenuation strategy is to retain the positions other than the aspect word in a decaying manner. Specifically, calculate the difference between the preset threshold and the first value, and calculate the ratio of this difference to the preset threshold, that is, calculate the probability value of the first value, to obtain the second coefficient of the target word. The first value specifically refers to the difference between the target word and the central position of the aspect word. It can be specifically calculated through formula (7) shown below.
[0108]
[0109] In the formula, p2 is the second coefficient, aspect is the position of the center of the aspect word, that is, the second position, word is the first position of the target word, and 100 is a preset threshold.
[0110] Exemplarily, the second coefficients of all the words included in the input text are P2 as [0.985, 1, 1, 0.985, 0.975, 0.965, 0.955, 0.945, 0.935, 0.925, 0.915, 0.905, 0.895, 0.885, 0.875, 0.865, 0.855].
[0111] S304. Calculate the attenuation coefficient of the target word according to the first coefficient and the second coefficient.
[0112] Optionally, in S304 above, calculating the attenuation coefficient of the target word according to the first coefficient and the second coefficient can be specifically implemented through the following steps:
[0113] Calculate the product of the first coefficient and the second coefficient to obtain the attenuation coefficient of the target word; or calculate the sum value or weighted sum value of the first coefficient and the second coefficient to obtain the attenuation coefficient.
[0114] It can be understood that on the basis of S303 and S302 above, the above two attenuation strategies are connected in series as the input of the next layer (description module). Specifically, the product of the first coefficient and the second coefficient can be calculated to obtain the attenuation coefficient, that is, p1 * p2 = O(t), where O(t) is the attenuation coefficient of all the words included in the input text. On the basis of the above example, O(t) is [0.985, 1, 1, 0.985, 0.975, 0.965, 0.955, 0.945, 0, 0, 0, 0, 0, 0, 0, 0, 0]. Or, the sum value or weighted sum of the first coefficient and the second coefficient can also be calculated to obtain the attenuation coefficient. The manner of determining the total attenuation coefficient of the input text based on multiple strategies is not limited and can be determined according to user needs.
[0115] The text classification method provided by the embodiments of the present disclosure determines the first coefficient by comparing the preset distance and the target distance, fully retains the context information of the content within the preset distance, and cuts off all context information exceeding the preset distance to reduce the influence of distant sentiment words on the sentiment analysis of aspect words. At the same time, other words except the aspect word are retained in a position attenuation manner, and multiple attenuation strategies are combined to more comprehensively and accurately highlight the role of local context.
[0116] Figure 4The structural schematic diagram of the text classification device provided by the embodiments of the present disclosure. The text classification device provided by the embodiments of the present disclosure can execute the processing flow provided by the above-mentioned text classification method embodiments and is applied to the above-mentioned text classification method, such as Figure 4 As shown in the figure, the device 400 includes an acquisition unit 401, a first calculation unit 402, a second calculation unit 403, and a prediction unit 404, where:
[0117] The acquisition unit 401 is configured to acquire an input text, where the input text includes an aspect word and a sentiment word with a sentiment attribute;
[0118] The first calculation unit 402 is configured to calculate the distance between a target word included in the input text and the aspect word to obtain a target distance, where the target word is at least part of the words included in the input text, and the at least part of the words includes the sentiment word;
[0119] The second calculation unit 403 is configured to calculate an attenuation coefficient of the target word based on a preset coefficient corresponding to the magnitude relationship between the target distance and a preset distance, where the attenuation coefficient is used to characterize the influence degree of the target word on the sentiment judgment of the aspect word;
[0120] The prediction unit 404 is configured to predict a sentiment tendency based on the input text and the attenuation coefficient through a pre-trained text classification model to obtain a sentiment type corresponding to the aspect word.
[0121] Optionally, the first calculation unit 402 is configured to:
[0122] Determine a first position of the target word in the input text, and determine a second position according to the position of the aspect word in the input text;
[0123] Calculate a difference between the first position and the second position to obtain a first value;
[0124] Calculate the distance between the target word and the aspect word according to a preset value, the first value, and the number of words included in the aspect word to obtain the target distance.
[0125] Optionally, the first calculation unit 402 is configured to:
[0126] In the case where the aspect word includes one word, determine the position of the aspect word in the input text as the second position; or,
[0127] In the case where the aspect word includes multiple words, determine the position of each word in the input text, and calculate a sum value of the positions of each word to obtain a second value; determine a ratio of the second value to the number of the multiple words as the second position.
[0128] Optionally, the second calculation unit 403 is configured to:
[0129] Determine the number of preset distances to be obtained according to the number of statements included in the input text, and form multiple distance ranges according to different numbers of preset distances;
[0130] Set the preset coefficient corresponding to the target distance range in which the target distance is located among the multiple distance ranges as the first coefficient of the target word;
[0131] Calculate the ratio of the difference between the preset threshold and the first value to the preset threshold to obtain the second coefficient of the target word;
[0132] Calculate the attenuation coefficient of the target word according to the first coefficient and the second coefficient.
[0133] Among them, the multiple distance ranges include a first range and a second range, and the preset coefficients include a first threshold corresponding to the first range and a second threshold corresponding to the second range.
[0134] Optionally, the second calculation unit 403 is configured to:
[0135] In the case where the target distance range is the first range, set the first threshold as the first coefficient of the target word;
[0136] In the case where the target distance range is the second range, set the second threshold as the first coefficient, where the first threshold and the second threshold are different.
[0137] Optionally, the second calculation unit 403 is configured to:
[0138] Calculate the product of the first coefficient and the second coefficient to obtain the attenuation coefficient of the target word; or,
[0139] Calculate the sum value or weighted sum value of the first coefficient and the second coefficient to obtain the attenuation coefficient.
[0140] Among them, the text classification model includes a representation module, a description module, and a classification module.
[0141] Optionally, the prediction unit is configured to:
[0142] Use the input text as the input of the representation module, and extract context features through the representation module to generate a representation vector;
[0143] Use the representation vector and the attenuation coefficient as the input of the description module, and capture the influence of sentiment words on aspect words through the description module to generate a sentence representation of each sentiment type;
[0144] Based on the sentence representation, the classification module obtains the distribution of sentiment polarities, and determines the sentiment types corresponding to the aspect words.
[0145] Figure 4 The text classification device in the illustrated embodiment can be used to execute the technical solutions in the above method embodiments. The implementation principles and technical effects are similar and will not be elaborated here.
[0146] Figure 5 The following is a schematic structural diagram of an electronic device provided by an embodiment of the present disclosure. Specifically referring to Figure 5 FIG. [FIGURE NUMBER] shows a schematic structural diagram of an electronic device 500 suitable for implementing the present disclosure. The electronic device 500 in the embodiments of the present disclosure may include, but is not limited to, mobile terminals such as mobile phones, laptop computers, digital broadcast receivers, PDAs (Personal Digital Assistants), PADs (Tablet Computers), PMPs (Portable Multimedia Players), vehicle terminals (such as vehicle navigation terminals), wearable electronic devices, etc., and fixed terminals such as digital TVs, desktop computers, smart home devices, etc. Figure 5 The electronic device shown is merely an example and should not impose any limitations on the functions and usage scope of the embodiments of the present disclosure.
[0147] As Figure 5 shown, the electronic device 500 may include a processing device (such as a central processing unit, a graphics processing unit, etc.) 501, which can perform various appropriate actions and processes according to a program stored in a read-only memory (ROM) 502 or a program loaded from a storage device 508 into a random access memory (RAM) 503 to implement the text classification method of the embodiments as described in the present disclosure. In the RAM 503, various programs and data required for the operation of the electronic device 500 are also stored. The processing device 501, the ROM 502, and the RAM 503 are connected to each other through a bus 504. An input / output (I / O) interface 505 is also connected to the bus 504.
[0148] Generally, the following devices may be connected to the I / O interface 505: an input device 506 including, for example, a touch screen, a touchpad, a keyboard, a mouse, a camera, a microphone, an accelerometer, a gyroscope, etc.; an output device 507 including, for example, a liquid crystal display (LCD), a speaker, a vibrator, etc.; a storage device 508 including, for example, a magnetic tape, a hard disk, etc.; and a communication device 509. The communication device 509 may allow the electronic device 500 to communicate with other devices wirelessly or wiredly to exchange data. Although Figure 5 FIG. [FIGURE NUMBER] shows an electronic device 500 having various devices, it should be understood that it is not required to implement or include all the shown devices. More or fewer devices may be alternatively implemented or included.
[0149] In particular, according to an embodiment of the present disclosure, the processes described above with reference to the flowchart can be implemented as a computer software program. For example, an embodiment of the present disclosure includes a computer program product that includes a computer program carried on a non-transitory computer-readable medium. The computer program includes program code for performing the method shown in the flowchart, thereby implementing the text classification method as described above. In such an embodiment, the computer program can be downloaded and installed from the network via the communication device 509, or installed from the storage device 508, or installed from the ROM 502. When the computer program is executed by the processing device 501, the above-described functions defined in the method of the embodiment of the present disclosure are performed.
[0150] It should be noted that the computer-readable medium in the present disclosure can be a computer-readable signal medium, a computer-readable storage medium, or any combination of the two. The computer-readable storage medium can be, for example, but not limited to, an electrical, magnetic, optical, electromagnetic, infrared, or semiconductor system, apparatus, or device, or any combination of the above. More specific examples of the computer-readable storage medium can include, but are not limited to: an electrical connection with one or more wires, a portable computer disk, a hard disk, a random access memory (RAM), a read-only memory (ROM), an erasable programmable read-only memory (EPROM or flash memory), an optical fiber, a portable compact disk read-only memory (CD-ROM), an optical storage device, a magnetic storage device, or any suitable combination of the above. In the present disclosure, the computer-readable storage medium can be any tangible medium that contains or stores a program that can be used by or in conjunction with an instruction execution system, apparatus, or device. In the present disclosure, the computer-readable signal medium can include a data signal propagated in a baseband or as part of a carrier wave, which carries computer-readable program code. Such a propagated data signal can take various forms, including but not limited to electromagnetic signals, optical signals, or any suitable combination of the above. The computer-readable signal medium can also be any computer-readable medium other than the computer-readable storage medium, and the computer-readable signal medium can send, propagate, or transmit a program for use by or in conjunction with an instruction execution system, apparatus, or device. The program code contained on the computer-readable medium can be transmitted by any suitable medium, including but not limited to: wires, optical cables, RF (radio frequency), etc., or any suitable combination of the above.
[0151] In some embodiments, the client and the server can communicate using any currently known or future-developed network protocol such as HTTP (HyperText Transfer Protocol), and can be interconnected with digital data communication in any form or medium (e.g., a communication network). Examples of communication networks include local area networks (“LANs”), wide area networks (“WANs”), the Internet (e.g., the Internet), and end-to-end networks (e.g., ad hoc end-to-end networks), as well as any currently known or future-developed networks.
[0152] The above computer-readable medium can be included in the above electronic device; or can exist separately without being assembled into the electronic device.
[0153] Optionally, when the above one or more programs are executed by the electronic device, the electronic device can also perform the other steps described in the above embodiments.
[0154] Computer program code for performing the operations of the present disclosure can be written in one or more programming languages or combinations thereof. The above programming languages include, but are not limited to, object-oriented programming languages such as Java, Smalltalk, C++, and also include conventional procedural programming languages such as the “C” language or similar programming languages. The program code can be executed entirely on the user's computer, partially on the user's computer, executed as a stand-alone software package, partially on the user's computer and partially on a remote computer, or entirely on a remote computer or server. In the case of a remote computer, the remote computer can be connected to the user's computer through any type of network, including a local area network (LAN) or a wide area network (WAN), or can be connected to an external computer (e.g., by using an Internet service provider to connect through the Internet).
[0155] The flowcharts and block diagrams in the accompanying drawings illustrate the architecture, functionality, and operation of possible implementations of systems, methods, and computer program products according to various embodiments of the present disclosure. In this regard, each block in the flowchart or block diagram may represent a module, a segment of a program, or a portion of code that contains one or more executable instructions for implementing a specified logical function. It should also be noted that in some alternative implementations, the functions noted in the blocks may occur in a different order than noted in the drawings. For example, two consecutive blocks shown may actually be executed substantially in parallel, or they may sometimes be executed in the reverse order, depending on the functions involved. It should also be noted that each block in the block diagrams and / or flowcharts, and combinations of blocks in the block diagrams and / or flowcharts, can be implemented by a dedicated hardware-based system that performs the specified functions or operations, or by a combination of dedicated hardware and computer instructions.
[0156] The units involved in the embodiments described in the present disclosure can be implemented in software or in hardware. In some cases, the name of the unit does not constitute a limitation on the unit itself.
[0157] The functions described above herein can be performed at least in part by one or more hardware logic components. By way of example, and without limitation, exemplary types of hardware logic components that can be used include: field-programmable gate arrays (FPGAs), application-specific integrated circuits (ASICs), application-specific standard products (ASSPs), systems on a chip (SOCs), complex programmable logic devices (CPLDs), and the like.
[0158] In the context of the present disclosure, a machine-readable medium may be a tangible medium that can contain or store a program for use by or in connection with an instruction execution system, apparatus, or device. A machine-readable medium may be a machine-readable signal medium or a machine-readable storage medium. A machine-readable medium may include, but is not limited to, electronic, magnetic, optical, electromagnetic, infrared, or semiconductor systems, apparatus, or devices, or any suitable combination of the foregoing. More specific examples of a machine-readable storage medium would include an electrical connection based on one or more wires, a portable computer diskette, a hard disk, a random access memory (RAM), a read-only memory (ROM), an erasable programmable read-only memory (EPROM or Flash memory), an optical fiber, a portable compact disc read-only memory (CD-ROM), an optical storage device, a magnetic storage device, or any suitable combination of the foregoing.
[0159] It should be noted that in this text, relational terms such as "first" and "second" are only used to distinguish one entity or operation from another entity or operation, and do not necessarily require or imply any actual relationship or order between these entities or operations. Moreover, the term "comprising", "including" or any other variant thereof is intended to cover non-exclusive inclusion, such that a process, method, article or text classification method comprising a series of elements includes not only those elements but also other elements not expressly listed, or elements inherent to such process, method, article or text classification method. Without further limitation, an element defined by the statement "comprising an..." does not exclude the presence of additional identical elements in the process, method, article or text classification method comprising the said element.
[0160] The above are only specific embodiments of the present disclosure, enabling those skilled in the art to understand or implement the present disclosure. Various modifications to these embodiments will be obvious to those skilled in the art, and the general principles defined herein can be implemented in other embodiments without departing from the spirit or scope of the present disclosure. Therefore, the present disclosure will not be limited to the embodiments described herein, but rather to the broadest scope consistent with the principles and novel features disclosed herein.
Claims
1. A text classification method, characterized in that, Including: Obtain input text, where the input text includes an aspect word and a sentiment word with a sentiment attribute; Calculate the distance between the target word included in the input text and the aspect word to obtain a target distance, where the target word is at least part of the words included in the input text, and the at least part of the words includes the sentiment word; Calculate the attenuation coefficient of the target word based on the preset coefficient corresponding to the magnitude relationship between the target distance and the preset distance, where the attenuation coefficient is used to characterize the influence degree of the target word on the sentiment judgment of the aspect word; Predict the sentiment tendency according to the input text and the attenuation coefficient through a pre-trained text classification model to obtain the sentiment type corresponding to the aspect word.
2. The method according to claim 1, characterized in that, The calculating the distance between the target word included in the input text and the aspect word to obtain a target distance includes: Determine the first position of the target word in the input text, and determine the second position according to the position of the aspect word in the input text; Calculate the difference between the first position and the second position to obtain a first value; Calculate the distance between the target word and the aspect word according to the preset value, the first value, and the number of words included in the aspect word to obtain the target distance.
3. The method according to claim 2, characterized in that The determining the second position according to the position of the aspect word in the input text includes: In the case where the aspect word includes one word, determine the position of the aspect word in the input text as the second position; or, In the case where the aspect word includes multiple words, determine the position of each word in the input text, and calculate the sum value of the positions of each word to obtain a second value; determine the ratio of the second value to the number of the multiple words as the second position.
4. The method according to claim 2, wherein The calculating the attenuation coefficient of the target word based on the preset coefficient corresponding to the magnitude relationship between the target distance and the preset distance includes: Determine the number of preset distances to be obtained according to the number of sentences included in the input text, and form multiple distance ranges according to different numbers of preset distances; Set the preset coefficient corresponding to the target distance range in which the target distance is located among the multiple distance ranges as the first coefficient of the target word; Calculate the ratio of the difference between the preset threshold and the first value to the preset threshold to obtain the second coefficient of the target word; Calculate the attenuation coefficient of the target word according to the first coefficient and the second coefficient.
5. The method according to claim 4, wherein The multiple distance ranges include a first range and a second range, the preset coefficients include a first threshold corresponding to the first range and a second threshold corresponding to the second range, and the setting the preset coefficient corresponding to the target distance range in which the target distance is located among the multiple distance ranges as the first coefficient of the target word includes: In the case where the target distance range is the first range, set the first threshold as the first coefficient of the target word; In the case where the target distance range is the second range, set the second threshold as the first coefficient, where the first threshold and the second threshold are different.
6. The method according to claim 4, wherein The calculating the attenuation coefficient of the target word according to the first coefficient and the second coefficient includes: Calculate the product of the first coefficient and the second coefficient to obtain the attenuation coefficient of the target word; or, Calculate the sum value or weighted sum value of the first coefficient and the second coefficient to obtain the attenuation coefficient.
7. The method according to claim 1, wherein The text classification model includes a representation module, a description module, and a classification module. Predicting the sentiment tendency according to the input text and the attenuation coefficient through the pre-trained text classification model to obtain the sentiment type corresponding to the aspect word includes: Use the input text as the input of the representation module, and extract context features through the representation module to generate a representation vector; Use the representation vector and the attenuation coefficient as the input of the description module, and capture the influence of the sentiment word on the aspect word through the description module to generate a sentence representation of each sentiment type; Obtain the distribution of sentiment polarities based on the sentence representation through the classification module to obtain the sentiment type corresponding to the aspect word.
8. A text classification device, characterized in that, Including: An acquisition unit for acquiring an input text, where the input text includes an aspect word and a sentiment word with a sentiment attribute; A first calculation unit for calculating the distance between the target word included in the input text and the aspect word to obtain a target distance, where the target word is at least part of the words included in the input text, and the at least part of the words includes the sentiment word; A second calculation unit for calculating the attenuation coefficient of the target word based on the preset coefficient corresponding to the magnitude relationship between the target distance and the preset distance, where the attenuation coefficient is used to characterize the influence degree of the target word on the sentiment judgment of the aspect word; A prediction unit for predicting the sentiment tendency according to the input text and the attenuation coefficient through the pre-trained text classification model to obtain the sentiment type corresponding to the aspect word.
9. An electronic device, characterized in that, Including: A memory; A processor; And A computer program; Wherein, the computer program is stored in the memory and is configured to be executed by the processor to implement the text classification method as described in any one of claims 1 to 7.
10. A computer-readable storage medium having a computer program stored thereon, characterized in that, When the computer program is executed by the processor, it implements the steps of the text classification method as described in any one of claims 1 to 7.