Balanced sampling method for multi-level classification data set

By employing a balanced sampling method for multi-level classification datasets, including water level filling and layer-by-layer recursive processing, the problem of local and global imbalance in multi-level datasets is solved, thereby improving the model's generalization ability and recognition accuracy.

CN121388680APending Publication Date: 2026-01-23DARK MATTER ARTIFICIAL INTELLIGENT (BEIJING) TECHNOLOGY CO LTD
View PDF 0 Cites 0 Cited by

Patent Information

Application Number
CN202511443597.1
Authority / Receiving Office
CN · China
Patent Type
Applications(China)
Current Assignee / Owner
Filing Date
2025-10-10
Publication Date
2026-01-23

AI Technical Summary

Technical Problem

When processing multi-level, multi-dimensional datasets, existing technologies using single-layer sampling methods can lead to local and global imbalances, resulting in decreased model generalization ability and stability.

Method used

A balanced sampling method for multi-level classification datasets is adopted. Through water level filling allocation and layer-by-layer recursive processing, a dataset that takes into account both local and global balance is constructed, including top-level node allocation, layer-by-layer recursive allocation and consistency adjustment, forming a classification sampling data tree.

Benefits of technology

It effectively avoids the distribution drift problem caused by single-layer sampling, improves the model's generalization ability and recognition accuracy in long-tail categories and complex scenarios, and ensures the stability and consistency of the dataset.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN121388680A_ABST
    Figure CN121388680A_ABST
Patent Text Reader

Abstract

The invention relates to the technical field of model training, and discloses a balanced sampling method for a multi-level classification data set, which comprises the following steps of: acquiring original data, and confirming a hierarchical structure of the original data; performing water level filling distribution on a top node based on the original data; layer-by-layer recursion processing is carried out downwards based on the top layer nodes, data size distribution of each layer of nodes is realized, and a classified sampling data tree is obtained; according to the method, the problem of local balance-global imbalance distribution drift caused by single-layer sampling is effectively avoided, a high-quality balanced data set considering both local balance and global balance is successfully constructed, and the generalization ability and stability of the model in long-tail categories and complex scenes are remarkably improved.
Need to check novelty before this filing date? Find Prior Art

Description

TECHNICAL FIELD

[0001] The present application relates to the technical field of model training, and more particularly to a balanced sampling method for multi-level classification data sets. BACKGROUND

[0002] In many artificial intelligence application scenarios such as natural language processing, intelligent education evaluation, and medical diagnosis assistance, data often presents complex multi-level and multi-dimensional characteristics. For example, in the field of intelligent education, test question data not only covers primary dimensions such as subjects and grades, but also further subdivides into secondary dimensions such as question types and knowledge point modules. In some scenarios, it even extends to tertiary or deeper levels of classification, such as question difficulty levels and test ability types, forming a typical tree or network hierarchical structure. Such multi-level and multi-dimensional data generally have an uneven class distribution problem, i.e., a small number of classes have very few samples, while a large number of classes have a large number of samples. This uneven distribution can cause machine learning models to overfit to the head classes during training, severely reducing the recognition and prediction performance of long-tail classes, and greatly limiting the generalization ability and stability of the model in complex scenarios. Therefore, constructing a balanced data set through sampling technology is a key step to improve model performance. Currently, the main methods for handling unbalanced data in the industry include oversampling and undersampling. The SMOTE method is representative of oversampling, which balances the class distribution by synthesizing new minority class samples. Undersampling achieves balance by reducing the number of majority class samples. However, these traditional methods are designed based on single-level class structures and do not consider the internal relationships of multi-level data. When applied to tree or network hierarchical multi-level data, the limitations of traditional methods are particularly prominent: if sampling is only performed on a certain level, the class balance within that level can be achieved, but the class distribution ratio of the upper nodes will be disrupted. For example, in education test question data, if SMOTE oversampling is performed on the "question type" secondary dimension to increase the number of fill-in-the-blank question samples, it may result in the "mathematics" primary subject sample proportion far exceeding that of other subjects, causing serious imbalance in the upper class distribution. This "local balance-global imbalance" phenomenon caused by single-level sampling is essentially a distribution drift problem, which can cause the features learned by the model to deviate from the true data distribution, thereby reducing the generalization ability and stability of the model. Therefore, there is an urgent need for a balanced sampling method that can balance both locally and globally and adapt to multi-level and multi-dimensional data to construct high-quality balanced data sets, which is a problem that needs to be solved by those skilled in the art. SUMMARY

