Text classification method, apparatus, device, and medium

CN118277570BActive Publication Date: 2026-11-03PING AN TECH (SHENZHEN) CO LTD
View PDF 2 Cites 0 Cited by

Patent Information

Application Number
CN202410412786.1
Authority / Receiving Office
CN · China
Patent Type
Patents(China)
Current Assignee / Owner
Filing Date
2024-04-03
Publication Date
2026-11-03
Estimated Expiration
2044-04-03

AI Technical Summary

Technical Problem

Traditional text classification methods suffer from low accuracy because sentence vectors cannot accurately represent the semantic information between sentences due to the anisotropy of word representation space in case texts.

Method used

By obtaining the text sentence vector set of the text set to be classified, finding the neighboring semantic sentence vectors that have semantic adjacency, performing remapping, constructing positive sample pairs and negative sample pairs, calculating the sample loss value, determining the target sentence vector set, and performing text classification.

Benefits of technology

It improves the accuracy of text classification, especially in the medical field, by increasing the accuracy of case text classification.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN118277570B_ABST
    Figure CN118277570B_ABST
Patent Text Reader

Abstract

The application relates to an artificial intelligence technology in the medical field, and discloses a text classification method, device, equipment and medium, which can be used for classifying medical cases. The method comprises the following steps: obtaining a text set to be classified, and extracting a text sentence vector set of the text set to be classified; finding, in the text sentence vector set, a neighboring semantic sentence vector having a semantic neighboring relationship with each text sentence vector, obtaining a neighboring relationship between each text sentence vector and the corresponding neighboring semantic sentence vector in the text sentence vector set, remapping the text sentence vector set according to the neighboring relationship, and obtaining an optimized sentence vector set; constructing a positive sample pair set and a negative sample pair set according to the optimized sentence vector set, calculating a sample loss value generated by the positive sample pair set and the negative sample pair set, and determining a target sentence vector set according to the sample loss value; and performing text classification on the target sentence vector set to obtain a classification result of the text set to be classified. The application can improve the accuracy of text classification.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] This invention relates to the field of artificial intelligence, and more particularly to a text classification method, apparatus, device, and storage medium. Background Technology

[0002] Text classification refers to categorizing texts based on predetermined rules. For example, in the medical field, the vast amount of medical case texts needs to be summarized and integrated, requiring deep learning technology to categorize the cases.

[0003] Traditional text classification methods utilize neural networks to extract sentence vectors from case texts and then use the similarity between these vectors to represent the semantic information of the text. However, this approach suffers from several drawbacks. Firstly, the word representation space in case texts is anisotropic, with high-frequency words clustering near the origin and low-frequency words sparsely distributed. Secondly, sentence representation is dominated by high-frequency words, making it difficult to accurately represent the semantic information between sentences. This results in low accuracy in case text classification, potentially leading to confusion between diagnosed and treated cases during the consultation process and causing misdiagnosis. Summary of the Invention

[0004] This invention provides a text classification method, apparatus, device, and storage medium. Its main purpose is to solve the problem that the sentence vectors extracted from case texts cannot accurately represent the semantic information between sentences, resulting in low accuracy in case text classification.

[0005] To achieve the above objectives, the present invention provides a text classification method, comprising:

[0006] Obtain the text set to be classified, and extract the text sentence vector set of the text set to be classified;

[0007] In the text sentence vector set, for each text sentence vector, find the neighboring semantic sentence vectors that have a semantic adjacency relationship with it, obtain the adjacency relationship between each text sentence vector in the text sentence vector set and its corresponding neighboring semantic sentence vectors, and remap the text sentence vector set according to the adjacency relationship to obtain an optimized sentence vector set;

[0008] Construct a set of positive sample pairs and a set of negative sample pairs based on the optimized sentence vector set, calculate the sample loss value generated by the set of positive sample pairs and the set of negative sample pairs, and determine the target sentence vector set based on the sample loss value;

[0009] The target sentence vector set is classified into texts to obtain the classification result of the text set to be classified.

[0010] Optionally, the step of finding neighboring semantic sentence vectors that have a semantic adjacency relationship with each text sentence vector in the text sentence vector set includes:

[0011] Sentence frequency sampling is performed on each text sentence vector in the text sentence vector set to obtain the sentence vector sampling space;

[0012] Based on the sentence vector sampling space, find multiple candidate sentence vectors that are semantically adjacent to each text sentence vector;

[0013] Calculate the Euclidean distance between each text sentence vector and the corresponding plurality of candidate sentence vectors, and perform semantic adjacency filtering on the plurality of candidate sentence vectors based on the Euclidean distance to obtain the adjacent semantic sentence vectors corresponding to each text sentence vector.

[0014] Optionally, the step of remapping the text sentence vector set according to the adjacency relationship to obtain an optimized sentence vector set includes:

[0015] Calculate the neighborhood reconstruction weight of each text sentence vector in the text sentence vector set based on the adjacency relationship;

[0016] The global connection relationship between each text sentence vector is determined based on the neighborhood reconstruction weight, and the text sentence vectors are spatially mapped based on the global connection relationship to obtain the optimized sentence vector set.

[0017] Optionally, constructing the positive sample pair set and the negative sample pair set based on the optimized sentence vector set includes:

[0018] Step A: Select one of the optimized sentence vectors from the set of optimized sentence vectors one by one according to the preset order;

