Text classification method, apparatus, device, and medium

By representing text and labels using high-dimensional cube quality parameters and calculating the quality of the intersecting parts to determine similarity, this method solves the problems of logical inconsistency and inefficiency in existing hierarchical classification methods, and achieves efficient and accurate text classification and intuitive display of label hierarchical relationships.

CN116578701BActive Publication Date: 2025-11-28PING AN TECH (SHENZHEN) CO LTD
View PDF 2 Cites 0 Cited by

Patent Information

Application Number
CN202310470829.7
Authority / Receiving Office
CN · China
Patent Type
Patents(China)
Current Assignee / Owner
Filing Date
2023-04-24
Publication Date
2025-11-28
Estimated Expiration
2043-04-24

AI Technical Summary

Technical Problem

Existing hierarchical classification methods often produce illogical and inefficient results. Traditional methods fail to effectively utilize the hierarchical structure information of labels, leading to problems with classification accuracy and efficiency.

Method used

The text and labels to be classified are represented by high-dimensional cube quality parameters. The similarity between the text and the labels is determined by calculating the quality of the intersection of the cubes. The hierarchical relationship is represented by the size scaling parameter of the high-dimensional cube, which avoids the defect of hierarchical classification in traditional methods and directly calculates the multi-label classification task.

Benefits of technology

It achieves more efficient and accurate text classification, can intuitively display the hierarchical relationship of labels, improves the accuracy and efficiency of classification results, and allows for the visual inspection of classification accuracy.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN116578701B_ABST
    Figure CN116578701B_ABST
Patent Text Reader

Abstract

The application is suitable for the field of digital medical treatment, and discloses a text classification method. The method comprises the following steps: obtaining a text to be classified and converting the text into a text vector; mapping the text vector into a first cuboid quality parameter and determining the quality of a first cuboid according to the first cuboid quality parameter; obtaining a second cuboid quality parameter of a second cuboid corresponding to a label, wherein the second cuboid quality parameter comprises a size scaling parameter, and the size scaling parameter is used to identify the level of the label; determining the quality of an intersection part of the first cuboid and the second cuboid according to the first cuboid quality parameter and the second cuboid quality parameter; determining a first similarity score between the label and the text to be classified according to the quality of the intersection part and the quality of the first cuboid; and if the first similarity score is greater than a classification threshold, determining that the text belongs to a classification corresponding to the label. The method of the application solves the problems of the existing hierarchical classification method, such as the fact that the classification result does not conform to logic and the fact that the classification efficiency is low.
Need to check novelty before this filing date? Find Prior Art

Description

TECHNICAL FIELD

[0001] The present application relates to the technical field of artificial intelligence and the technical field of digital medicine, in particular to a text classification method, device, equipment and medium. BACKGROUND

[0002] In the natural language processing branch of the field of artificial intelligence, the cognition of text such as text classification is a very common and annually updated task. Text classification refers to inputting a piece of text, and the model needs to label the text according to the content of the text. The text classification task exists in various practical applications, such as medical text classification, news classification, topic classification, question and answer matching, intent recognition, sentiment classification, inference, etc. For example, input text "Is heart rate 72bpm normal?", and the output classification is "cardiology".

[0003] In text classification, there is a special classification task, i.e. hierarchical classification task, and there is a hierarchical relationship between categories. A piece of text usually has multiple labels, including parent and child classes in the hierarchical structure.

[0004] There are two methods for traditional hierarchical classification tasks: 1. Ignore the hierarchical relationship and convert the task into a multi-label classification task; 2. Classify according to the hierarchy, for example, first classify from the highest level, and then classify to the child node after determining the high-level label. However, in the first method, the model does not learn the structure information, and the classification result does not conform to the hierarchical structure logic; in the second method, although the high-level prior knowledge can be used to help the child level to judge, to a certain extent, the defects of the first method are avoided, but the efficiency is too low, and multiple rounds of prediction are required, and when the previous level is wrong, the child level will also be wrong, and the accuracy cannot be guaranteed. SUMMARY

[0005] Therefore, the present application provides a text classification method, device, medium and equipment to solve the problems of the existing hierarchical classification method, such as the classification result not conforming to the logic and the low classification efficiency.

[0006] The first aspect of the present application provides a text classification method, which comprises:

[0007] Obtaining a text to be classified, and converting the text to be classified into a text vector;

[0008] Mapping the text vector into a first cuboid mass parameter of a first cuboid, and determining the mass of the first cuboid according to the first cuboid mass parameter, wherein the first cuboid mass parameter comprises a first density, a first starting position and a first ending position;

[0009] obtaining a second cuboid mass parameter of a second cuboid corresponding to the label, wherein the second cuboid mass parameter comprises a second density, a second start position, a second end position, and a size scaling parameter, wherein the size scaling parameter is used to identify a hierarchy of the label;

[0010] determining an intersection part of the first cuboid and the second cuboid according to the first cuboid mass parameter and the second cuboid mass parameter, and determining a mass of the intersection part;

[0011] determining a first similarity score between the label and the text to be classified according to the mass of the intersection part and the mass of the first cuboid;

[0012] if the first similarity score is greater than a classification threshold, determining that the text to be classified belongs to a classification corresponding to the label, wherein the classification threshold corresponds to the label.

[0013] In a second aspect, the present application provides a text classification device, the device comprising:

[0014] an encoding module configured to obtain a text to be classified and convert the text to be classified into a text vector;

