Model obtaining method, classification method, device, electronic device and storage medium
Patent Information
- Application Number
- CN202310197554.4
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2023-03-01
- Publication Date
- 2026-08-21
- Estimated Expiration
- 2043-03-01
AI Technical Summary
由于不平衡数据中少数类样本的数量远少于多数类样本,利用不平衡数据训练得到的分类模型会因为缺乏足够的数据,对少数类样本的刻画能力不足,难以有效的对这些少数类样本进行分类,容易将少数类的样本错误的识别为多数类样本,造成分类模型的分类性能低
[0037]通过以上方案可知,本申请提供的一种模型获得方法、分类方法、装置及电子设备和存储介质,先对文本分类模型进行初始训练,基于利用样本数据集对初始文本分类模型的测试结果,确定分类性能较低的目标类别,以及目标类别最容易被错误识别成的配对类别,从目标类别及其配对类别对应的样本数据中提取目标类别对应的描述逻辑和配对类别对应的描述逻辑,然后对初始文本分类模型进行目标训练,在目标训练过程中,初始文本分类模型的参数的更新除了考虑类别标签外,还考虑了目标类别及其配对类别的描述逻辑,而任一类别对应的描述逻辑表征样本数据所包含的知识与该任一类别的关联关系,因此,本申请的文本分类模型的获得方法在样本数据集为不平衡数据集的情况下,也能够使文本分类模型学习到少数类别和其他类别间更多的区别信息,从而提高文本分类模型的分类性能。
Smart Images