[0019] Step B: Back-translate the selected optimized sentence vector to obtain the corresponding back-translated sentence vector, and combine the selected optimized sentence vector and the corresponding back-translated sentence vector to obtain a positive sample pair;

[0020] Step C: Replace the selected optimized sentence vector with antonyms to obtain the corresponding antonym sentence vector. Combine the selected optimized sentence vector and the corresponding antonym sentence vector to obtain antonym negative sample pairs.

[0021] Step D: Randomly select any optimized sentence vector other than the selected optimized sentence vector from the optimized sentence vector set to obtain a sampled sentence vector. Combine the selected optimized sentence vector and the sampled sentence vector to obtain a sampled negative sample pair.

[0022] Step E: Combine the antonym negative sample pairs and the sampled negative sample pairs to obtain negative sample pairs;

[0023] Repeat steps A through E above until all optimized sentence vectors in the optimized sentence vector set have been selected, thus obtaining a set of positive sample pairs and a set of negative sample pairs.

[0024] Optionally, determining the target sentence vector set based on the sample loss value includes:

[0025] Determine whether the sample loss value is less than a preset threshold;

[0026] When the sample loss value is not less than a preset threshold, the positive sample set and the negative sample set are reconstructed until the sample loss value is less than the preset threshold.

[0027] When the sample loss value is less than a preset threshold, the optimized sentence vector set corresponding to the sample loss value is used as the target sentence vector set.

[0028] Optionally, extracting the text sentence vector set of the text set to be classified includes:

[0029] The text set to be classified is encoded to obtain a word vector feature set;

[0030] The word vector feature set is weighted and pooled to obtain a dynamic word vector feature set;

[0031] The dynamic word vector feature set is averaged and pooled to obtain the sentence vector set of the text set to be classified.

[0032] Optionally, the step of performing text classification on the target sentence vector set to obtain the classification result of the text set to be classified includes:

[0033] Extract the sentence vector feature set of the target sentence vector set;

[0034] Calculate the category probability of the sentence vector feature set, and select the category with the highest probability from the category probabilities as the classification result of the text set to be classified.

[0035] To address the above problems, the present invention also provides a text classification device, the device comprising:

[0036] The encoding module is used to acquire the text set to be classified and extract the text sentence vector set of the text set to be classified;

[0037] The remapping module is used to find multiple adjacent semantic sentence vectors that have a semantic adjacency relationship with each text sentence vector in the text sentence vector set, obtain the adjacency relationship between each text sentence vector in the text sentence vector set and the multiple adjacent semantic sentence vectors, and remap the text sentence vector set according to the adjacency relationship to obtain an optimized sentence vector set;

[0038] The sample construction module is used to construct a positive sample pair set and a negative sample pair set based on the optimized sentence vector set, calculate the sample loss value generated by the positive sample pair set and the negative sample pair set, and determine the target sentence vector set based on the sample loss value.

[0039] The classification module is used to perform text classification on the target sentence vector set to obtain the classification result of the text set to be classified.

[0040] To address the above problems, the present invention also provides an electronic device, the electronic device comprising:

[0041] Memory, storing at least one computer program; and

[0042] The processor executes the computer program stored in the memory to implement the text classification method described above.

[0043] To address the aforementioned problems, the present invention also provides a computer-readable storage medium storing at least one computer program, which is executed by a processor in an electronic device to implement the text classification method described above.

[0044] In this embodiment of the invention, firstly, the text sentence vector set of the text set to be classified can be accurately extracted. Secondly, by finding adjacent semantic sentence vectors with semantic adjacency for each text sentence vector in the text sentence vector set, and then remapping the text sentence vector set according to the adjacency relationship, an optimized sentence vector set is obtained. This can remove some meaningless sentence information while retaining the effective semantic information of the text sentence vector set, thereby improving the ability of sentence vectors to represent sentence semantic information and facilitating subsequent improvement in text classification efficiency. Finally, by constructing positive sample pairs and negative sample pairs based on the optimized sentence vector set, the loss value between the positive and negative sample pair sets is calculated to further improve the ability to represent semantic information between sentences and perform classification of the text set to be classified. Applied in the medical field, this invention can solve the problem that the extracted sentence vectors from medical case texts cannot accurately represent the semantic information between sentences, resulting in low accuracy in medical case text classification. Therefore, the text classification method, apparatus, device, and storage medium proposed in this embodiment of the invention can improve the accuracy of text classification. Attached Figure Description

[0045] Figure 1 This is a flowchart illustrating a text classification method provided in an embodiment of the present invention;

[0046] Figure 2 This is a detailed flowchart illustrating one step of a text classification method provided in an embodiment of the present invention.

[0047] Figure 3This is a detailed flowchart illustrating one step of a text classification method provided in an embodiment of the present invention.

[0048] Figure 4 This is a schematic diagram of a text classification device provided in an embodiment of the present invention;

[0049] Figure 5 This is a schematic diagram of the internal structure of an electronic device that implements a text classification method according to an embodiment of the present invention.

[0050] The realization of the objective, functional features and advantages of the present invention will be further explained in conjunction with the embodiments and with reference to the accompanying drawings. Detailed Implementation

[0051] It should be understood that the specific embodiments described herein are merely illustrative of the invention and are not intended to limit the invention.