[0015] a mapping module configured to map the text vector into a first cuboid mass parameter of a first cuboid, and determine a mass of the first cuboid according to the first cuboid mass parameter, wherein the first cuboid mass parameter comprises a first density, a first start position, and a first end position;

[0016] an obtaining module configured to obtain a second cuboid mass parameter of a second cuboid corresponding to the label, wherein the second cuboid mass parameter comprises a second density, a second start position, a second end position, and a size scaling parameter, wherein the size scaling parameter is used to identify a hierarchy of the label;

[0017] a calculating module configured to determine an intersection part of the first cuboid and the second cuboid according to the first cuboid mass parameter and the second cuboid mass parameter, and determine a mass of the intersection part;

[0018] the calculating module is further configured to determine a first similarity score between the label and the text to be classified according to the mass of the intersection part and the mass of the first cuboid;

[0019] a judging module configured to, if the first similarity score is greater than a classification threshold, determine that the text to be classified belongs to a classification corresponding to the label, wherein the classification threshold corresponds to the label.

[0020] In a third aspect of the present application, an electronic device is provided, which includes a storage medium, a processor, and instructions or code stored on the storage medium and executable on the processor, and the processor executes the instructions or code to implement the text classification method described above.

[0021] In a fourth aspect of the present application, a storage medium is provided, which stores instructions or code, and the instructions or code are executed by a processor to implement the text classification method described above.

[0022] The text classification method, device, equipment and medium described above convert the text to be classified and the labels with hierarchical relationship into high-dimensional cubic masses, wherein the hierarchical relationship is represented by using the size scaling parameter of the high-dimensional cubic, and the hierarchy of the text to be classified is defaulted as 1, so that the hierarchical relationship of the labels can be more intuitively presented. The intersection part between the text to be classified and each label is calculated respectively, the similarity between the two is calculated by using the mass of the intersection part, and the greater the mass of the intersection part is, the higher the similarity is. In this way, the task is converted into a multi-label classification task, the defects of the two-direction hierarchical classification methods in the current industry are avoided, the hierarchical relationship of different labels is considered, and the reasoning and prediction can be completed more efficiently and accurately without classifying in sequence according to the hierarchy. In addition, the method is more intuitive in the display of the results, and the accuracy of the hierarchical classification can be checked directly by viewing the volume and mass of the cubic in a visual way.

[0023] The above description is only a summary of the technical solutions of the present application, in order to more clearly understand the technical means of the present application, the specific embodiments of the present application can be implemented according to the content of the description, and in order to make the above and other purposes, characteristics and advantages of the present application more obvious and easy to understand, the following will describe the specific embodiments of the present application. BRIEF DESCRIPTION OF DRAWINGS

[0024] In order to more clearly illustrate the technical solutions of the embodiments of the present application, the following will briefly introduce the drawings needed to be used in the description of the embodiments of the present application. Obviously, the drawings in the following description are only some embodiments of the present application, and other drawings can also be obtained by those skilled in the art without creating labor intensity on the basis of these drawings.

[0025] Figure 1 A flowchart of a text classification method provided by an embodiment of the present application is shown;

[0026] Figure 2 A schematic diagram of mapping labels of another text classification method provided by an embodiment of the present application to a second cubic is shown;

[0027] Figure 3 A schematic diagram of mapping labels of another text classification method provided by an embodiment of the present application to a second cubic is shown;

[0028] Figure 4 A flow diagram of another text classification method provided by the embodiments of the application is shown;

[0029] Figure 5 A flow diagram of another text classification method provided by the embodiments of the application is shown;

[0030] Figure 6 A flow diagram of another text classification method provided by the embodiments of the application is shown;

[0031] Figure 7 A structural block diagram of a text classification device provided by the embodiments of the application is shown;

[0032] Figure 8 A structural block diagram of an electronic device provided by the embodiments of the application is shown. DETAILED DESCRIPTION

[0033] The technical solutions in the embodiments of the application will be clearly and completely described below with reference to the drawings in the embodiments of the application. Obviously, the described embodiments are only a part of the embodiments of the application, rather than all the embodiments of the application. Based on the embodiments in the application, all other embodiments obtained by those of ordinary skill in the art without creative work fall within the protection scope of the application.

[0034] The text classification method provided by the embodiments of the application can be applied to an electronic device with instruction or program running capability, wherein the electronic device can be, but is not limited to, various personal computers, notebook computers, smart phones, tablet computers, portable wearable devices, and vehicle-mounted systems, etc. Running in different computing devices is only a difference in the execution subject of the scheme, and those of ordinary skill in the art can predict that running in different computing devices can produce the same technical effects. The application will be described in detail below through specific embodiments.

[0035] The method can be widely applied to multiple different fields, such as medical field, electronic medical record labeling, health management, intelligent medical inquiry, and the like. The natural language text is a medical text, and specifically can be an electronic healthcare record, an electronic personal health record, including medical records, electrocardiograms, medical images and a series of electronic records with preservation and reference value. According to the obtained text, multiple different levels and mutually intersecting classifications corresponding to the text can be determined. For example, if the patient inputs the text "cerebral hemorrhage", since the disease belongs to both "neurology diseases" and "cardiovascular diseases", if the similarity of "cerebral hemorrhage" with "neurology diseases" and "cardiovascular diseases" is relatively high, the two labels of "neurology diseases" and "cardiovascular diseases" can be automatically added to the text, so as to facilitate doctors of two departments to conduct a consultation and more comprehensively analyze the patient's condition. If the similarity of "cerebral hemorrhage" with "neurology diseases" is relatively high, and the similarity with "cardiovascular diseases" is relatively low, only the label of "neurology diseases" can be added to the text, and then more targeted treatment can be performed.