[0003] Therefore, the present application provides a balanced sampling method for multi-level classification data sets, which can construct high-quality balanced data sets that balance both locally and globally.

[0004] To achieve the above object, the present application adopts the following technical solutions: A balanced sampling method of multi-level classification data set, comprising the following steps: Obtaining original data and confirming the hierarchy of the original data; Based on the original data, water level filling distribution is performed on the top-level nodes; Based on the top-level nodes, recursive processing is performed layer by layer downward to realize data volume distribution of each layer node, and a classification sampling data tree is obtained.

[0005] Preferably, the step of water level filling distribution comprises: Obtaining the total amount of data to be distributed and the upper limit of the capacity of each top-level node; Through multiple rounds of traversal, data volume is distributed to each top-level node that has not reached the upper limit of the capacity, and the total amount of data to be distributed is updated; Until all data is distributed or all nodes reach the upper limit of the capacity.

[0006] Preferably, the step of recursive processing comprises: Taking the upper-level nodes as parent nodes, traversing each parent node to confirm a set of child nodes; According to each child node, confirming the parent node information corresponding to each child node; Traversing each child node to calculate a global distribution amount according to the parent node information corresponding to the current child node; Distributing the global distribution amount to the corresponding parent node and updating the distribution amount parameter; Until all child nodes are traversed.

[0007] Preferably, the step of distributing the global distribution amount to the corresponding parent node comprises: distributing according to the capacity proportion of the parent node.

[0008] Preferably, the step of distributing according to the capacity proportion of the parent node comprises: Initializing the global distribution amount that can be distributed; Calculating an accurate floating point distribution value in proportion, and obtaining an initial integer distribution by rounding down; Calculating the remainder, the total sum of the distributed amount, and the difference value to be distributed; Sorting the parent nodes in descending order according to the remainder, and distributing samples to the upper limit of the capacity of each parent node according to the difference value until the difference value is 0.

[0009] Preferably, the step of recursive processing further comprises: performing consistency adjustment after the distribution of the global distribution amount is completed.

[0010] Preferably, the step of consistency adjustment comprises: Compare the total capacity demand of the parent node with the total allocation of the child nodes; When the total capacity demand is not met, increase the allocation of the un-reached upper limit child node by upward adjustment; When the total capacity demand is exceeded, reduce the child node with allocation by downward adjustment; When the total capacity demand is consistent with the total allocation of the child nodes, output the final child node.

[0011] Preferably, the step further comprises verifying the classified sampling data tree, and confirming the error position and reason according to the verification result.

[0012] A model training method, characterized in that the training set is constructed by using the above-mentioned balanced sampling method.

[0013] According to the above technical solution, compared with the prior art, the present disclosure provides a balanced sampling method for a multi-level classification data set, which confirms the original data hierarchy first, then implements multi-round traversal distribution water level filling distribution on the top-level node, and then performs layer-by-layer recursive processing based on the parent node capacity proportion distribution and supplemented by consistency adjustment, and finally obtains the classification sampling data tree through verification and correction, which completely avoids the "local balance-global imbalance" distribution drift problem caused by single-layer sampling from the bottom logic, successfully constructs a high-quality balanced training set that takes into account the local balance and overall global balance of each level, and significantly improves the generalization ability, recognition accuracy and running stability of the model in long-tail categories and multi-dimensional complex scenarios. BRIEF DESCRIPTION OF DRAWINGS

[0014] In order to more clearly illustrate the technical solutions in the embodiments of the present application or the prior art, the drawings needed to be used in the embodiments or prior art description will be briefly introduced below. Obviously, the drawings in the following description are only embodiments of the present application, and those skilled in the art can obtain other drawings according to the provided drawings without creative labor.

[0015] Figure 1 A balanced sampling method for a multi-level classification data set provided by the present application.

[0016] Figure 2 A method for water level filling of the top-level node in the embodiment of the present application.

[0017] Figure 3 A method for recursive processing in the embodiment of the present application. DETAILED DESCRIPTION

[0018] With reference to the accompanying drawings, the technical solutions in the embodiments of the present application will be clearly and completely described below, obviously, the described embodiments are only a part of the embodiments of the present application, rather than all the embodiments. Based on the embodiments in the present application, all other embodiments obtained by those skilled in the art without creative work belong to the protection scope of the present application. Embodiment 1