[0052] This invention provides a text classification method. The execution entity of the text classification method includes, but is not limited to, at least one of the following: a server, a terminal, or an electronic device configured to execute the method provided in this application embodiment. In other words, the text classification method can be executed by software or hardware installed on a terminal device or a server device, and the software can be a blockchain platform. The server includes, but is not limited to, a single server, a server cluster, a cloud server, or a cloud server cluster.

[0053] Reference Figure 1 The flowchart shown is a schematic diagram of a text classification method provided in an embodiment of the present invention. In this embodiment, the text classification method includes the following steps S1-S4:

[0054] S1. Obtain the text set to be classified and extract the text sentence vector set of the text set to be classified.

[0055] For example, in the medical field, the text set to be classified could be a collection of medical records from Hospital A over a year. The text sentence vector set refers to a set of vectors representing each sentence in the text as a fixed-length vector.

[0056] This invention can extract the text sentence vector set of the text set to be classified using the sentence encoding layer in a trained text classification model. In this invention, the text classification model is a neural network model composed of a sentence encoding layer, a remapping layer, a sample layer, and a classification layer. Specifically, the sentence encoding layer is used to initially generate a context-related text sentence vector set from the text set to be classified; the remapping layer is used to re-represent the spatial semantic information of the text sentence vector set to improve the accuracy of representing semantic information between sentences; the sample layer is used to construct positive and negative sample pairs to further improve the model's ability to learn and represent semantic information between sentences; and the classification layer is used to determine the category to which the text set to be classified belongs.

[0057] In one embodiment of the present invention, when training the text classification model, firstly, the text set to be classified and the corresponding standard classification results are obtained, and the sentence vector set of the text set to be classified is extracted through the sentence encoding layer. Then, the remapping layer is used to find the adjacent semantic sentence vectors with semantic adjacency for each text sentence vector in the text sentence vector set, and the spatial semantic information of the text sentence vector set is re-represented to obtain the optimized sentence vector set. Secondly, the sample layer constructs positive sample pairs and negative sample pairs based on the optimized sentence vector set, and then determines the target sentence vector set based on the sample loss value. Finally, the text to be classified is classified by the classification layer to obtain the predicted classification result, and the loss value between the standard classification result and the predicted classification result is calculated using a loss function (such as the ReLU function). The parameters of the text classification model are adjusted according to the loss value until the loss value meets the preset threshold, and the trained text classification model is obtained.

[0058] As an embodiment of the present invention, the step of extracting the text sentence vector set of the text set to be classified includes:

[0059] The text set to be classified is encoded to obtain a word vector feature set; the word vector feature set is weighted and pooled to obtain a dynamic word vector feature set; the dynamic word vector feature set is averaged and pooled to obtain a sentence vector set of the text set to be classified.

[0060] The sentence encoding layer in the text classification model is composed of a Transformer model. This model can encode the text to be classified in order to obtain a context-related word vector feature set.

[0061] Specifically, in this embodiment of the invention, the sentence encoding layer encodes the text set to be classified to obtain a word vector feature set:

[0062] h i =M(B i )

[0063] Among them, h i B represents the feature set of the i-th word vector; M represents the sentence encoding layer; B represents the feature set of the ith word vector. i This represents the i-th word in the text set to be classified.

[0064] Furthermore, in one embodiment of the present invention, the weighted pooling means taking the average of the first and last vectors in the vector sequence of the word vector feature set. Through weighted pooling, word vectors with semantic features from different layers can be fused to improve the semantic representation ability of word vectors.

[0065] Furthermore, in this embodiment of the invention, the average pooling means taking the average value of all dynamic word vector features in the dynamic word vector feature set, realizing information interaction between dynamic word vector features to generate a sentence vector set closely related to the context, further improving the semantic representation ability of sentence vectors, and facilitating accurate representation of semantic information between sentences.

[0066] S2. In the text sentence vector set, find the neighboring semantic sentence vectors that have a semantic adjacency relationship with each text sentence vector, obtain the adjacency relationship between each text sentence vector and the corresponding neighboring semantic sentence vector, and remap the text sentence vector set according to the adjacency relationship to obtain an optimized sentence vector set.

[0067] In this embodiment of the invention, the remapping layer in the text classification model can be used to find neighboring semantic sentence vectors that have a semantic adjacency relationship with each text sentence vector in the text sentence vector set, obtain the adjacency relationship between each text sentence vector in the text sentence vector set and its corresponding neighboring semantic sentence vector, and remap the text sentence vector set according to the adjacency relationship to obtain an optimized sentence vector set.

[0068] In this embodiment of the invention, the adjacent semantic sentence vector refers to a sentence vector that has a semantic adjacency relationship with a selected text sentence vector from the text sentence vector set. The optimized sentence vector set refers to the set of sentence vectors after spatial reconstruction among the sentence vectors in the text sentence vector set.

[0069] In this embodiment of the invention, since the extracted text sentence vector set is high-dimensional data, and the sentence vector ultimately represents semantic features through mapping in a low-dimensional space, in order to minimize data loss and reduce computational load during the process of text sentence vectors representing semantic features from high-dimensional to low-dimensional, the adjacency relationship between each text sentence vector and its corresponding adjacent semantic sentence vector is obtained by finding adjacent semantic sentence vectors with semantic adjacency relationships in the text sentence vector set for each text sentence vector. The text sentence vector set is then remapped according to the adjacency relationship to obtain an optimized sentence vector set. This can solve the problem in traditional techniques where the word representation space is anisotropic, high-frequency words cluster together and are close to the origin, while low-frequency words are sparsely distributed, and sentence representation is dominated by high-frequency words, making it impossible for the extracted sentence vectors to accurately represent the semantic information between sentences. This facilitates the improvement of the accuracy of case text classification in the future.