[0036] For another example, a hospital sets up an infectious disease department, under which a fever clinic and an intestinal clinic are set up. When intelligent medical inquiry is performed, the patient inputs the text "flu, runny nose, fever", which belongs to both "infectious disease department" and "fever clinic". At this time, the similarity between "flu, runny nose, fever" and "infectious disease department" and "fever clinic" can be calculated respectively, and according to the size relationship between the similarity and a preset threshold, the two labels of "infectious disease department" and "fever clinic" can be automatically added to the text, or only the label of "infectious disease department" or "fever clinic" can be added to the text.

[0037] Please refer to Figure 1 as shown, Figure 1 A flowchart of a text classification method provided by an embodiment of the present application includes the following steps:

[0038] S10: obtaining a text to be classified, and converting the text to be classified into a text vector;

[0039] The method provided by the present application is used in hierarchical classification, and specifically, a class can belong to different levels, and it is determined which class or classes the text belongs to. For example, angina pectoris in coronary heart disease belongs to both a disease class and a cardiovascular disease class, wherein the disease class and the cardiovascular disease class belong to different levels, and the level of the disease is higher than the level of the cardiovascular disease.

[0040] In this embodiment, the text to be classified is converted into a text vector, and then the features implied in the text vector are mined in subsequent steps, and then the text vector is discriminated. Specifically, the text can be input into an Encoder encoder, such as a BERT, ELMO, etc. model, and the vector corresponding to the text is output.

[0041] wherein the dimension n of the text vector can be set according to a specific scene, for example, set to 200, 300 or 400 dimensions, etc. In this embodiment, the specific category is identified by a label, each label corresponds to a category, and the dimension of the text vector is positively correlated with the label level. In the case of a large label level, a larger dimension n can be set, and vice versa.

[0042] S20: mapping the text vector into a first cuboid mass parameter of a first cuboid, and determining the mass of the first cuboid according to the first cuboid mass parameter, wherein the first cuboid mass parameter comprises a first density, a first start position and a first end position;

[0043] In this embodiment, the text vector is converted into a parameter capable of representing the mass of the cuboid by mapping. The representation of the mass of the cuboid requires a total of 4 parameters for constraint, which are: density x d , start position x i , end position x e and size scaling x s . It can be understood that by these four constraints, the mass of a high-dimensional cuboid can be limited, and the cuboid mass representation is: Ma(x) = x d ∏k(x e,k -x i,k )x s , wherein k in the formula refers to the current dimension.

[0044] It can be understood that since the text vector does not have a hierarchy, the first cuboid mapped from the text vector does not have a size scaling, and the size scaling parameter of the first cuboid can also be considered as 1. Therefore, only the first density, the first start position and the first end position of the first cuboid are needed to be mapped from the text vector.

[0045] In step S20, the text vector is mapped into a first cuboid mass parameter, comprising the following steps:

[0046] S21: averaging and splitting the elements in the text vector to obtain four first sub-vectors;

[0047] S22: taking each element in the first sub-vector as a first edge, and determining the two end positions of each first edge as the first start position and the first end position;

[0048] S23: determining the first density according to the first sub-vector content.

[0049] For steps S21-S23, since there are 4 constraints for the cuboid mass in total, the text vector is split into 4 parts, and the splitting manner is designed as equal division. Each of the first sub-vectors after splitting is input into the parameter generation module to obtain the first cuboid mass parameter.

[0050] It can be understood that the cuboid is composed of multiple edges, each edge contains two end points, and each element in the first word vector is a edge of the cuboid, and the positions of the two end points are a pair of first start position and first end position, thereby obtaining multiple pairs of first start position and first end position. In addition, the first density is determined according to the content of the first sub-vector. Specifically, if the text density corresponding to the first sub-vector is large, that is, the first sub-vector contains more content, it can be considered that the first density of the first cuboid corresponding to the first sub-vector is also large.

[0051] S30: obtaining the second cuboid mass parameter of the second cuboid corresponding to the label, wherein the second cuboid mass parameter includes the second density, the second start position, the second end position and the size scaling parameter, wherein the size scaling parameter is used to identify the level of the label;

[0052] In this embodiment, the second cuboid corresponding to the label has a second cuboid mass parameter, and the principle is the same as that of the first cuboid mass parameter of the first cuboid, which will not be described here.

[0053] It can be understood that since the text vector does not have a level, the first cuboid mapped from the text vector does not have a size scaling, and it can be considered that the size scaling parameter of the first cuboid is 1. For the label, since each label belongs to a different level, the second cuboid mass parameter includes the size scaling parameter, and different size scaling parameters are set for labels of different levels, so that the size scaling parameter can be used to identify the level of the label.

[0054] Before step S30, the following steps are further included:

[0055] S301: evenly splitting the elements in the label vector corresponding to the label to obtain four second sub-vectors;

[0056] S302: regarding each element in the second sub-vector as a second edge, and determining the two end point positions of each second edge as the second start position and the second end position, respectively;

[0057] S303: determining the second density according to the second sub-vector content;

[0058] S304: determining the size scaling parameter according to the level corresponding to the label.

[0059] For steps S301-S304, before obtaining the second cuboid quality parameter corresponding to the label, the label is also vectorized and mapped to the second cuboid quality parameter. The principle is the same as the text vector mapping to the first cuboid quality parameter, which will not be repeated here.