[0019] As Figure 1 , Figure 2 and Figure 3 The embodiments of the present application disclose a method for balanced sampling of multi-level classification data set, comprising the following steps: S1: obtaining original data and confirming the hierarchy of the original data.

[0020] S2: performing water level filling distribution on the top layer node based on the original data.

[0021] S3: performing layer-by-layer recursive processing based on the top layer node to realize data volume distribution of each layer node, and obtaining classification sampling data tree.

[0022] In the embodiment, in order to prevent the data structure from being damaged in the processing process, the original structure can be copied before starting the distribution to generate an independent working copy, and the subsequent operation is performed based on the working copy.

[0023] In the embodiment, first, water level filling distribution is performed on the top layer node, that is, the top layer resource or data unit is supplemented or distributed according to the preset rule to ensure the balance in quantity and proportion. This step is the starting point of recursive processing, and only after the top layer is reasonably distributed, the processing can be passed down.

[0024] Then, the layer-by-layer recursive processing is performed, in the multi-level classification data result, recursive processing is performed on each layer, and global splitting is performed on all nodes of the layer to further refine the nodes into smaller sub-units; then, the next layer is called to enter the recursive process, and the process of “distribution-judgment-splitting” is repeated recursively until the lowest layer is processed.

[0025] In order to further implement the above technical solution, the step of water level filling distribution comprises: obtaining the total amount of data to be distributed and the upper limit of the capacity of each top layer node; through multiple rounds of traversal, the data volume is distributed to each top layer node that does not reach the upper limit of the capacity, and the total amount of data to be distributed is updated; until all data is distributed or all nodes reach the upper limit of the capacity.

[0026] In order to further implement the above technical solution, the step of recursive processing comprises: S31: taking the upper layer node as a parent node, traversing each parent node to confirm the child node set.

[0027] S32: Based on each child node, confirm the parent node information corresponding to each child node.

[0028] S33: Traverse each child node and calculate the global allocation based on the parent node information corresponding to the current child node.

[0029] S34: Allocate the global allocation to the corresponding parent node and update the allocation parameters.

[0030] S35: Continue until all child nodes have been traversed.

[0031] Furthermore, the global allocation is distributed to the corresponding parent nodes, specifically by allocating based on the capacity ratio of the parent nodes. The steps include: S341: Initialize the allocatable global allocation.

[0032] S342: Calculate the precise floating-point allocation value proportionally and obtain the initial integer allocation by rounding down.

[0033] S343: Calculate the remainders of the allocation to integers, the total of the allocated amounts, and the difference to be allocated.

[0034] S344: Sort parent nodes in descending order of remainder, and allocate samples to each parent node according to the difference until the difference is 0.

[0035] In another embodiment, after the global allocation is completed during recursive processing, consistency adjustment is performed. Specific steps include: Compare the total capacity requirement of the parent node with the total allocation of the child nodes.

[0036] S361: When the total capacity requirement is not met, the allocation of child nodes that have not reached the upper limit is increased by adjusting upwards.

[0037] S362: When the total capacity requirement is exceeded, the number of child nodes with allocated capacity is reduced by adjusting downwards; S363: When the total capacity requirement matches the total allocation of child nodes, output the final child nodes.

[0038] In another embodiment, after the recursive unrolling is complete, the method verifies the resulting mixture. If the verification passes, the result is returned directly as the final output of the method; if the verification fails, an error message is output, indicating the problematic node or the inconsistent allocation, for further correction. Regardless of whether the verification succeeds or fails, the process enters the termination phase, forming a closed loop.

[0039] This embodiment ensures stability and correctness under complex, multi-layered data structures through a three-pronged mechanism of "balanced allocation, recursive processing, and verification and correction." It not only dynamically adapts to different data scales but also ensures that the final output meets consistency and reliability requirements through a verification process.

[0040] For example, this invention can be applied to defect detection in an optical inspection system. A raw defect image set is acquired from optical sensors on the production line and organized according to a preset defect classification system. The required total sample size is determined based on the training task requirements, and a sample upper limit is set for each defect type. The system supplements samples for defect types that have not reached their upper limits through multiple rounds of allocation until the total sample size is allocated or all defect types have reached their capacity limits.

[0041] The sample size allocated at the top level is recursively distributed to lower-level defect morphology categories. The system uses the current defect type as the parent node and identifies its subordinate defect morphology subcategories. Based on the characteristic distribution ratio of each subcategory, the sample size to be allocated to each subcategory is calculated, and the allocation parameters are updated. This process continues recursively down to the lowest-level defect severity category. Example 2