[0070] As an embodiment of the present invention, reference is made to... Figure 2 As shown, the step of finding neighboring semantic sentence vectors with semantic adjacency to each text sentence vector in the text sentence vector set includes the following steps S21-S23:

[0071] S21. Perform sentence frequency sampling on each text sentence vector in the text sentence vector set to obtain the sentence vector sampling space;

[0072] S22. Based on the sentence vector sampling space, find multiple candidate sentence vectors that are semantically adjacent to each text sentence vector;

[0073] S23. Calculate the Euclidean distance between each text sentence vector and the corresponding plurality of candidate sentence vectors, and perform semantic adjacency filtering on the plurality of candidate sentence vectors based on the Euclidean distance to obtain the adjacent semantic sentence vectors corresponding to each text sentence vector.

[0074] The sentence vector sampling space is a probability space that reflects the semantic proximity of selected text sentence vectors with other sentence vectors in a high-dimensional space. That is, the higher the sentence frequency information of a text sentence vector, the greater the probability that the text sentence vector is semantically adjacent to other sentence vectors.

[0075] In one embodiment of the present invention, since the sentence vector sampling space is a probability space that reflects the semantic adjacency of the selected text sentence vector with other sentence vectors in the high-dimensional space, the spatial probability of the selected text sentence vector and the corresponding sentence vector can be compared with a preset probability value (such as 0.75). When the spatial probability of the selected text sentence vector and the corresponding sentence vector is greater than the preset probability value, the sentence vector is used as a candidate sentence vector of the selected text sentence vector.

[0076] In this embodiment of the invention, the Euclidean distance can be calculated using the Euclidean formula. Furthermore, this invention can select the k closest candidate sentences from the calculated Euclidean distances between the text sentence vector and the corresponding multiple candidate sentences as the adjacent semantic sentence vectors corresponding to the text sentence vector. By finding the k candidate sentences that are semantically adjacent to the text sentence vector, it is possible to retain the effective semantic information of the text sentence vector set while removing some meaningless sentence information, thereby improving the ability of the sentence vector to represent the semantic information of the sentence.

[0077] Further, the step of remapping the text sentence vector set according to the adjacency relationship to obtain an optimized sentence vector set includes:

[0078] Calculate the neighborhood reconstruction weight of each text sentence vector in the text sentence vector set based on the adjacency relationship; determine the global connection relationship between each text sentence vector based on the neighborhood reconstruction weight; and perform spatial mapping on the text sentence vectors based on the global connection relationship to obtain the optimized sentence vector set.

[0079] The neighborhood reconstruction weights refer to the weights of local correlation between each text sentence vector reconstructed in the low-dimensional space and in the high-dimensional space. These neighborhood reconstruction weights can be obtained using the Lagrange multiplier method. To ensure the accuracy of sentence vector representation of semantic features, calculating the neighborhood reconstruction weights allows for the reconstruction of the spatial structure of each text sentence vector in the high-dimensional space from the low-dimensional space, thus guaranteeing the accuracy of sentence vector representation of semantic features.

[0080] In one embodiment of the present invention, the Lagrange multiplier method is used to calculate the neighborhood reconstruction weights and each text sentence vector to determine the low-dimensional sentence vector corresponding to each text sentence vector, and to identify the structural relationship between the low-dimensional sentence vectors corresponding to each text sentence vector, that is, to determine the global connection relationship between each text sentence vector. Based on the structural relationship of the low-dimensional sentence vectors, the text sentence vector set is spatially mapped to obtain an optimized sentence vector set.

[0081] S3. Construct positive sample set pairs and negative sample set pairs based on the optimized sentence vector set, calculate the sample loss value generated by the positive sample set pairs and the negative sample set pairs, and determine the target sentence vector set based on the sample loss value.

[0082] In this embodiment of the invention, a positive sample pair set and a negative sample pair set can be constructed using the sample layer in the text classification model based on the optimized sentence vector set. The sample loss value generated by the positive sample pair set and the negative sample pair set is calculated, and the target sentence vector set is determined based on the sample loss value.

[0083] This invention constructs a set of positive sample pairs and a set of negative sample pairs based on the optimized sentence vector set, thereby learning a more accurate semantic representation of case sentences, which facilitates the improvement of the accuracy of subsequent case text classification.

[0084] As an embodiment of the present invention, reference is made to... Figure 3 As shown, the construction of the positive sample pair set and the negative sample pair set based on the optimized sentence vector set includes the following steps S31-S37:

[0085] S31. Select one of the optimized sentence vectors in the set of optimized sentence vectors one by one according to the preset order;

[0086] S32. Back-translate the selected optimized sentence vector to obtain the corresponding back-translated sentence vector, and combine the selected optimized sentence vector and the corresponding back-translated sentence vector to obtain a positive sample pair;

[0087] S33. Replace the selected optimized sentence vector with antonyms to obtain the corresponding antonym sentence vector. Combine the selected optimized sentence vector and the corresponding antonym sentence vector to obtain antonym negative sample pairs.

[0088] S34. Randomly select any optimized sentence vector other than the selected optimized sentence vector from the optimized sentence vector set to obtain a sampled sentence vector. Combine the selected optimized sentence vector and the sampled sentence vector to obtain a sampled negative sample pair.