[0060] It can be understood that, since the text vector does not have a hierarchy, the first cuboid does not have a size scaling. Since the label belongs to different hierarchies, the size scaling can be used to identify the hierarchy corresponding to the label. Specifically, the size scaling parameter is determined according to the hierarchy, and the lower the hierarchy corresponding to the label, the smaller the size scaling parameter, resulting in a smaller second cuboid.

[0061] This embodiment can distinguish the hierarchy corresponding to the label through the size of the second cuboid, so as to basically consider the hierarchical relationship of the label without classifying according to the hierarchy, realize the hierarchical classification of the text, and avoid the defects brought by the existing hierarchical classification method.

[0062] Figure 2 A schematic diagram of mapping labels to second cuboids according to another embodiment of the present application is shown. As shown in the figure, there are four different levels of labels: " / disease", " / disease / cardiology disease", " / disease / neurology disease", and " / disease / neurology disease / neurosurgery disease". The " / disease" label and the " / disease / neurology disease" label are mapped to the second cuboid quality parameter corresponding to the second cuboid. Since the hierarchy of the " / disease" label is higher than that of the " / disease / neurology disease" label, the number of size scaling of the " / disease" label is greater than that of the " / disease / neurology disease", and the second cuboid corresponding to the " / disease / neurology disease" label is scaled more, that is, the volume of the second cuboid corresponding to the " / disease / neurology disease" label in the figure is smaller.

[0063] Figure 3 A schematic diagram of mapping labels to second cuboids according to another embodiment of the present application is shown. As shown in the figure, " / disease" is the parent level of " / disease / cardiology disease" and " / disease / neurology disease", and " / disease / neurology disease" is the parent level of " / disease / neurology disease / neurosurgery disease", so the range of " / disease" is the largest, and the corresponding second cuboid is also the largest. The second cuboids corresponding to " / disease / cardiology disease" and " / disease / neurology disease" are both contained in the second cuboid corresponding to " / disease". In addition, since some diseases belong to both " / disease / cardiology disease" and " / disease / neurology disease", there is an intersection between " / disease / cardiology disease" and " / disease / neurology disease", that is, there is an intersection between the second cuboids corresponding to the two.

[0064] S40: determining the intersection of the first cuboid and the second cuboid according to the first cuboid quality parameter and the second cuboid quality parameter, and determining the quality of the intersection;

[0065] In this embodiment, since the first cuboid quality parameter can uniquely define a first cuboid and the second cuboid quality parameter can uniquely define a second cuboid, the intersection of the two cuboids can be determined according to the first cuboid quality parameter and the second cuboid quality parameter, and the quality of the intersection can be determined.

[0066] Figure 4 A schematic diagram of the intersection of a first cuboid and a second cuboid of another embodiment of the present application is shown. As shown in the diagram, x is a first cuboid corresponding to a text to be classified, and y is a second cuboid corresponding to a label, wherein the densities of the first cuboid and the second cuboid are different, and are indicated by diagonal lines in the diagram, and the intersection i of x and y is the intersection of the first cuboid and the second cuboid.

[0067] In step S40, the intersection of the first cuboid and the second cuboid is determined according to the first cuboid quality parameter and the second cuboid quality parameter, including the following steps:

[0068] S41: determining a first space occupied by the first cuboid according to the first start position and the first end position;

[0069] S42: determining a second space occupied by the second cuboid according to the second start position, the second end position and the size scaling parameter;

[0070] S43: determining the intersection of the first space and the second space as the intersection.

[0071] For steps S41-S43, the first cuboid is uniquely identified according to the first quality parameter. Specifically, the first quality parameter includes multiple pairs of first start positions and first end positions, each pair of first start position and first end position identifies an edge, and multiple edges constitute the first cuboid, thereby defining the first space occupied by the first cuboid.

[0072] Similarly, the second quality parameter includes multiple pairs of second start positions and second end positions, each pair of second start position and second end position identifies an edge, and multiple edges constitute the second cuboid, and on this basis, the size of the second cuboid is scaled according to the size scaling parameter, thereby obtaining the final second space occupied by the second cuboid.

[0073] After the first space and the second space are determined, the intersection of the first space and the second space can be found, and the intersection is the intersection of the first vector and the second vector.

[0074] In step S40, the quality of the intersection is determined, including the following steps:

[0075] S44: determining a third density of the intersection part as a mean of the first density and the second density;

[0076] S45: calculating a mass of the intersection part according to the volume of the intersection part and the third density.

[0077] For steps S44-S45, the mass of the cuboid x can be obtained by the product of the volume and the density: Ma(x)=Vol(x)*p x Based on this, the volume of the intersection part can be multiplied by the third density to obtain the mass of the intersection part, wherein the third density takes the mean of the first density of the first cuboid and the second density of the second cuboid.

[0078] S50: determining a first similarity score between the label and the text to be classified according to the mass of the intersection part and the mass of the first cuboid;

[0079] In this embodiment, if the first cuboid and the second cuboid have an intersection, it can be considered that the label and the text to be classified have a similar part. Further, the larger the volume of the intersection part is, the larger the similar part can be considered to be; on this basis, the larger the density of the intersection part is, the larger the text density of the similar part can be considered to be, that is, the more important the text of the similar part is. For example, the similar part of "de" and "le" is obviously less important than the similar part of "cyst". Therefore, the high or low of the similarity score is related to the mass of the intersection part.