Figure CN116226713B_ABST
Abstract
Description
Technical Field
[0001] This application relates to the field of machine learning technology, and more specifically, to a model acquisition method, classification method, apparatus, electronic device, and storage medium. Background Technology
[0002] In real-world classification tasks, the number of samples in each class is often not perfectly balanced. It frequently occurs that the number of samples in one or more classes is far less than the number of samples in other classes, making data imbalance a common problem in machine learning tasks. Because the number of minority class samples in imbalanced data is much smaller than that of majority class samples, classification models trained on imbalanced data lack sufficient data to adequately characterize minority class samples. This makes it difficult to effectively classify these minority class samples, and they are prone to misidentifying minority class samples as majority class samples, resulting in low classification performance.
[0003] Therefore, improving the classification performance of classification models has become an urgent technical problem to be solved. Summary of the Invention
[0004] The purpose of this application is to provide a model acquisition method, a classification method, an apparatus, an electronic device, and a storage medium, including the following technical solutions:
[0005] A model acquisition method, the method comprising:
[0006] The initial text classification model is obtained by initially training the text classification model with the target number of times using the sample dataset;
[0007] The initial text classification model is tested using the sample dataset to determine the target category and its paired categories; wherein, the initial text classification model performs worse in classifying the target category than in classifying non-target categories; and the number of sample data of the target category that are incorrectly identified as paired categories is greater than the number that are incorrectly identified as non-paired categories.
[0008] From the target sample data belonging to any target category and its paired category in the sample dataset, extract the description logic corresponding to each target category and its paired category respectively; the description logic corresponding to any category represents the relationship between the knowledge contained in the sample data and the target category.
[0009] The initial text classification model is trained using the sample dataset to obtain the target text classification model. During the training process, the parameters of the initial text classification model are updated based on the category labels of each sample data in the sample dataset and the description logic.
[0010] Optionally, in the above method, the process of determining the target category includes:
[0011] Statistical analysis is performed on the sample data belonging to the first category label in the sample dataset, as well as the sample data that was misclassified as the first category label by the initial text classification model, to determine the classification accuracy and classification recall corresponding to the first category label;
[0012] If the classification accuracy and classification recall corresponding to the first category label meet the target conditions, the first category label is determined to be the target category.
[0013] Optionally, in the above method, the process of determining the target category includes:
[0014] If at least one sample data in the sample dataset belonging to the first category label is incorrectly classified as a non-first category label, the first category label is determined as the target category.
[0015] Optionally, in the above method, updating the parameters of the initial text classification model based on the category labels of each sample data in the sample dataset and the description logic includes:
[0016] The parameters of the initial text classification model are updated with the goal of ensuring that the classification results of each sample data output by the initial text classification model are close to the category labels of the sample data input to the initial text classification model, and that the classification results of the sample data output by the initial text classification model that conform to the description logic match the description logic.
[0017] Optionally, the process of updating the parameters of the initial text classification model in the above method includes:
[0018] Obtain the first loss value between the classification result output by the initial text classification model and the category label of the sample data input to the initial text classification model;
[0019] Obtain a second loss value showing the degree of matching between the classification result of the sample data that conforms to the description logic output by the initial text classification model and the description logic;
[0020] The target second loss value is obtained by weighted summing of the second loss values corresponding to the sample data that conform to the description logic input into the initial text classification model;
[0021] The parameters of the initial text classification model are updated with the goal of minimizing the total loss value obtained based on the first loss value and the target second loss value.
[0022] Optionally, in the above method, the weights of the sample data that conform to the description logic and are input to the initial text classification model corresponding to the second loss value are pre-configured parameters.
[0023] The above methods may optionally include:
[0024] With the goal of minimizing the total loss value obtained based on the first loss value and the target second loss value, the weights of the sample data corresponding to the second loss value that conform to the description logic input into the initial text classification model are updated.
[0025] A classification method, the method comprising:
[0026] Input text data into a text classification model to obtain the classification result corresponding to the text data output by the text classification model;
[0027] The text classification model is obtained through the model acquisition method described in any of the preceding items.
[0028] A model acquisition apparatus, the apparatus comprising:
[0029] The first training module is used to perform initial training of the text classification model using the sample dataset to obtain the initial text classification model.
[0030] The testing module is used to test the initial text classification model using the sample dataset to determine the target category and its paired categories; wherein the initial text classification model's classification performance for the target category is lower than its classification performance for non-target categories; and the number of sample data of the target category that are incorrectly identified as the paired category is greater than the number that are incorrectly identified as non-paired categories.
[0031] The extraction module is used to extract the description logic corresponding to each target category and its paired category from the target sample data belonging to each target category and its paired category in the sample dataset; the description logic corresponding to each category represents the relationship between the knowledge contained in the sample data and the target category.
[0032] The second training module is used to perform target training on the initial text classification model using the sample dataset to obtain the target text classification model; during the training process, the parameters of the initial text classification model are updated based on the category labels of each sample data in the sample dataset and the description logic.
[0033] An electronic device, comprising:
[0034] Memory, used to store programs;
[0035] A processor for calling and executing the program in the memory, thereby implementing the steps of the model acquisition method and / or classification method as described in any of the preceding claims.
[0036] A readable storage medium having a computer program stored thereon, which, when executed by a processor, implements the steps of the model acquisition method and / or classification method as described in any of the preceding claims.
[0037] As can be seen from the above scheme, the model acquisition method, classification method, device, electronic device, and storage medium provided in this application first perform initial training on the text classification model. Based on the test results of the initial text classification model using the sample dataset, the target category with low classification performance and the paired category that the target category is most likely to be misidentified are determined. The description logic corresponding to the target category and the description logic corresponding to the paired category are extracted from the sample data corresponding to the target category and its paired category. Then, the initial text classification model is trained on the target. During the target training process, the update of the parameters of the initial text classification model considers not only the category label but also the description logic of the target category and its paired category. The description logic corresponding to any category represents the relationship between the knowledge contained in the sample data and any category. Therefore, the text classification model acquisition method of this application can enable the text classification model to learn more distinguishing information between a few categories and other categories even when the sample dataset is an imbalanced dataset, thereby improving the classification performance of the text classification model. Attached Figure Description
[0038] To more clearly illustrate the technical solutions of the embodiments of this application, the accompanying drawings used in the embodiments will be briefly introduced below. Obviously, the drawings described below are only some embodiments of this application. For those skilled in the art, other drawings can be obtained based on these drawings without creative effort.
[0039] Figure 1 A flowchart illustrating an implementation of the model acquisition method provided in this application embodiment;
[0040] Figure 2 A flowchart illustrating the determination of a target category provided in this application embodiment;
[0041] Figure 3 A schematic diagram of an architecture for obtaining the total loss value provided in an embodiment of this application;
[0042] Figure 4 A schematic diagram of the model acquisition device provided in the embodiments of this application;
[0043] Figure 5This is a schematic diagram of the structure of an electronic device provided in an embodiment of this application.
[0044] The terms "first," "second," "third," "fourth," etc. (if present) in the specification, claims, and accompanying drawings are used to distinguish similar parts and are not necessarily used to describe a specific order or sequence. It should be understood that such data can be interchanged where appropriate so that the embodiments of this application described herein can be implemented in a sequence other than that illustrated herein. Detailed Implementation
[0045] The technical solutions of the embodiments of this application will be clearly and completely described below with reference to the accompanying drawings. Obviously, the described embodiments are only some embodiments of this application, and not all embodiments. Based on the embodiments of this application, all other embodiments obtained by those of ordinary skill in the art without creative effort are within the scope of protection of this application.
[0046] The model acquisition method provided in this application embodiment can be used in electronic devices, which can be terminal devices or servers, which can be single servers or server clusters.
[0047] like Figure 1 The diagram shown is a flowchart of one implementation of the model acquisition method provided in this application, which may include:
[0048] Step S101: Use the sample dataset to perform initial training of the text classification model to obtain the initial text classification model.
[0049] The sample data in the sample dataset is text data, and the sample dataset can be a balanced dataset or an imbalanced dataset.
[0050] The initial training process for a text classification model can include: inputting sample data from the sample dataset into the text classification model to obtain the categories of the sample data output by the model (usually represented by the probability of the sample data belonging to each category label). For ease of distinction, the categories of the sample data output by the text classification model are denoted as the predicted categories. Based on the category labels and predicted categories of the sample data, the parameters of the text classification model are updated. Specifically, the goal can be to update the parameters of the text classification model so that the predicted categories of the sample data output by the model approximate the category labels of the sample data.
[0051] Initial training of a text classification model with a target number of iterations refers to iteratively training the model with the target number of iterations. For example, the target number of iterations can be once or multiple times. Due to the limited number of training iterations, the initial text classification model cannot yet be deployed to real-world applications.
[0052] Step S102: Test the initial text classification model using the above sample dataset to determine the target category and its paired categories; wherein, the initial text classification model's classification performance for the target category is lower than its classification performance for non-target categories; the number of target category sample data incorrectly identified as paired categories is greater than the number incorrectly identified as non-paired categories.
[0053] Each sample data in the sample dataset can be input into the initial text classification model to obtain the predicted category of each sample data output by the initial text classification model.
[0054] The predicted category of each sample data is compared with the category label to determine the target category and its paired category.
[0055] Step S103: Extract the description logic corresponding to each target category and its paired category from the target sample data belonging to any target category and its paired category in the sample dataset; the description logic corresponding to any category represents the relationship between the knowledge contained in the sample data and any category.
[0056] The category label of the target sample data is either any of the above target categories or a paired category of any of the above target categories.
[0057] Optionally, a logic extractor (e.g., DL-Learner) can be used to extract the description logic corresponding to the target category and the description logic corresponding to the paired category of the target category from the target sample data.
[0058] Optionally, topic modeling models can be used to extract topic words from each target sample data, and description logic corresponding to the target category can be constructed based on the topic words, or description logic corresponding to the paired categories of the target category can be constructed based on the topic words.
[0059] Optionally, keywords can be extracted from each target sample data using TF-IDF (term frequency–inverse document frequency), and description logic corresponding to the target category can be constructed based on the keywords, or description logic corresponding to the paired categories of the target category can be constructed based on the topic words.
[0060] As an example, the association between the knowledge contained in any sample data and any category may include, but is not limited to: if any sample data contains keywords corresponding to any category, then any sample data belongs to that category. This descriptive logic can be represented by a logical expression of the form of formula (1):
[0061] Contains(w i )→Positive Class with 100% accuracy (1)
[0062] Among them, w i Let w represent the keyword corresponding to the i-th category. The above logical expression means: if a text contains the keyword w i This text must belong to the i-th category.
[0063] The keyword here is w i It can represent a single keyword or a set of keywords.
[0064] Step S104: Use the sample dataset to train the initial text classification model to obtain the target text classification model; during the training process, update the parameters of the initial text classification model based on the category labels of each sample data in the sample dataset and the above description logic.
[0065] The sample dataset can be input into the initial text classification model to obtain the predicted category of each sample data point output by the initial text classification model. Based on the predicted category, category label, and the aforementioned descriptive logic, the parameters of the initial text classification model are updated.
[0066] The model acquisition method provided in this application first performs initial training on a text classification model to obtain an initial text classification model. Based on the test results of the initial text classification model using a sample dataset, it identifies the target category with low classification performance and the paired category that the target category is most likely to be misidentified. It extracts the description logic corresponding to the target category and the description logic corresponding to the paired category from the sample data corresponding to the target category and its paired category. Then, it performs target training on the initial text classification model. During the target training process, the update of the parameters of the initial text classification model considers not only the category label but also the description logic of the target category and its paired category. The description logic corresponding to any category represents the relationship between the knowledge contained in the sample data and any category, enabling the text classification model to learn more knowledge during training. Therefore, the method for obtaining the text classification model in this application can enable the text classification model to learn more distinguishing information between a few categories and other categories even when the sample dataset is an imbalanced dataset, thereby improving the classification performance of the text classification model.
[0067] In an optional embodiment, one implementation of determining the target category provided in this application can be:
[0068] If at least one sample data in the sample dataset belonging to the first category label is incorrectly classified as a non-first category label, then the first category label is determined as the target category.
[0069] In other words, if any sample data belonging to the first category label is incorrectly identified as a non-first category label, the first category label will be determined as the target category.
[0070] In an optional embodiment, a flowchart of one implementation of determining the target category provided in this application is as follows: Figure 2 As shown, it may include:
[0071] Step S201: Determine the classification accuracy and classification recall corresponding to the first category label, including: performing statistical analysis on the sample data in the sample dataset that belong to the first category label, and the sample data that were misclassified as the first category label by the initial text classification model, in order to determine the classification accuracy and classification recall corresponding to the first category label.
[0072] The first category label can be any category label from all the category labels in the sample dataset.
[0073] The accuracy rate for the first category label refers to the proportion of sample data that is correctly identified as the first category label out of all sample data that are identified as the first category label.
[0074] The recall rate for the first category label refers to the proportion of sample data belonging to the first category label that is correctly identified as the first category label.
[0075] Step S202: If the classification accuracy and classification recall corresponding to the first category label meet the target conditions, determine the first category label as the target category.
[0076] Optionally, the F-value corresponding to the first category label can be calculated based on the classification accuracy and classification recall corresponding to the first category label. β The score is the F value corresponding to the first category label. β The score is compared with the corresponding target value to determine whether the first category label is the target category.
[0077] Among them, F β Fractions can be calculated using formula (2):
[0078]
[0079] Where preciosn represents classification accuracy and recall represents classification recall.
[0080] As an example, F β The score can be, but is not limited to, any of the following: F1 score, F2 score, F 0.5 Fraction.
[0081] Optionally, if the first category label corresponds to F β If the score is less than the target value, then the first category label is determined to be the target category; otherwise, the first category label is determined not to be the target category.
[0082] Unlike the previous embodiment, which identified all category labels that were incorrectly identified as other categories as target categories, this embodiment only identifies category labels that meet the target conditions of classification accuracy and classification recall as target categories. This reduces the number of target categories, thereby reducing the amount of data processing in the process of obtaining the classification model and improving the efficiency of model acquisition.
[0083] After determining the target category, for the first target category (which is any target category among the determined target categories) and non-first target category A (which is any non-first target category among all non-first target categories), count the number of sample data belonging to the first target category that are incorrectly identified as non-first target category A. If the number of sample data belonging to the first target category that are incorrectly identified as non-first target category A is the largest, that is, the number of sample data incorrectly identified as non-first target category A is greater than the number of sample data incorrectly identified as any other non-first target category, then non-first target category A is determined as the paired category of the first target category.
[0084] In an optional embodiment, one way to update the parameters of the initial text classification model based on the category labels of each sample data in the sample dataset and the above-described description logic can be:
[0085] The parameters of the initial text classification model are updated with the goal of ensuring that the classification results of each sample data output by the initial text classification model are close to the category labels of the sample data input to the initial text classification model, and that the classification results of the sample data output by the initial text classification model that conform to the above description logic match the above description logic.
[0086] Taking the description logic shown in formula (1) as an example, for any sample data in the sample dataset, if any sample data contains the keyword w i If the category label of any sample data is the i-th category, then any sample data conforms to the description logic shown in formula (1).
[0087] In other words, when updating the parameters of the initial text classification model, this application considers the relationship between the classification results of sample data that conform to the above description logic and the description logic, while the relationship between the classification results of sample data that do not conform to the above description logic and the description logic can be ignored.
[0088] Optionally, the process of updating the parameters of the initial text classification model described above may include:
[0089] Obtain the first loss value between the classification result output by the initial text classification model and the category label of the sample data input to the initial text classification model.
[0090] The initial text classification model outputs a probability distribution of the sample data, which represents the probability that the sample data belongs to each category label.
[0091] As an example, the first loss value can be the cross-entropy loss value, but it can also be other loss values, such as the focal loss value.
[0092] The second loss value is obtained to determine the degree of matching between the classification result of the sample data output by the initial text classification model that conforms to the above description logic and the above description logic.
[0093] The sample data input to the initial text classification model may or may not contain sample data that conforms to the above description logic.
[0094] In the foregoing embodiments, the paired categories of different target categories may be the same. Therefore, when extracting description logic, multiple description logics may be extracted for the same category. Based on this, in an optional embodiment, for any description logic (for ease of description, denoted as description logic logic), and any sample data that conforms to description logic logic (for ease of description, denoted as sample data Y), logic This can be converted into a Sentential Decision Diagram (SDD) or Probabilistic Sentential Decision Diagram (PSDD) using the PyPSDD library, and then applied to the sample data Y. logic The classification results (i.e., sample data Y) logic The sample data Y is obtained by processing the probability distribution of each category and the SDD describing the logic. logic The probability distribution of the classification results in each category matches the degree of matching with the description logic.
[0095] As an example, the calculated sample data Y can be used... logic The logarithmic operation is performed between the classification results and the descriptive logic to obtain the corresponding sample data Y. logic And the second loss value describing the logic, that is, the second loss value is the logarithmic loss value of the degree of matching.
[0096] The target second loss value is obtained by weighted summing of the second loss values corresponding to the sample data that conform to the above description logic input to the initial text classification model.
[0097] Optionally, the weights of the second loss values corresponding to each sample data that conforms to the description logic can be pre-configured parameters, that is, the weights of the second loss values corresponding to each sample data that conforms to the description logic can be hyperparameters.
[0098] The parameters of the initial text classification model are updated with the goal of minimizing the total loss value obtained based on the first loss value and the target second loss value.
[0099] Optionally, the weights of the second loss value corresponding to each sample data that conforms to the description logic can be updated during the training of the initial text classification model. Based on this, the training process of the initial text classification model also includes:
[0100] With the goal of minimizing the total loss value obtained based on the first loss value and the target second loss value, the weights of the sample data corresponding to the second loss value that conform to the above-described logic are updated for the input initial text classification model.
[0101] Optionally, the total loss value obtained based on the first loss value and the target second loss value can be: the sum of the first loss value and the target second loss value. As an example, the total loss value can be calculated using formula (3):
[0102]
[0103] Where Loss represents the total loss value; Loss Data This represents the first loss value of the sample data input to the initial text classification model; The target second loss value is represented; N is the number of sample data points input to the initial text classification model; M is the number of descriptive logics; λ k Let λ be the weight corresponding to the k-th description logic, where λ is the weight corresponding to the j-th sample data if the j-th sample data conforms to the k-th description logic. k ≠0, if the j-th sample data does not conform to the k-th description logic, then for the j-th sample data, λ k =0; Match kj The degree of matching between the classification result of the j-th sample data and the k-th descriptive logic.
[0104] As an example, if the j-th sample data does not conform to the k-th description logic, the second loss value corresponding to the j-th sample data does not need to be calculated, that is, there is no need to calculate log(Match) kj ).
[0105] In this embodiment, different sample data conforming to the same description logic have the same weight. In another embodiment, different sample data conforming to the same description logic may have different weights.
[0106] like Figure 3 The diagram shown is a schematic representation of an architecture for obtaining the total loss value according to an embodiment of this application. This architecture consists of two layers: an upper layer is the Logic Discovery layer, and a lower layer is the Logic Injection layer, where the discovered descriptive logic is injected into the loss function used to train the classification model.
[0107] As an example, Figure 3 The diagram shows six category pairs: (c1, c2), (c1, c3), (c1, c4), (c2, c3), (c2, c4), and (c3, c4). The two categories in each pair are the target category and its paired category determined in step S102 above. When extracting descriptive logic from the sample data corresponding to the q-th category pair (q = 1, 2, 3, 4, 5, 6), at least one descriptive logic can be extracted for each category in the q-th category pair. Figure 3 For ease of explanation, only one description logic is displayed for each category, i.e. Figure 3 f in q This represents a descriptive logic corresponding to one category in the q-th category pair extracted from the sample data corresponding to the q-th category pair. Based on this, Figure 3 Only six description logics are shown. Then, each description logic is converted into a Sentence Decision Graph (SDD) (also called an SDD tree). When optimizing the parameters of the classification model, for any sample data and the q-th description logic, if the sample data matches the q-th description logic, the matching degree between the classification result of the sample data and the q-th description logic is calculated. Figure 3 The middle is reflected as v q =1, if any sample data does not conform to the q-th description logic, then the matching degree between the classification result of the sample data and any description logic is not calculated. Figure 3 The middle is reflected as v q =0. After calculating the matching degree, the second loss value corresponding to the matching degree, λ, can be calculated. qThis represents the weight corresponding to the q-th description logic. The second loss values of the sample data conforming to the description logic are weighted and summed to obtain the target second loss value. This target second loss value is then compared with the first loss value (Loss). Data Sum the results to get the total loss value.
[0108] This application also provides a classification method, which includes:
[0109] Input the text data into the text classification model obtained by the above method, and obtain the classification result of the text data output by the text classification model.
[0110] Corresponding to the method embodiments, this application also provides a model acquisition device. A schematic diagram of a model acquisition device provided in this application embodiment is shown below. Figure 4 As shown, it may include:
[0111] The system comprises a first training module 401, a testing module 402, an extraction module 403, and a second training module 404; wherein...
[0112] The first training module 401 is used to perform initial training of the text classification model using the sample dataset to obtain the initial text classification model.
[0113] The testing module 402 is used to test the initial text classification model using the sample dataset to determine the target category and its paired categories; wherein, the initial text classification model has lower classification performance for the target category than for non-target categories; and the number of sample data of the target category that are incorrectly identified as the paired category is greater than the number that are incorrectly identified as non-paired categories.
[0114] The extraction module 403 is used to extract the description logic corresponding to each target category and its paired category from the target sample data belonging to each target category and its paired category in the sample dataset; the description logic corresponding to each category represents the association between the knowledge contained in the sample data and the target category.
[0115] The second training module 404 is used to perform target training on the initial text classification model using the sample dataset to obtain the target text classification model; during the training process, the parameters of the initial text classification model are updated based on the category labels of each sample data in the sample dataset and the description logic.
[0116] The model acquisition apparatus provided in this application first performs initial training on a text classification model to obtain an initial text classification model. Based on the test results of the initial text classification model using a sample dataset, it determines the target category with low classification performance and the paired category that the target category is most likely to be misidentified. It extracts the description logic corresponding to the target category and the description logic corresponding to the paired category from the sample data corresponding to the target category and its paired category. Then, it performs target training on the initial text classification model. During the target training process, the update of the parameters of the initial text classification model considers not only the category label but also the description logic of the target category and its paired category. The description logic corresponding to any category represents the relationship between the knowledge contained in the sample data and any category, enabling the text classification model to learn more knowledge during training. Therefore, the method for obtaining the text classification model in this application can enable the text classification model to learn more distinguishing information between a few categories and other categories even when the sample dataset is an imbalanced dataset, thereby improving the classification performance of the text classification model.
[0117] In an optional embodiment, the model obtaining apparatus further includes a determining module for determining a target category, the determining module being configured to:
[0118] Statistical analysis is performed on the sample data belonging to the first category label in the sample dataset, as well as the sample data that was misclassified as the first category label by the initial text classification model, to determine the classification accuracy and classification recall corresponding to the first category label;
[0119] If the classification accuracy and classification recall corresponding to the first category label meet the target conditions, the first category label is determined to be the target category.
[0120] In an optional embodiment, the model obtaining apparatus further includes a determining module for determining a target category, the determining module being configured to:
[0121] If at least one sample data in the sample dataset belonging to the first category label is incorrectly classified as a non-first category label, the first category label is determined as the target category.
[0122] In an optional embodiment, when the second training module updates the parameters of the initial text classification model based on the category labels of each sample data in the sample dataset and the description logic, it is used to:
[0123] The parameters of the initial text classification model are updated with the goal of ensuring that the classification results of each sample data output by the initial text classification model are close to the category labels of the sample data input to the initial text classification model, and that the classification results of the sample data output by the initial text classification model that conform to the description logic match the description logic.
[0124] In an optional embodiment, when the second training module updates the parameters of the initial text classification model, it is used to:
[0125] Obtain the first loss value between the classification result output by the initial text classification model and the category label of the sample data input to the initial text classification model;
[0126] A second loss value is obtained to show the degree of matching between the classification result of the sample data that conforms to the description logic output by the initial text classification model and the description logic.
[0127] The target second loss value is obtained by weighted summing of the second loss values corresponding to the sample data that conform to the description logic input into the initial text classification model;
[0128] The parameters of the initial text classification model are updated with the goal of minimizing the total loss value obtained based on the first loss value and the target second loss value.
[0129] In an optional embodiment, the weights of the sample data that conform to the description logic input to the initial text classification model corresponding to the second loss value are pre-configured parameters.
[0130] In an optional embodiment, the second training module is further configured to:
[0131] With the goal of minimizing the total loss value obtained based on the first loss value and the target second loss value, the weights of the sample data corresponding to the second loss value that conform to the description logic input into the initial text classification model are updated.
[0132] Corresponding to the method embodiments, this application also provides a classification device, which is used to: input text data into a text classification model trained as described above, and obtain the classification result of the text data output by the text classification model.
[0133] Corresponding to the method embodiments, this application also provides an electronic device, a schematic diagram of which is shown below. Figure 5 As shown, it may include: at least one processor 1, at least one communication interface 2, at least one memory 3, and at least one communication bus 4.
[0134] In this embodiment, the number of processor 1, communication interface 2, memory 3, and communication bus 4 is at least one, and processor 1, communication interface 2, and memory 3 communicate with each other through communication bus 4.
[0135] Processor 1 may be a central processing unit (CPU), an application-specific integrated circuit (ASIC), or one or more integrated circuits configured to implement the embodiments of this application.
[0136] Memory 3 may include high-speed RAM, and may also include non-volatile memory, such as at least one disk storage device.
[0137] The memory 3 stores a program, and the processor 1 can call the program stored in the memory 3. The program is used for:
[0138] The initial text classification model is obtained by initially training the text classification model with the target number of times using the sample dataset;
[0139] The initial text classification model is tested using the sample dataset to determine the target category and its paired categories; wherein, the initial text classification model performs worse in classifying the target category than in classifying non-target categories; and the number of sample data of the target category that are incorrectly identified as paired categories is greater than the number that are incorrectly identified as non-paired categories.
[0140] From the target sample data belonging to any target category and its paired category in the sample dataset, extract the description logic corresponding to each target category and its paired category respectively; the description logic corresponding to any category represents the relationship between the knowledge contained in the sample data and the target category.
[0141] The initial text classification model is trained using the sample dataset to obtain the target text classification model. During the training process, the parameters of the initial text classification model are updated based on the category labels of each sample data in the sample dataset and the description logic.
[0142] Optionally, the refined and extended functions of the program can be found in the description above.
[0143] This application embodiment also provides a storage medium that can store a program suitable for execution by a processor, the program being used for:
[0144] The initial text classification model is obtained by initially training the text classification model with the target number of times using the sample dataset;
[0145] The initial text classification model is tested using the sample dataset to determine the target category and its paired categories; wherein, the initial text classification model performs worse in classifying the target category than in classifying non-target categories; and the number of sample data of the target category that are incorrectly identified as paired categories is greater than the number that are incorrectly identified as non-paired categories.
[0146] From the target sample data belonging to any target category and its paired category in the sample dataset, extract the description logic corresponding to each target category and its paired category respectively; the description logic corresponding to any category represents the relationship between the knowledge contained in the sample data and the target category.
[0147] The initial text classification model is trained using the sample dataset to obtain the target text classification model. During the training process, the parameters of the initial text classification model are updated based on the category labels of each sample data in the sample dataset and the description logic.
[0148] Optionally, the refined and extended functions of the program can be found in the description above.
[0149] Those skilled in the art will recognize that the units and algorithm steps of the various examples described in conjunction with the embodiments disclosed herein can be implemented in electronic hardware, or a combination of computer software and electronic hardware. Whether these functions are implemented in hardware or software depends on the specific application and design constraints of the technical solution. Those skilled in the art can use different methods to implement the described functions for each specific application, but such implementation should not be considered beyond the scope of this application.
[0150] In the several embodiments provided in this application, it should be understood that the disclosed systems, apparatuses, and methods can be implemented in other ways. Furthermore, the couplings or direct couplings or communication connections shown or discussed may be indirect couplings or communication connections through interfaces, devices, or units, and may be electrical, mechanical, or other forms.
[0151] The units described as separate components may or may not be physically separate. The components shown as units 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 units can be selected to achieve the purpose of this embodiment according to actual needs.
[0152] In addition, the functional units in the various embodiments of this application 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.
[0153] It should be understood that in the embodiments of this application, the claims, various embodiments, and features can be combined with each other to solve the aforementioned technical problems.
[0154] If the aforementioned functions are implemented as software functional units and sold or used as independent products, they can be stored in a computer-readable storage medium. Based on this understanding, the technical solution of this application, in essence, or the part that contributes to the prior art, or a portion of the technical solution, can be embodied in the form of a software product. This computer software product is stored in a storage medium and includes several instructions to cause a computer device (which may be a personal computer, server, or network device, etc.) to execute all or part of the steps of the methods described in the various embodiments of this application. The aforementioned storage medium includes various media capable of storing program code, such as USB flash drives, portable hard drives, read-only memory (ROM), random access memory (RAM), magnetic disks, or optical disks.
[0155] The above description of the disclosed embodiments enables those skilled in the art to make or use this application. Various modifications to these embodiments will be readily apparent to those skilled in the art, and the general principles defined herein may be implemented in other embodiments without departing from the spirit or scope of this application. Therefore, this application is not to be limited to the embodiments shown herein, but is to be accorded the widest scope consistent with the principles and novel features disclosed herein.
Claims
1. A method for obtaining a model, the method comprising: The initial text classification model is obtained by initially training the text classification model with the target number of times using the sample dataset; The sample data in the sample dataset is text data; The initial text classification model is tested using the sample dataset to determine the target category and its paired categories; wherein, the initial text classification model performs worse in classifying the target category than in classifying non-target categories; and the number of sample data of the target category that are incorrectly identified as paired categories is greater than the number that are incorrectly identified as non-paired categories. From the target sample data belonging to any target category and its paired category in the sample dataset, extract the description logic corresponding to each target category and its paired category; the description logic corresponding to each category represents the relationship between the knowledge contained in the sample data and the category. The initial text classification model is trained using the sample dataset to obtain the target text classification model. During the training process, the parameters of the initial text classification model are updated based on the category labels of each sample data in the sample dataset and the description logic.
2. The method according to claim 1, wherein, The process of determining the target category includes: Statistical analysis is performed on the sample data belonging to the first category label in the sample dataset, as well as the sample data that was misclassified as the first category label by the initial text classification model, to determine the classification accuracy and classification recall corresponding to the first category label; If the classification accuracy and classification recall corresponding to the first category label meet the target conditions, the first category label is determined to be the target category.
3. The method according to claim 1, wherein, The process of determining the target category includes: If at least one sample data in the sample dataset belonging to the first category label is incorrectly classified as a non-first category label, the first category label is determined as the target category.
4. The method according to claim 1, wherein updating the parameters of the initial text classification model based on the category labels of each sample data in the sample dataset and the description logic includes: The parameters of the initial text classification model are updated with the goal of ensuring that the classification results of each sample data output by the initial text classification model are close to the category labels of the sample data input to the initial text classification model, and that the classification results of the sample data output by the initial text classification model that conform to the description logic match the description logic.
5. The method according to claim 4, wherein updating the parameters of the initial text classification model includes: Obtain the first loss value between the classification result output by the initial text classification model and the category label of the sample data input to the initial text classification model; Obtain a second loss value showing the degree of matching between the classification result of the sample data that conforms to the description logic output by the initial text classification model and the description logic; The target second loss value is obtained by weighted summing of the second loss values corresponding to the sample data that conform to the description logic input into the initial text classification model; The parameters of the initial text classification model are updated with the goal of minimizing the total loss value obtained based on the first loss value and the target second loss value.
6. The method according to claim 5, wherein, The weights of the second loss value corresponding to the sample data that conforms to the description logic input to the initial text classification model are pre-configured parameters.
7. The method according to claim 5, wherein, Also includes: With the goal of minimizing the total loss value obtained based on the first loss value and the target second loss value, the weights of the sample data corresponding to the second loss value that conform to the description logic input into the initial text classification model are updated.
8. A classification method, the method comprising: Input text data into a text classification model to obtain the classification result corresponding to the text data output by the text classification model; The text classification model is obtained by the model acquisition method described in any one of claims 1-7.
9. A model-obtaining apparatus, the apparatus comprising: The first training module is used to perform initial training of the text classification model using the sample dataset to obtain the initial text classification model. The sample data in the sample dataset is text data; The testing module is used to test the initial text classification model using the sample dataset to determine the target category and its paired categories; wherein the initial text classification model's classification performance for the target category is lower than its classification performance for non-target categories; and the number of sample data of the target category that are incorrectly identified as the paired category is greater than the number that are incorrectly identified as non-paired categories. The extraction module is used to extract the description logic corresponding to each target category and its paired category from the target sample data belonging to any target category and its paired category in the sample dataset; the description logic corresponding to any category represents the relationship between the knowledge contained in the sample data and the any category. The second training module is used to perform target training on the initial text classification model using the sample dataset to obtain the target text classification model; during the training process, the parameters of the initial text classification model are updated based on the category labels of each sample data in the sample dataset and the description logic.
10. An electronic device, comprising: Memory, used to store programs; A processor for calling and executing the program in the memory, thereby implementing the various steps of the model acquisition method and / or classification method as described in any one of claims 1-8.
Citation Information
Patent Citations
Text classification method, text classifier and storage medium for unbalanced data set
CN108628971A
Category overlapping imbalance data classification method based on dynamic classifier selection
CN110516741A