[0089] S35. Combine the antonym negative sample pairs and the sampled negative sample pairs to obtain negative sample pairs;

[0090] S36. Determine whether all optimized sentence vectors in the optimized sentence vector set have been selected;

[0091] S37. After all optimized sentence vectors in the optimized sentence vector set have been selected, a positive sample pair set and a negative sample pair set are obtained.

[0092] If not all optimized sentence vectors in the optimized sentence vector set have been selected, return to S31 until all optimized sentence vectors in the optimized sentence vector set have been selected.

[0093] The preset order can be the order of the optimized sentence vector sets. Back-translation refers to translating the text set to be classified corresponding to the optimized sentence vector set into another language, and then translating that language back into the original language. This can be achieved using Baidu Translate or Google Translate. Since the back-translated sentences often differ from the original sentences but still share some similarities, back-translation not only expands the data but also increases the number of similar data within the expanded data. This results in a greater distinction in sentence structure between the back-translated sentences and the sentences in the text to be classified, facilitating the improvement of subsequent accuracy in identifying similar sentences and thus enhancing the accuracy of text classification.

[0094] In one embodiment of the present invention, the antonym replacement can be performed by a converter to search for multiple words containing antonyms in the text to be classified corresponding to the sentence vector set, and then perform batch antonym replacement. The antonym samples generated by the antonym replacement, compared with the original sentences of the text to be classified, can serve as negative antonym samples with the same sentence length and similar structure as the original sentences. This increases the amount of negative sample data, and since the sentence length of the negative antonym samples is the same as the original sentences and their sentence structures are similar, it can further improve the accuracy of the model in learning the semantic representation of sentences with similar semantic structures.

[0095] Furthermore, in this embodiment of the invention, the optimized sentence vector set can be randomly sampled using a random sampler (such as RandomSampler). Specifically, the optimized sentence vector set is divided into multiple batches, random sampling is performed from each batch, and the sampled vector sets in each batch are merged to obtain the sampled sentence vector set.

[0096] In one embodiment of the present invention, the sample loss value can be calculated using the following formula:

[0097]