[0080] In addition, the similarity score is also related to the mass of the first cuboid, and it can be understood that in the case of the same intersection part, the amount of information included in the text to be classified is different, and the similarity degree of the label and the text to be classified is also different.

[0081] Therefore, the first similarity score can be calculated according to the mass of the intersection part and the mass of the first cuboid.

[0082] In step S50, the first similarity score between the label and the text to be classified is determined according to the mass of the intersection part and the mass of the first cuboid, including the following steps:

[0083] S51: calculating a ratio of the mass of the intersection part and the mass of the first cuboid, and taking the ratio as the first similarity score.

[0084] For step S51, it can be understood that the larger the mass of the intersection part of the first cuboid and the second cuboid is, the larger the intersection of the text to be classified corresponding to the first cuboid and the label corresponding to the second cuboid is, that is, the higher the similarity is, and therefore the higher the first similarity score is.

[0085] In addition, in the case of the same quality of the intersection part, the greater the mass of the first cuboid, the more the part belonging to the first cuboid but not belonging to the second cuboid, and thus the lower the similarity.

[0086] Based on this, the ratio of the quality of the intersection part to the mass of the first cuboid can be calculated, where x represents the text to be classified, y is the label, the intersection part of x and y is i, and Ma represents the quality. The ratio is taken as the first similarity score between the label and the text to be classified, and the ratio satisfies positive correlation with the quality of the intersection part and negative correlation with the mass of the first cuboid.

[0087] S60: If the first similarity score is greater than a classification threshold value, it is determined that the text to be classified belongs to the classification corresponding to the label, wherein the classification threshold value corresponds to the label.

[0088] In this embodiment, the higher the first similarity score between the label and the text to be classified, the more similar the label and the text to be classified, and the greater the possibility that the text to be classified belongs to the classification corresponding to the label. Therefore, a classification threshold value is set for each label, and it is determined that the text to be classified belongs to the classification corresponding to the label if the first similarity score is greater than the classification threshold value.

[0089] wherein the classification threshold values corresponding to different labels can be the same or different.

[0090] wherein before step S60, the following steps are further included:

[0091] S601: obtaining a verification set text, and determining a second similarity score between the label and the verification set text;

[0092] S602: determining a classification result of the verification set text according to the second similarity score and a preset threshold value;

[0093] S603: determining an F1 value corresponding to the label according to the classification result and the categories corresponding to the training set texts;

[0094] S604: adjusting the preset threshold value according to the F1 value, and returning to the step of determining the classification result of the verification set text until the F1 value meets a preset condition, and taking the preset threshold value at this time as the classification threshold value.

[0095] For steps S601-S604, a preset threshold value is designed for each label, and in the verification phase, the threshold value corresponding to the best F1 value is selected for each classification label as the classification threshold value.

[0096] Specifically, in the verification phase, a second similarity score between the label and the verification set text is calculated, wherein the calculation method is similar to the aforementioned calculation of the first similarity score between the label and the text to be classified. According to the second similarity score and a preset threshold, a classification result of the verification set text can be obtained, wherein if the second similarity score is greater than the preset threshold, it is determined that the verification set text belongs to the classification corresponding to the label, otherwise it does not.

[0097] Then, according to the classification result and the actual category corresponding to the training set text, the accuracy of the classification result can be obtained, and then the precision and recall of the classification can be determined. It can be understood that the precision and the recall are complementary, that is, the higher the precision, the lower the recall. The F1 value is a parameter used to comprehensively evaluate the precision and the recall, and can achieve the balance of the precision and the recall. When the precision and the recall are both high, the F1 value is also high. Specifically, Wherein, P is the precision, P is the recall.

[0098] Based on this, the preset threshold is adjusted according to the precision and the recall of the classification, so that the F1 value is maximum, and the preset threshold at this time is taken as the classification threshold.

[0099] Further, the initial threshold can be set to 0.5.

[0100] Figure 5 The flowchart of the text classification method provided by another embodiment of the application is shown in the figure, and the method includes the following steps:

[0101] S001: obtaining a text to be classified, and converting the text to be classified into a text vector;

[0102] S002: averaging and splitting the elements in the text vector to obtain four first sub-vectors;

[0103] S003: taking each element in the first sub-vector as a first edge, and determining the two end positions of each first edge as a first start position and a first end position;

[0104] S004: determining a first density according to the content of the first sub-vector;

[0105] S005: averaging and splitting the elements in the label vector corresponding to the label to obtain four second sub-vectors;

[0106] S006: taking each element in the second sub-vector as a second edge, and determining the two end positions of each second edge as a second start position and a second end position;

[0107] S007: determining a second density according to the content of the second sub-vector;

[0108] S008: determining a size scaling parameter according to the level corresponding to the label;

[0109] S009: obtaining a second cuboid quality parameter of a second cuboid corresponding to the label, wherein the second cuboid quality parameter comprises a second density, a second start position, a second end position, and the size scaling parameter, wherein the size scaling parameter is used to identify the level of the label;

[0110] S010: determining a first space occupied by the first cuboid according to the first start position and the first end position;

[0111] S011: determining a second space occupied by the second cuboid according to the second start position, the second end position, and the size scaling parameter;

[0112] S012: determining an intersection of the first space and the second space as an intersection part;

[0113] S013: determining a mean value of the first density and the second density as a third density of the intersection part;

[0114] S014: calculating a mass of the intersection part according to a volume of the intersection part and the third density;

[0115] S015: calculating a ratio of the mass of the intersection part to a mass of the first cuboid, and taking the ratio as a first similarity score;