[0042] Based on the same inventive concept, this invention discloses a model training method. During training, a training set is constructed using Example 1, and a classification model is trained using this training set.

[0043] In this embodiment, a deep learning network suitable for pixel-level localization and classification is used as the core architecture of the detection model. The prediction head of this architecture is initialized to correspond to the hierarchical structure of the aforementioned defect classification system, ensuring that the model can output prediction results that match the defect categories at each level.

[0044] Similarly, taking an optical detection system as an example, the model loss is calculated based on the model's forward propagation: Obtain the true label of the sample, which contains the complete hierarchical path encoding from the defect root category to the specific defect pattern. Use the cross-entropy loss function to compare the model's top-level classification output with the sample's root category ground truth. Traverse each non-leaf node on the hierarchical path of the sample, and calculate the cross-entropy loss between the model's output at the corresponding level classifier and the ground truth of the path node. Use the focus loss function to compare the classification output of the model's final layer (leaf node layer) with the sample's specific defect pattern ground truth. Sum the above three losses according to preset weights to obtain the total loss for this round of training.

[0045] Furthermore, after loading the balanced training data, the model is trained for a full cycle using the aforementioned total loss function until the validation set accuracy converges.

[0046] The various embodiments in this specification are described in a progressive manner, with each embodiment focusing on its differences from other embodiments. Similar or identical parts between embodiments can be referred to interchangeably. For the apparatus disclosed in the embodiments, since they correspond to the methods disclosed in the embodiments, the description is relatively simple; relevant parts can be referred to the method section.

[0047] The above description of the disclosed embodiments enables those skilled in the art to make or use the invention. 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 the invention. Therefore, the invention 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 balanced sampling method for multi-level classification datasets, characterized in that, Includes the following steps: Obtain the raw data and confirm the hierarchical structure of the raw data; Water level filling allocation is performed on the top-level node based on the original data; By recursively processing downwards from the top-level node, the data volume of each node is allocated, resulting in a classification sampling data tree.

2. The balanced sampling method for a multi-level classification dataset according to claim 1, characterized in that, The water level filling and distribution steps include: Get the total amount of data to be allocated and the capacity limit of each top-level node; Through multiple rounds of traversal, data is allocated to each top-level node that has not reached its capacity limit, while the total amount of data to be allocated is updated. Until all data is allocated or all nodes reach their capacity limit.

3. The balanced sampling method for a multi-level classification dataset according to claim 1, characterized in that, The steps of the recursive processing include: Using the top-level node as the parent node, traverse each parent node to determine the set of child nodes; Based on each child node, determine the parent node information corresponding to each child node; Iterate through each child node and calculate the global allocation based on the parent node information corresponding to the current child node; Allocate the global allocation to the corresponding parent node and update the allocation parameters; Continue until all child nodes have been traversed.

4. The balanced sampling method for a multi-level classification dataset according to claim 3, characterized in that, The process of allocating the global allocation to the corresponding parent node specifically involves allocating the allocation based on the capacity ratio of the parent node.

5. The balanced sampling method for a multi-level classification dataset according to claim 4, characterized in that, The allocation based on the capacity ratio of the parent node includes the following steps: Initialize the available global allocation; Calculate the precise floating-point allocation value proportionally, and obtain the initial integer allocation by rounding down. Calculate the remainder, the total already allocated, and the difference to be allocated; Sort parent nodes in descending order of remainder, and allocate samples to each parent node according to the difference until the difference is 0.

6. The balanced sampling method for a multi-level classification dataset according to claim 3, characterized in that, The recursive processing steps also include: performing consistency adjustment after the global allocation is completed.

7. The balanced sampling method for a multi-level classification dataset according to claim 6, characterized in that, The consistency adjustment steps include: Compare the total capacity requirement of the parent node with the total allocation of the child nodes; When the total capacity requirement is not met, the allocation of child nodes that have not reached the upper limit is increased by adjusting upwards; When the total capacity requirement is exceeded, the number of child nodes with allocated capacity is reduced by adjusting downwards. When the total capacity requirement matches the total allocation of child nodes, the final child nodes are output.

8. The balanced sampling method for a multi-level classification dataset according to claim 1, characterized in that, The steps also include: verifying the classification sampling data tree, and confirming the error location and cause based on the verification results.

9. A model training method, characterized in that, The training set is constructed using the sampling method described in any one of claims 1-8.