[0098] in, Represents the sample loss value; N represents the number of negative sample pairs; j represents one of the negative sample pairs; (h i ,h′ i ) represents the set of positive sample pairs; h i h′ represents the vector of the i-th optimized sentence. i The vector of the i-th back-translated sentence; (h i ,h′ j ) represents the set of negative sample pairs; h′ j This represents the vector of the j-th sampled sentence; This represents the set of negative sample pairs for antonyms; Represents the vector of the i-th antonym; sim(h i ,h′ i ) represents the cosine similarity between positive sample pairs; sim(h i ,h′ j () represents the cosine similarity between pairs of sampled negative samples; τ represents the cosine similarity between negative sample pairs of antonyms; τ represents the temperature coefficient. The smaller the temperature coefficient, the better the positive sample pairs can be separated from the negative sample pairs, resulting in a more uniform sample representation.

[0099] In this embodiment of the invention, by calculating the sample loss values ​​of positive and negative sample pairs, the consistency of the input of positive sample pairs is maximized, that is, the spatial distance of semantic vectors in positive sample pairs is closer and the spatial distance of semantic vectors in negative sample pairs is farther, thereby learning more accurate sentence semantic representations, which facilitates the improvement of the accuracy of subsequent case text classification.

[0100] Further, determining the target sentence vector set based on the sample loss value includes:

[0101] Determine whether the sample loss value is less than a preset threshold; if the sample loss value is not less than the preset threshold, reconstruct the positive sample set and the negative sample set until the sample loss value is less than the preset threshold; if the sample loss value is less than the preset threshold, use the optimized sentence vector set corresponding to the sample loss value as the target sentence vector set.

[0102] The preset threshold can be 0.2. By judging whether the sample loss value is less than the preset threshold, the rationality of the constructed positive and negative sample pair set can be verified to ensure the accuracy of the semantic information between sentences. When it is verified that the constructed positive and negative sample pair set is unreasonable, the optimized sentence vector set can be randomly sampled again until the sample loss value is less than the preset threshold, which further improves the accuracy of the semantic representation of the case sentences.

[0103] S4. Perform text classification on the target sentence vector set to obtain the classification result of the text set to be classified.

[0104] In this embodiment of the invention, the classification layer in the text classification model can be used to classify the target sentence vector set.

[0105] In this embodiment of the invention, the classification layer includes an attention mechanism and an activation function, which are used to classify the target sentence vector set into categories. The classification result refers to the classification category to which the text set to be classified belongs. For example, if a medical text describes a patient with symptoms such as acute onset, chills, high fever, cough, white phlegm, dullness on percussion of the left upper lung, and increased vocal fremitus, and the case is diagnosed as left-sided pneumonia, then the classification result of the medical text is the pneumonia case diagnosis category.

[0106] As an embodiment of the present invention, the step of performing text classification on the target sentence vector set to obtain the classification result of the text set to be classified includes:

[0107] Extract the sentence vector feature set of the target sentence vector set; calculate the category probability of the sentence vector feature set, and select the category with the highest probability from the category probabilities as the classification result of the text set to be classified.

[0108] Specifically, the Q (query), K (key), and V (value) values ​​of the target sentence vector set can be extracted through an attention mechanism, and the features of the Q, K, and V values ​​can be extracted by outputting the tan linear function, thus extracting the sentence vector feature set of the target sentence vector set.

[0109] In one embodiment of the present invention, an activation function (such as the Softmax function) can be used to output the probability of the category to which the sentence vector feature set belongs. For example, if there is a medical text A, the probability of belonging to the case diagnosis category is 0.85 and the probability of belonging to the case treatment category is 0.65. Then, the case diagnosis category with the highest probability is selected from the above two category probabilities as the classification result of the medical text A.

[0110] In this embodiment of the invention, firstly, the text sentence vector set of the text set to be classified can be accurately extracted. Secondly, by finding adjacent semantic sentence vectors with semantic adjacency for each text sentence vector in the text sentence vector set, and then remapping the text sentence vector set according to the adjacency relationship, an optimized sentence vector set is obtained. This can remove some meaningless sentence information while retaining the effective semantic information of the text sentence vector set, thereby improving the ability of sentence vectors to represent sentence semantic information and facilitating subsequent improvement in text classification efficiency. Finally, by constructing positive and negative sample pairs based on the optimized sentence vector set, the loss value between the positive and negative sample pair sets is calculated to further improve the ability to represent semantic information between sentences and perform classification of the text set to be classified. Applied in the medical field, this method can solve the problem that the extracted sentence vectors from medical case texts cannot accurately represent the semantic information between sentences, resulting in low accuracy in medical case text classification. Therefore, the text classification method proposed in this embodiment of the invention can improve the accuracy of text classification.

[0111] like Figure 4 As shown, the text classification device 100 of the present invention can be installed in an electronic device. Depending on the functions implemented, the text classification device may include an encoding module 101, a remapping module 102, a sample construction module 103, and a classification module 104. The module in this invention can also be called a unit, which refers to a series of computer program segments that can be executed by the processor of an electronic device and can perform a fixed function, and which are stored in the memory of the electronic device.

[0112] In this embodiment, the functions of each module / unit are as follows:

[0113] In detail, each module in the text classification device 100 described in this embodiment of the invention employs the same methods as described above during use. Figures 1 to 3 The text classification method described herein uses the same technical means and can produce the same technical effect, so it will not be elaborated here.

[0114] like Figure 5 The diagram shown is a schematic representation of the structure of the electronic device that implements the text classification method of the present invention.

[0115] The electronic device may include a processor 10, a memory 11, a communication bus 12 and a communication interface 13, and may also include a computer program, such as a text classification program, stored in the memory 11 and capable of running on the processor 10.

[0116] The memory 11 includes at least one type of medium, such as flash memory, portable hard drive, multimedia card, card-type memory (e.g., SD or DX memory), magnetic memory, local disk, optical disk, etc. In some embodiments, the memory 11 can be an internal storage unit of an electronic device, such as a portable hard drive. In other embodiments, the memory 11 can be an external storage device of the electronic device, such as a plug-in portable hard drive, Smart Media Card (SMC), Secure Digital (SD) card, Flash Card, etc. Furthermore, the memory 11 can include both internal and external storage units of the electronic device. The memory 11 can be used not only to store application software and various types of data installed on the electronic device, such as the code of a text classification program, but also to temporarily store data that has been output or will be output.

[0117] In some embodiments, the processor 10 may be composed of integrated circuits, such as a single packaged integrated circuit or multiple integrated circuits with the same or different functions, including combinations of one or more central processing units (CPUs), microprocessors, digital processing chips, graphics processors, and various control chips. The processor 10 is the control unit of the electronic device, connecting various components of the entire electronic device through various interfaces and lines. It executes programs or modules (e.g., text classification programs) stored in the memory 11, and calls data stored in the memory 11 to perform various functions of the electronic device and process data.

[0118] The communication bus 12 can be a Peripheral Component Interconnect (PCI) bus or an Extended Industry Standard Architecture (EISA) bus, etc. This bus can be divided into an address bus, a data bus, a control bus, etc. The communication bus 12 is configured to enable communication between the memory 11 and at least one processor 10, etc. For ease of illustration, only one thick line is used in the figure, but this does not indicate that there is only one bus or one type of bus.

[0119] Figure 5 Only electronic devices with components are shown; those skilled in the art will understand that... Figure 5The structure shown does not constitute a limitation on the electronic device and may include fewer or more components than shown, or combine certain components, or have different component arrangements.

[0120] For example, although not shown, the electronic device may also include a power supply (such as a battery) to power the various components. Preferably, the power supply can be logically connected to the at least one processor 10 through a power management device, thereby enabling functions such as charging management, discharging management, and power consumption management. The power supply may also include one or more DC or AC power supplies, recharging devices, power fault detection circuits, power converters or inverters, power status indicators, and other arbitrary components. The electronic device may also include various sensors, Bluetooth modules, Wi-Fi modules, etc., which will not be described in detail here.

[0121] Optionally, the communication interface 13 may include a wired interface and / or a wireless interface (such as a Wi-Fi interface, a Bluetooth interface, etc.), which is typically used to establish communication connections between the electronic device and other electronic devices.

[0122] Optionally, the communication interface 13 may further include a user interface, which may be a display, an input unit (such as a keyboard), or, optionally, a standard wired or wireless interface. Optionally, in some embodiments, the display may be an LED display, a liquid crystal display, a touch-sensitive liquid crystal display, or an OLED (Organic Light-Emitting Diode) touchscreen, etc. The display may also be appropriately referred to as a screen or display unit, used to display information processed in the electronic device and to display a visual user interface.

[0123] It should be understood that the embodiments described are for illustrative purposes only and are not limited to this structure in the scope of the patent application.

[0124] The text classification program stored in the memory 11 of the electronic device is a combination of multiple computer programs, which, when run in the processor 10, can achieve the following:

[0125] Obtain the text set to be classified, and extract the text sentence vector set of the text set to be classified;

[0126] In the text sentence vector set, for each text sentence vector, find the neighboring semantic sentence vectors that have a semantic adjacency relationship with it, obtain the adjacency relationship between each text sentence vector in the text sentence vector set and its corresponding neighboring semantic sentence vectors, and remap the text sentence vector set according to the adjacency relationship to obtain an optimized sentence vector set;

[0127] Construct a set of positive sample pairs and a set of negative sample pairs based on the optimized sentence vector set, calculate the sample loss value generated by the set of positive sample pairs and the set of negative sample pairs, and determine the target sentence vector set based on the sample loss value;

[0128] The target sentence vector set is classified into texts to obtain the classification result of the text set to be classified.

[0129] Specifically, the processor 10's implementation method of the above-mentioned computer program can be found in [reference needed]. Figure 1 The descriptions of the relevant steps in the corresponding embodiments are not repeated here.

[0130] Furthermore, if the modules / units integrated into the electronic device are implemented as software functional units and sold or used as independent products, they can be stored in a computer-readable medium. The computer-readable medium can be non-volatile or volatile. The computer-readable medium may include: any entity or device capable of carrying the computer program code, a recording medium, a USB flash drive, a portable hard drive, a magnetic disk, an optical disk, a computer memory, or a read-only memory (ROM).

[0131] This invention also provides a computer-readable storage medium storing a computer program, which, when executed by a processor of an electronic device, can perform the following:

[0132] Obtain the text set to be classified, and extract the text sentence vector set of the text set to be classified;

[0133] In the text sentence vector set, for each text sentence vector, find the neighboring semantic sentence vectors that have a semantic adjacency relationship with it, obtain the adjacency relationship between each text sentence vector in the text sentence vector set and its corresponding neighboring semantic sentence vectors, and remap the text sentence vector set according to the adjacency relationship to obtain an optimized sentence vector set;

[0134] Construct a set of positive sample pairs and a set of negative sample pairs based on the optimized sentence vector set, calculate the sample loss value generated by the set of positive sample pairs and the set of negative sample pairs, and determine the target sentence vector set based on the sample loss value;

[0135] The target sentence vector set is classified into texts to obtain the classification result of the text set to be classified.

[0136] Furthermore, the computer-readable storage medium may primarily include a program storage area and a data storage area, wherein the program storage area may store the operating system, at least one application required for a function, etc.; and the data storage area may store data created based on the use of blockchain nodes, etc.

[0137] In the several embodiments provided by this invention, it should be understood that the disclosed media, devices, apparatuses, and methods can be implemented in other ways. For example, the apparatus embodiments described above are merely illustrative; for instance, the division of modules is only a logical functional division, and other division methods may be used in actual implementation.

[0138] The modules described as separate components may or may not be physically separate. The components shown as modules may or may not be physical units; that is, they may be located in one place or distributed across multiple network units. Some or all of the modules can be selected to achieve the purpose of this embodiment according to actual needs.

[0139] Furthermore, the functional modules in the various embodiments of the present invention can be integrated into one processing unit, or each unit can exist physically separately, or two or more units can be integrated into one unit. The integrated unit can be implemented in hardware or in the form of hardware plus software functional modules.

[0140] It will be apparent to those skilled in the art that the present invention is not limited to the details of the exemplary embodiments described above, and that the present invention can be implemented in other specific forms without departing from the spirit or essential characteristics of the present invention.

[0141] Therefore, the embodiments should be considered exemplary and non-limiting in all respects, and the scope of the invention is defined by the appended claims rather than the foregoing description. Thus, all variations falling within the meaning and scope of equivalents of the claims are intended to be embraced within the invention. No appended diagram markings in the claims should be construed as limiting the scope of the claims.

[0142] The blockchain referred to in this invention is a novel application model of computer technologies such as distributed data storage, peer-to-peer transmission, consensus mechanisms, and encryption algorithms. Essentially, a blockchain is a decentralized database, a chain of data blocks linked together using cryptographic methods. Each data block contains information about a batch of network transactions, used to verify the validity of the information (anti-counterfeiting) and generate the next block. A blockchain can include an underlying blockchain platform, a platform product service layer, and an application service layer.

[0143] Furthermore, it is clear that the word "comprising" does not exclude other units or steps, and the singular does not exclude the plural. Multiple units or devices recited in a system claim may also be implemented by a single unit or device through software or hardware. The term "second class" is used to indicate names and does not indicate any specific order.

[0144] Finally, it should be noted that the above embodiments are only used to illustrate the technical solutions of the present invention and are not intended to limit it. Although the present invention has been described in detail with reference to preferred embodiments, those skilled in the art should understand that modifications or equivalent substitutions can be made to the technical solutions of the present invention without departing from the spirit and scope of the technical solutions of the present invention.

Claims

1. A text classification method, characterized in that, The method includes: Obtain the text set to be classified, and extract the text sentence vector set of the text set to be classified; In the text sentence vector set, for each text sentence vector, find the neighboring semantic sentence vectors that have a semantic adjacency relationship with it, obtain the adjacency relationship between each text sentence vector in the text sentence vector set and its corresponding neighboring semantic sentence vectors, and remap the text sentence vector set according to the adjacency relationship to obtain an optimized sentence vector set; Construct a set of positive sample pairs and a set of negative sample pairs based on the optimized sentence vector set, calculate the sample loss value generated by the set of positive sample pairs and the set of negative sample pairs, and determine the target sentence vector set based on the sample loss value; The target sentence vector set is classified into texts to obtain the classification result of the text set to be classified. The step of finding neighboring semantic sentence vectors that have a semantic adjacency relationship with each text sentence vector in the text sentence vector set includes: sampling the sentence frequency of each text sentence vector in the text sentence vector set to obtain a sentence vector sampling space; finding multiple candidate sentence vectors that are semantically adjacent to each text sentence vector according to the sentence vector sampling space; calculating the Euclidean distance between each text sentence vector and the corresponding multiple candidate sentence vectors; and performing semantic adjacency filtering on the multiple candidate sentence vectors according to the Euclidean distance to obtain the neighboring semantic sentence vectors corresponding to each text sentence vector. The step of remapping the text sentence vector set according to the adjacency relationship to obtain an optimized sentence vector set includes: calculating the neighborhood reconstruction weight of each text sentence vector in the text sentence vector set according to the adjacency relationship; determining the global connection relationship between each text sentence vector according to the neighborhood reconstruction weight; and spatially mapping the text sentence vectors according to the global connection relationship to obtain the optimized sentence vector set.

2. The text classification method as described in claim 1, characterized in that, The step of constructing a set of positive sample pairs and a set of negative sample pairs based on the optimized sentence vector set includes: Step A: Select one of the optimized sentence vectors from the set of optimized sentence vectors one by one according to the preset order; Step B: Back-translate the selected optimized sentence vector to obtain the corresponding back-translated sentence vector, and combine the selected optimized sentence vector and the corresponding back-translated sentence vector to obtain a positive sample pair; Step C: Replace the selected optimized sentence vector with antonyms to obtain the corresponding antonym sentence vector. Combine the selected optimized sentence vector and the corresponding antonym sentence vector to obtain antonym negative sample pairs. Step D: Randomly select any optimized sentence vector other than the selected optimized sentence vector from the optimized sentence vector set to obtain a sampled sentence vector. Combine the selected optimized sentence vector and the sampled sentence vector to obtain a sampled negative sample pair. Step E: Combine the antonym negative sample pairs and the sampled negative sample pairs to obtain negative sample pairs; Repeat steps A through E above until all optimized sentence vectors in the optimized sentence vector set have been selected, thus obtaining a set of positive sample pairs and a set of negative sample pairs.

3. The text classification method as described in any one of claims 1-2, characterized in that, Determining the target sentence vector set based on the sample loss value includes: Determine whether the sample loss value is less than a preset threshold; When the sample loss value is not less than a preset threshold, the positive sample pair set and the negative sample pair set are reconstructed until the sample loss value is less than the preset threshold. When the sample loss value is less than a preset threshold, the optimized sentence vector set corresponding to the sample loss value is used as the target sentence vector set.

4. The text classification method as described in any one of claims 1-2, characterized in that, The extraction of the text sentence vector set from the text set to be classified includes: The text set to be classified is encoded to obtain a word vector feature set; The word vector feature set is weighted and pooled to obtain a dynamic word vector feature set; The dynamic word vector feature set is averaged and pooled to obtain the sentence vector set of the text set to be classified.

5. The text classification method as described in any one of claims 1-2, characterized in that, The step of performing text classification on the target sentence vector set to obtain the classification result of the text set to be classified includes: Extract the sentence vector feature set of the target sentence vector set; Calculate the category probability of the sentence vector feature set, and select the category with the highest probability from the category probabilities as the classification result of the text set to be classified.

6. A text classification apparatus for implementing the text classification method as described in any one of claims 1 to 5, characterized in that, The device includes: The encoding module is used to acquire the text set to be classified and extract the text sentence vector set of the text set to be classified; The remapping module is used to find multiple adjacent semantic sentence vectors that have a semantic adjacency relationship with each text sentence vector in the text sentence vector set, obtain the adjacency relationship between each text sentence vector in the text sentence vector set and the multiple adjacent semantic sentence vectors, and remap the text sentence vector set according to the adjacency relationship to obtain an optimized sentence vector set; The sample construction module is used to construct a positive sample pair set and a negative sample pair set based on the optimized sentence vector set, calculate the sample loss value generated by the positive sample pair set and the negative sample pair set, and determine the target sentence vector set based on the sample loss value. The classification module is used to perform text classification on the target sentence vector set to obtain the classification result of the text set to be classified.

7. An electronic device, characterized in that, The electronic device includes: At least one processor; and, A memory communicatively connected to the at least one processor; wherein, The memory stores a computer program that can be executed by the at least one processor, the computer program being executed by the at least one processor to enable the at least one processor to perform the text classification method as described in any one of claims 1 to 5.

8. A computer-readable storage medium storing a computer program, characterized in that, When the computer program is executed by a processor, it implements the text classification method as described in any one of claims 1 to 5.

Citation Information

Patent Citations

  • Electronic contract task assignment method based on deep semantic analysis

    CN117408449A

  • Information classification extraction method, apparatus, computer device and storage medium

    WO2021042503A1