[0116] S016: obtaining a verification set text, and determining a second similarity score between the label and the verification set text;

[0117] S017: determining a classification result of the verification set text according to the second similarity score and a preset threshold;

[0118] S018: determining an F1 value corresponding to the label according to the classification result and a category corresponding to the training set text;

[0119] S019: adjusting the preset threshold according to the F1 value, and returning to the step of determining the classification result of the verification set text until the F1 value meets a preset condition, and taking the preset threshold at this time as a classification threshold.

[0120] S020: if the first similarity score is greater than the classification threshold, determining that the text to be classified belongs to a category corresponding to the label, wherein the classification threshold corresponds to the label.

[0121] For steps S001-S020, the principles and effects are similar to those of the foregoing embodiments, and reference can be made to the related descriptions in the method embodiments. To avoid repetition, no further description is given here.

[0122] Figure 6A flowchart of a text classification method of another embodiment of the present application is shown. As shown, first, the text to be classified is input into an Encoder encoder, and the text to be classified is converted into a text vector in the Encoder encoder; then, high-dimensional cuboid quality mapping is performed on the text vector, and the text vector is mapped into a first cuboid corresponding to a first cuboid quality parameter; a similarity score between the label and the text to be classified (i.e., the label score in the figure) is calculated according to the first cuboid quality parameter and a second cuboid quality parameter of the label; finally, according to the size relationship between the similarity score and a threshold value, it is determined whether the text to be classified belongs to the classification corresponding to the label, and the determination result is output.

[0123] It can be seen that, compared with the existing hierarchical text classification method, the above scheme represents the text to be classified and the labels with hierarchical relationship by high-dimensional cuboid quality, wherein the hierarchical relationship is represented by the size scaling parameter of the high-dimensional cuboid, and the hierarchy of the text to be classified is defaulted to 1, so that the hierarchical relationship of the labels can be more intuitively presented. The intersection part between the text to be classified and each label is calculated respectively, the similarity between the two is calculated by the quality of the intersection part, and the greater the quality of the intersection part, the higher the similarity. In this way, the task is converted into a multi-label classification task, avoiding the defects of the two-direction hierarchical classification methods in the current industry, considering the hierarchical relationship of different labels, and without classifying in order according to the hierarchy, the reasoning and prediction can be completed more efficiently and accurately. In addition, the method is more intuitive in result display, and the accuracy of hierarchical classification can be checked directly by viewing the volume and mass of the cuboid through visualization.

[0124] It should be understood that the size of the serial number of each step in the above embodiments does not mean the order of execution, and the execution order of each process should be determined according to its function and internal logic, and should not constitute any limitation on the implementation process of the embodiments of the present application.

[0125] In an embodiment, a text classification device is provided, which corresponds to the text classification method of the above embodiment. As shown, the text classification device comprises an encoding module, a mapping module, an obtaining module, a calculating module and a judging module. The functions of each functional module are described in detail as follows: Figure 7

[0126] The encoding module is configured to obtain the text to be classified and convert the text to be classified into a text vector;

[0127] The mapping module is configured to map the text vector into a first cuboid quality parameter of a first cuboid, and determine the quality of the first cuboid according to the first cuboid quality parameter, wherein the first cuboid quality parameter comprises a first density, a first start position and a first end position;

[0128] ​The acquisition module is configured to acquire a second cuboid mass parameter of a second cuboid corresponding to the label, wherein the second cuboid mass parameter comprises a second density, a second start position, a second end position, and a size scaling parameter, and the size scaling parameter is used to identify a hierarchy of the label.

[0129] The calculation module is configured to determine an intersection part of the first cuboid and the second cuboid according to the first cuboid mass parameter and the second cuboid mass parameter, and determine a mass of the intersection part.

[0130] The calculation module is further configured to determine a first similarity score between the label and the text to be classified according to the mass of the intersection part and the mass of the first cuboid.

[0131] The judgment module is configured to determine that the text to be classified belongs to a classification corresponding to the label if the first similarity score is greater than a classification threshold, wherein the classification threshold corresponds to the label.

[0132] In an embodiment, the calculation module is configured to:

[0133] determine a first space occupied by the first cuboid according to the first start position and the first end position;

[0134] determine a second space occupied by the second cuboid according to the second start position, the second end position, and the size scaling parameter;

[0135] determine an intersection of the first space and the second space as the intersection part.

[0136] In an embodiment, the calculation module is configured to:

[0137] determine a third density of the intersection part as an average of the first density and the second density;

[0138] calculate the mass of the intersection part according to a volume of the intersection part and the third density.

[0139] In an embodiment, the calculation module is configured to:

[0140] calculate a ratio of the mass of the intersection part to the mass of the first cuboid, and take the ratio as the first similarity score.

[0141] In an embodiment, the mapping module is configured to:

[0142] average and split elements in the text vector to obtain four first sub-vectors;

[0143] take each element in the first sub-vector as a first edge, and determine two end point positions of each first edge as the first start position and the first end position, respectively;

[0144] determine the first density according to the content of the first sub-vector.

[0145] In an embodiment, the mapping module is further configured to:

[0146] average splitting elements in the label vector corresponding to the label to obtain four second sub-vectors;

[0147] determining two end point positions of each second edge as a second start position and a second end position, respectively;

[0148] determining the second density according to the second sub-vector content;

[0149] determining the size scaling parameter according to the label corresponding hierarchy.

[0150] In an embodiment, the device further comprises an initialization module configured to:

[0151] obtaining the validation set text, and determining a second similarity score between the label and the validation set text;

[0152] determining the classification result of the validation set text according to the second similarity score and a preset threshold;

[0153] determining the F1 value corresponding to the label according to the classification result and the category corresponding to the training set text;

[0154] adjusting the preset threshold according to the F1 value, and returning to the step of determining the classification result of the validation set text until the F1 value meets the preset condition, and taking the preset threshold at this time as the classification threshold.

[0155] In an embodiment, an electronic device is provided, which can be a mobile device such as a mobile phone, a tablet, a vehicle-mounted mobile terminal, or other devices with program execution capability. The internal structure of the electronic device can be as shown in Figure 8 The electronic device includes a processor, a memory, and a network module. The processor of the electronic device is configured to provide computing and control capabilities. The memory of the electronic device includes a non-volatile and / or volatile storage medium, an internal memory. The non-volatile storage medium stores an operating system, instructions or codes. The internal memory provides an environment for the operating system and instructions or codes in the non-volatile storage medium to run. The instructions or codes are executed by the processor to implement the functions or steps of the above-mentioned text classification method. The network module of the electronic device can include a network interface and / or a wireless network module, and the electronic device can communicate with other devices or service platforms through the network module. In addition, the electronic device can further include a display screen and an input device, etc.

[0156] In an embodiment, an electronic device is provided, which includes a memory, a processor, and instructions or codes stored in the memory and executable on the processor, and the processor executes the instructions or codes to implement the following steps:

[0157] obtaining the text to be classified and converting the text to be classified into a text vector;

[0158] mapping the text vector into a first cuboid mass parameter of a first cuboid, and determining a mass of the first cuboid according to the first cuboid mass parameter, wherein the first cuboid mass parameter comprises a first density, a first start position and a first end position;

[0159] obtaining a second cuboid mass parameter of a second cuboid corresponding to the label, wherein the second cuboid mass parameter comprises a second density, a second start position, a second end position and a size scaling parameter, wherein the size scaling parameter is used to identify a hierarchy of the label;

[0160] determining an intersection part of the first cuboid and the second cuboid according to the first cuboid mass parameter and the second cuboid mass parameter, and determining a mass of the intersection part;

[0161] determining a first similarity score between the label and the text to be classified according to the mass of the intersection part and the mass of the first cuboid;

[0162] if the first similarity score is greater than a classification threshold, determining that the text belongs to a classification corresponding to the label, wherein the classification threshold corresponds to the label.

[0163] In one embodiment, a storage medium is provided, on which instructions or codes are stored, which are executed by a processor to implement the following steps:

[0164] obtaining the text to be classified and converting the text to be classified into a text vector;

[0165] mapping the text vector into a first cuboid mass parameter of a first cuboid, and determining a mass of the first cuboid according to the first cuboid mass parameter, wherein the first cuboid mass parameter comprises a first density, a first start position and a first end position;

[0166] obtaining a second cuboid mass parameter of a second cuboid corresponding to the label, wherein the second cuboid mass parameter comprises a second density, a second start position, a second end position and a size scaling parameter, wherein the size scaling parameter is used to identify a hierarchy of the label;

[0167] determining an intersection part of the first cuboid and the second cuboid according to the first cuboid mass parameter and the second cuboid mass parameter, and determining a mass of the intersection part;

[0168] determining a first similarity score between the label and the text to be classified according to the mass of the intersection part and the mass of the first cuboid;

[0169] If the first similarity score is greater than a classification threshold, it is determined that the text belongs to a classification corresponding to the label, wherein the classification threshold corresponds to the label.

[0170] It should be noted that the above-mentioned functions or steps that can be achieved by the storage medium or the electronic device can correspond to the related description in the foregoing method embodiments, and to avoid repetition, they will not be described one by one here.

[0171] Those skilled in the art can understand that all or part of the processes in the above-mentioned embodiment methods can be completed by instructions or codes to instruct related hardware, and the instructions or codes can be stored in a non-volatile readable storage medium. When the instructions or codes are executed, they can include the processes of the above-mentioned embodiments of the method. In the embodiments provided in the present application, any reference to memory, storage, database or other medium can include non-volatile and / or volatile memory. Non-volatile memory can include read-only memory (ROM), programmable ROM (PROM), electrically programmable ROM (EPROM), electrically erasable programmable ROM (EEPROM) or flash memory. Volatile memory can include random access memory (RAM) or external cache memory. As an illustration but not limitation, RAM is available in various forms, such as static RAM (SRAM), dynamic RAM (DRAM), synchronous DRAM (SDRAM), double data rate SDRAM (DDR SDRAM), enhanced SDRAM (ESDRAM), synchronous link (Synchlink) DRAM (SLDRAM), memory bus (Rambus) direct RAM (RDRAM), direct memory bus dynamic RAM (DRDRAM), and memory bus dynamic RAM (RDRAM), etc.

[0172] Those skilled in the art can clearly understand that, for the convenience and brevity of description, only the division of the above-mentioned functional units and modules is exemplified, and in actual application, the above-mentioned functions can be completed by different functional units and modules according to needs, that is, the internal structure of the device is divided into different functional units or modules to complete all or part of the functions described above.

[0173] Those skilled in the art can understand that the units or processes in the drawings are not necessarily necessary for the implementation of the present application. Those skilled in the art can understand that the units in the system in the implementation scenario can be distributed in the system in the implementation scenario according to the description of the implementation scenario, or can be changed to be located in one or more systems different from the implementation scenario. The units of the above-mentioned implementation scenario can be combined into one unit, or can be further split into multiple sub-units.

[0174] The above-described embodiments are only used to illustrate the technical solutions of the present application, and are not intended to limit the present application; although the present application has been described in detail with reference to the foregoing embodiments, those skilled in the art should understand that: it can still modify the technical solutions recorded in the foregoing embodiments, or make equivalent replacement for part of the technical features; and these modifications or replacements do not make the essence of the corresponding technical solutions deviate from the spirit and scope of the technical solutions of the embodiments of the present application, and should be included in the protection scope of the present application.

Claims

1. A text classification method, characterized in that, The method includes: Obtain the text to be classified and convert it into a text vector; Mapping the text vector to the first cube mass parameter of the first cube includes: splitting the elements in the text vector into four first sub-vectors on an average basis; taking each element in the first sub-vector as a first edge, and determining the two endpoints of each first edge as a first start position and a first end position; and determining a first density based on the content of the first sub-vector. The mass of the first cube is determined based on the mass parameters of the first cube, wherein the mass parameters of the first cube include a first density, a first starting position, and a first ending position; The elements in the tag vector corresponding to the tag are split equally to obtain four second sub-vectors; each element in the second sub-vector is taken as a second edge, and the two endpoints of each second edge are determined as the second start position and the second end position; the second density is determined according to the content of the second sub-vector; the size scaling parameter is determined according to the level corresponding to the tag. Obtain the second cube mass parameters of the second cube corresponding to the label, wherein the second cube mass parameters include a second density, a second start position, a second end position, and a size scaling parameter, wherein the size scaling parameter is used to identify the layer of the label; Based on the mass parameters of the first cube and the second cube, the intersection of the first cube and the second cube is determined, and the mass of the intersection is determined. Based on the quality of the intersecting portion and the quality of the first cube, a first similarity score is determined between the label and the text to be classified. If the first similarity score is greater than the classification threshold, then the text to be classified is determined to belong to the category corresponding to the label, wherein the classification threshold corresponds to the label.

2. The method according to claim 1, characterized in that, The step of determining the intersection of the first cube and the second cube based on the mass parameters of the first cube and the second cube includes: Based on the first starting position and the first ending position, determine the first space occupied by the first cube; The second space occupied by the second cube is determined based on the second starting position, the second ending position, and the size scaling parameters; The intersection of the first space and the second space is defined as the intersecting part.

3. The method according to claim 1, characterized in that, Determining the quality of the intersecting portion includes: The average of the first density and the second density is determined to be the third density of the intersecting portion; The mass of the intersecting portion is calculated based on the volume of the intersecting portion and the third density.

4. The method according to claim 1, characterized in that, The step of determining a first similarity score between the label and the text to be classified based on the quality of the intersecting portion and the quality of the first cube includes: Calculate the ratio of the mass of the intersecting portion to the mass of the first cube, and use the ratio as the first similarity score.

5. The method according to claim 1, characterized in that, Before determining that the text to be classified belongs to the category corresponding to the tag if the similarity score is greater than the classification threshold, the method further includes: Obtain the validation set text and determine the second similarity score between the tag and the validation set text; Based on the second similarity score and the preset threshold, the classification result of the verification set text is determined; Based on the classification results and the categories corresponding to the validation set texts, determine the F1 value corresponding to the label; Adjust the preset threshold based on the F1 value and return to the step of determining the classification result of the validation set text until the F1 value meets the preset condition, and use the preset threshold at this time as the classification threshold.

6. A text classification device, characterized in that, The device includes: The encoding module is used to acquire the text to be classified and convert the text to be classified into a text vector. The mapping module is used to map the text vector into a first cube mass parameter of a first cube, and to determine the mass of the first cube based on the first cube mass parameter, wherein the first cube mass parameter includes a first density, a first start position, and a first end position. The acquisition module is used to acquire the second cube mass parameters of the second cube corresponding to the label, wherein the second cube mass parameters include a second density, a second starting position, a second ending position, and a size scaling parameter, wherein the size scaling parameter is used to identify the layer of the label; The calculation module is used to determine the intersection of the first cube and the second cube based on the mass parameters of the first cube and the second cube, and to determine the mass of the intersection. The calculation module is further configured to determine a first similarity score between the label and the text to be classified based on the quality of the intersecting portion and the quality of the first cube; The judgment module is used to determine that the text to be classified belongs to the category corresponding to the label if the first similarity score is greater than the classification threshold, wherein the classification threshold corresponds to the label; The mapping module is used to: split the elements in the text vector into four first sub-vectors; take each element in the first sub-vector as a first edge, and determine the two endpoints of each first edge as the first start position and the first end position; and determine the first density based on the content of the first sub-vectors. The mapping module is also used to: split the elements in the tag vector corresponding to the tag into four second sub-vectors; take each element in the second sub-vector as a second side, and determine the two endpoints of each second side as the second start position and the second end position; determine the second density based on the content of the second sub-vector; and determine the size scaling parameter based on the level corresponding to the tag.

7. A storage medium having a program or instructions stored thereon, characterized in that, When the program or instructions are executed by the processor, they implement the steps of the method as described in any one of claims 1 to 5.

8. An electronic device comprising a storage medium, a processor, and a computer program stored on the storage medium and executable on the processor, characterized in that, When the processor executes the program, it implements the method of any one of claims 1 to 5.

Citation Information

Patent Citations

  • Text classification method and device and computer equipment

    CN110362684A

  • Text classification method and device

    CN111858843A