A text smoothing sampling method and device, electronic equipment and storage medium

By using the formula si=f((qi)0.5/((qi/(∑ni=1qi))1/x) and clustering or random sampling methods in text sampling, the problem of insufficient reasoning ability of semantic analysis models caused by differences in the number of texts is solved, and the consistency of text quantity distribution and model performance are improved.

CN118690022BActive Publication Date: 2025-12-05BEIJING RUIQI INFORMATION TECH CO LTD +3
View PDF 3 Cites 0 Cited by

Patent Information

Application Number
CN202410997376.8
Authority / Receiving Office
CN · China
Patent Type
Patents(China)
Current Assignee / Owner
Filing Date
2024-07-24
Publication Date
2025-12-05
Estimated Expiration
2044-07-24

AI Technical Summary

Technical Problem

When sampling text sets with different labels, existing technologies suffer from several problems: the semantic analysis model has poor reasoning ability for labels with fewer texts due to large differences in the number of texts, and the distribution of the number of sampled texts is inconsistent with the distribution of the number of texts to be sampled.

Method used

The number of samples is obtained by using the formula si=f((qi)0.5/((qi/(∑ni=1qi))1/x), and clustering or random sampling is performed based on the number of texts and similarity to ensure the diversity and distribution consistency of the sampled texts and improve the reasoning ability of the semantic analysis model.

Benefits of technology

It improves the semantic analysis model's reasoning ability for labels with a small number of texts and enhances the consistency between the distribution of the number of sampled texts and the distribution of the number of texts to be sampled, thereby improving the training effect of the model.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN118690022B_ABST
    Figure CN118690022B_ABST
Patent Text Reader

Abstract

The present application relates to the technical field of electric digital data processing, in particular to a text smoothing sampling method and device, electronic equipment and storage medium. The method comprises: S100, obtaining a to-be-sampled text set A, A comprises a plurality of to-be-sampled texts, the labels of to-be-sampled texts of the same category are the same, and the labels of to-be-sampled texts of different categories are different; S200, obtaining the sampling number s of the i-th category i ; S300, if q i ≥ s i , obtaining s i to-be-sampled texts from the i-th to-be-sampled text a i to form the target sampling text of the i-th category; otherwise, determining a i as the target sampling text of the i-th category. The present application can improve the consistency between the number distribution of texts corresponding to different labels in the sampled texts and the number distribution of texts corresponding to different labels in the to-be-sampled texts, and improve the inference ability of the semantic analysis model trained based on the sampled texts for those labels with less corresponding text quantity.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] This invention relates to the field of electronic digital data processing technology, and in particular to a method, apparatus, electronic device, and storage medium for smooth text sampling. Background Technology

[0002] When sampling a text set containing different labels for training a semantic analysis model, the following problems may occur: (1) The number of texts corresponding to different labels varies greatly. If the text set is randomly sampled or sampled proportionally according to the number of texts corresponding to different labels, the proportion of texts corresponding to labels with fewer texts in the sampled texts is small, resulting in poor reasoning ability of the trained semantic analysis model for labels with fewer texts. For example, Chinese patent application with publication number CN116796205A discloses a data augmentation method, device, equipment and medium for medical texts. This patent application clusters existing medical texts and determines the weight of each medical text based on the clustering results. Specifically, it assigns higher weights to medical texts with stronger representativeness. When sampling existing medical texts, medical texts with higher corresponding weights are used as sampled texts. This sampling method results in more medical texts being sampled from clusters containing a large number of medical texts, making the data augmentation ability of the trained semantic analysis model for labels with fewer texts in the sampled texts smaller. (1) Medical texts in clusters with fewer medical texts are sampled less, resulting in a smaller proportion of medical texts in the final sampled texts; (2) The number of texts corresponding to different labels varies greatly. If a quantity threshold is set directly based on experience, when the number of texts corresponding to a certain label is greater than the quantity threshold, a small proportion of texts are sampled from the texts corresponding to that label; when the number of texts corresponding to a certain label is less than the quantity threshold, a large proportion of texts are sampled from the texts corresponding to that label. This sampling method is relatively crude, resulting in a large difference between the quantity distribution of texts corresponding to different labels in the sampled texts and the quantity distribution of texts corresponding to different labels in the text to be sampled. How to improve the consistency between the quantity distribution of texts corresponding to different labels in the sampled texts and the quantity distribution of texts corresponding to different labels in the text to be sampled, and how to improve the reasoning ability of the semantic analysis model trained based on the sampled texts for those labels with fewer corresponding texts, are problems that need to be solved urgently. Summary of the Invention

[0003] The purpose of this invention is to provide a text smoothing sampling method, apparatus, electronic device, and storage medium to improve the consistency between the quantity distribution of texts corresponding to different tags in the sampled text and the quantity distribution of texts corresponding to different tags in the text to be sampled, and to improve the reasoning ability of the semantic analysis model trained based on the sampled text for tags with a small number of corresponding texts.

[0004] According to a first aspect of the present invention, a method for smoothing text sampling includes the following steps:

[0005] S100, obtain the text set A to be sampled. A includes several classes of text to be sampled. Texts of the same class have the same label, and texts of different classes have different labels.

[0006] S200, obtain the number of samples s for the i-th class. i s i =f((q i ) 0.5 / ((q i / (∑ n i=1 q i )) 1 / x ), x is the preset first value, x is a positive integer, f() is the floor function; i ranges from 1 to n, n is the number of categories of the text to be sampled; q i denoted as the number of sampled texts included in the i-th type of sampled text.

[0007] S300, if q i ≥s i Then, from the i-th type of text to be sampled, a i Get s from i The sampled texts of class i are constituted by the sampled texts of class i; otherwise, the sampled texts of class i a are used to form the target sampled texts. i The target sampled text is identified as the i-th class.

[0008] According to a second aspect of the present invention, a text smoothing sampling device comprises:

[0009] The first acquisition module is used to acquire the text set A to be sampled. A includes several classes of text to be sampled. Text to be sampled in the same class has the same label, while text to be sampled in different classes has different labels.

[0010] The first traversal module is used to obtain the number of samples s for the i-th class. i s i =f((q i ) 0.5 / ((q i / (∑ n i=1 q i )) 1 / x ), x is the preset first value, x is a positive integer, f() is the floor function; i ranges from 1 to n, n is the number of categories of the text to be sampled; q i denoted as the number of sampled texts included in the i-th type of sampled text.

[0011] The first judgment module is used to determine if q i ≥si Then, from the i-th type of text to be sampled, a i Get s from i The sampled texts of class i are constituted by the sampled texts of class i; otherwise, the sampled texts of class i a are used to form the target sampled texts. i The target sampled text is identified as the i-th class.

[0012] According to a third aspect of the present invention, an electronic device includes a memory, a processor, and a computer program stored in the memory and executable on the processor, wherein the processor, when executing the computer program, implements the above-described text smoothing sampling method.

[0013] According to a fourth aspect of the present invention, a computer-readable storage medium stores a computer program that, when executed by a processor, implements the above-described text smoothing sampling method.

[0014] The present invention has at least the following beneficial effects:

[0015] In this invention, the text to be sampled, A, includes n categories of text to be sampled. Texts of the same category have the same label, while texts of different categories have different labels. When sampling A, this invention uses formula s... i =f((q i ) 0.5 / ((q i / (∑ n i=1 q i )) 1 / x Get the number of samples s of the i-th type of text to be sampled in A. i With q i ,∑ n i=1 q i Related to x, if the number of texts included in the i-th class of texts to be sampled is greater than or equal to s i Then, s is obtained from the i-th type of text to be sampled. i The target sampled texts of class i are composed of _s_ to be sampled; if the number of texts included in class i is less than s_i... i Then, the entire text to be sampled in the i-th category is determined as the target sampled text in the i-th category. Compared with methods that directly perform random sampling or proportional sampling on A, based on the formula s of this invention... i =f((q i ) 0.5 / ((q i / (∑ n i=1 q i )) 1 / xThis method can extract as much text as possible from class A, including classes with fewer texts. When these sampled texts are used as training text for the semantic analysis model, it can improve the trained model's inference ability regarding labels corresponding to classes with fewer texts. Furthermore, based on the formula s of this invention... i =f((q i ) 0.5 / ((q i / (∑ n i=1 q i )) 1 / x This can also achieve the goal of sampling more classes with a larger number of texts compared to classes with a smaller number of texts, thereby improving the consistency between the distribution of the number of texts corresponding to different labels in the sampled text and the distribution of the number of texts corresponding to different labels in the text to be sampled. Attached Figure Description

[0016] To more clearly illustrate the technical solutions in the embodiments of the present invention, the accompanying drawings used in the description of the embodiments will be briefly introduced below. Obviously, the accompanying drawings described below are only some embodiments of the present invention. For those skilled in the art, other drawings can be obtained based on these drawings without creative effort.

[0017] Figure 1 This is a flowchart of a text smoothing sampling method provided in Embodiment 1 of the present invention. Detailed Implementation

[0018] The technical solutions of the embodiments of the present invention will be clearly and completely described below with reference to the accompanying drawings. Obviously, the described embodiments are only some embodiments of the present invention, and not all embodiments. Based on the embodiments of the present invention, all other embodiments obtained by those skilled in the art without creative effort are within the scope of protection of the present invention.

[0019] Example 1:

[0020] According to this embodiment, a text smoothing sampling method is provided, such as... Figure 1 As shown, it includes:

[0021] S100, obtain the text set A to be sampled. A includes several classes of text to be sampled. Texts of the same class have the same label, and texts of different classes have different labels.

[0022] In this embodiment, A = {a1, a2, ..., a} i ,…,a n}, a iLet be the i-th type of text to be sampled, where i ranges from 1 to n, and n is the number of types of text to be sampled; a i The number of texts to be sampled is q. i a i Including q i The labels of the texts to be sampled are the same, but different. i The labels of the texts to be sampled are different.

[0023] S200, obtain the number of samples s for the i-th class. i s i =f((q i ) 0.5 / ((q i / (∑ n i=1 q i )) 1 / x ), x is the preset first value, x is a positive integer, f() is the floor function; i ranges from 1 to n, n is the number of categories of the text to be sampled; q i denoted as the number of sampled texts included in the i-th type of sampled text.

[0024] Optionally, x can be an empirical value, for example, x=3.

[0025] Optionally, f() is a floor function or a rounding function.

[0026] Preferably, x=f( l g((max(Q)) 0.5 )) or x=f( l g((∑ n i=1 q i ) 0.5 Q is the sequence of sample counts for A, consisting of the number of sampled texts included in each class of sampled texts, Q=(q1,q2,…,q i ,…,q n `max()` is the function to find the maximum value. l g is the logarithm to the base 10. Small-scale experiments show that when x = f( l g((max(Q)) 0.5 )) or x=f( l g((∑ n i=1 q i ) 0.5 When sampling, the distribution of the number of texts corresponding to different labels in the sampled text is basically consistent with the distribution of the number of texts corresponding to different labels in A.

[0027] S300, if q i ≥si Then, from the i-th type of text to be sampled, a i Get s from i The sampled texts of class i are constituted by the sampled texts of class i; otherwise, the sampled texts of class i a are used to form the target sampled texts. i The target sampled text is identified as the i-th class.

[0028] Optional, randomly select from a i Get s from i The texts to be sampled constitute the target sampled text of the i-th class.

[0029] Preferably, if q i ≥s i Then from a i Get s from i The target sampled texts of the i-th class consist of the following:

[0030] S310, according to a i The text similarity between the texts to be sampled includes a. i Perform clustering to obtain clustering result G. i G i Includes m clusters, where m is the number of pairs of a. i The number of clusters obtained by clustering.

[0031] In this embodiment, G i =(g i,1 ,g i,2 ,…,g i,j ,…,g i,m ), g i,j For a i The j-th cluster obtained by clustering, where the value of j ranges from 1 to m.

[0032] Those skilled in the art will understand that any method for obtaining text similarity in the prior art falls within the protection scope of this invention.

[0033] Those skilled in the art will understand that any clustering method in the prior art falls within the protection scope of this invention. Optionally, a density-based clustering method (such as DBSCAN) can be used to cluster a. i Perform clustering, where a i Each text to be sampled is treated as a point, and the distance between two texts to be sampled is used to determine the value of a. i Clustering shows that the distance between two texts to be sampled is negatively correlated with the text similarity between them. Therefore, a i Text samples with high similarity to Chinese texts are clustered into one cluster, a i Text samples with low similarity to Chinese texts were clustered into different clusters.

[0034] S320, obtain G i The number of texts to be sampled included in the smallest cluster. i,min .

[0035] In this embodiment, G i The smallest cluster in the middle is G i It includes the cluster with the fewest texts.

[0036] S330, if s i,min ≥f(s i If / m), then enter S340.

[0037] S340, Traverse G i From each g i,j f(s) i / m) texts to be sampled constitute the initial sampled text of the i-th class; g i,j For a i The j-th cluster obtained by clustering, where the value of j ranges from 1 to m.

[0038] Optional, randomly select from each g i,j f(s) i / m) texts to be sampled constitute the initial sampled text of the i-th class.

[0039] S350, if m×f(s) i / m)=s i If so, the initial sampled text of class i is determined as the target sampled text of class i.

[0040] Based on S310-S350, this embodiment uses G i The number of texts to be sampled included in the smallest cluster. i,min Greater than or equal to f(s) i In the case of / m), from each g i,j f(s) i / m) texts to be sampled constitute the initial sampled text of the i-th class. If m×f(s i / m)=s i Then it reached the point from a i The purpose of uniformly sampling text in m clusters is due to a i The m clusters represent a i The example contains m types of text, therefore this embodiment implements the processing of text a. i The diverse sampling improves the subsequent training of the semantic analysis model for a. i The reasoning ability corresponding to the tags.

[0041] Preferably, S350 further includes: if m×f(s i / m)>s iThen, randomly delete m×f(s) from the initial sampled text of the i-th class. i / m)-s i Given _ ... i / m)-s i The text belongs to a i m×f(s) i / m)-s i Clusters; if m×f(s) i / m) i Then from a i Randomly select s from the remaining text i -m×f(s i / m) sampled texts are added to the initial sampled text of the i-th class, and the initial sampled text of the i-th class after the addition is determined as the target sampled text of the i-th class; a i The remaining text is a i The text excluding the initial sampled text of class i.

[0042] This embodiment is in G i The number of texts to be sampled included in the smallest cluster. i,min Greater than or equal to f(s) i In the case of / m), from each g i,j f(s) i / m) texts to be sampled constitute the initial sampled text of the i-th class. If m×f(s i / m)≠s i Then, based on the initial sampled text of class i, a small adjustment is made to minimize the impact of sampling from class a. i The difference in the number of text samples in different clusters, due to a i The m clusters represent a i The example contains m types of text, therefore this embodiment implements the processing of text a. i The diverse sampling improves the subsequent training of the semantic analysis model for a. i The reasoning ability corresponding to the tags.

[0043] Preferably, S330 further includes: if s i,min <f(s i If / m), then enter S331.

[0044] S331, Traverse G i From each g i,j Get s from i,min The texts to be sampled constitute the first sampled text of the i-th class.

[0045] Optional, randomly select from each g i,j Get s from​i,min The texts to be sampled constitute the first sampled text of the i-th class.

[0046] S332, obtain the first remaining sampling number Δε1, Δε1=s i -m×s i,min .

[0047] S333, Obtain the clustering result G after the first sampling. 1 i G 1 i =(g 1 i,1 ,g 1 i,2 ,…,g 1 i,j ,…,g 1 i,m ), g 1 i,j To from g i,j Get s from i,min A cluster consisting of the remaining text after the first sampled text.

[0048] In this embodiment, if g i,j The number of texts included is greater than s i,min Then g 1 i,j A non-empty cluster; if g i,j The number of texts included is equal to s i,min Then g 1 i,j An empty cluster.

[0049] S334, Get G 1 i The number of non-empty clusters, δ.

[0050] S335, if Δε1=δ, then from G 1 i One sampled text is obtained from each non-empty cluster and appended to the first sampled text of the i-th class. The appended first sampled text of the i-th class is then determined as the target sampled text of the i-th class.

[0051] Based on S331-S335, this embodiment uses G i The number of texts to be sampled included in the smallest cluster. i,min Less than f(s) i In the case of / m), first start from each g i,j Get s from i,minThe first sampled text of class i is composed of several texts to be sampled. Then, the first remaining sample quantity Δε1 and the number of non-empty clusters δ are obtained. If δ = Δε1, then one text to be sampled is obtained from each non-empty cluster and appended to the first sampled text of class i. Thus, this embodiment minimizes the number of samples from class i. i The difference in the number of text samples in different clusters, due to a i The m clusters represent a i The example contains m types of text, therefore this embodiment implements the processing of text a. i The diverse sampling improves the subsequent training of the semantic analysis model for a. i The reasoning ability corresponding to the tags.

[0052] Preferably, S335 further includes: if Δε1 < δ, then from G 1 i One sampled text is obtained from each target cluster and appended to the first sampled text of the i-th class, and the appended first sampled text of the i-th class is determined as the target sampled text of the i-th class; the target cluster is from G 1 i Δε1 non-empty clusters are randomly selected from δ non-empty clusters.

[0053] This embodiment is in G i The number of texts to be sampled included in the smallest cluster. i,min Less than f(s) i In the case of / m), first start from each g i,j Get s from i,min The first sampled text of class i is composed of several unsampled texts. Then, the first remaining sample count Δε1 and the number of non-empty clusters δ are obtained. If Δε1 < δ, the first sampled text of class i is slightly adjusted to minimize the impact of sampling from class a. i The difference in the number of text samples in different clusters, due to a i The m clusters represent a i The example contains m types of text, therefore this embodiment implements the processing of text a. i The diverse sampling improves the subsequent training of the semantic analysis model for a. i The reasoning ability corresponding to the tags.

[0054] Preferably, S335 further includes: if Δε1>δ, then proceed to S336.

[0055] S336, Get G 1 i The smallest non-empty cluster contains the number of texts to be sampled, s. 1 i,min .

[0056] S337, if s1 i,min If it is ≥ f(Δε1 / δ), then proceed to S338.

[0057] S338, obtain f(Δε1 / δ) text samples to be sampled from each non-empty cluster in G and append them to the first sampled text of the i-th class. 1 i

[0058] S339, if f(Δε1 / δ)×δ = Δε1, then determine the appended first sampled text of the i-th class as the target sampled text of the i-th class.

[0059] Based on S336 - S339, in this embodiment, when the number s of text samples to be sampled included in the smallest cluster in G i is less than f(s i,min i / m), first obtain s i,j text samples to be sampled from each g i,min to form the first sampled text of the i-th class, then obtain the first remaining sampling quantity Δε1 and the number δ of non-empty clusters. If δ < Δε1, then obtain the number s 1 i of text samples to be sampled included in the smallest non-empty cluster in G 1 i,min 1 i,min , if s i i ≥ f(Δε1 / δ), then obtain f(Δε1 / δ) text samples to be sampled from each non-empty cluster and append them to the first sampled text of the i-th class. If f(Δε1 / δ)×δ = Δε1, then determine the appended first sampled text of the i-th class as the target sampled text of the i-th class; thereby, this embodiment minimizes the difference in the number of text samples sampled from different clusters of a i . Since the m clusters of a i represent m types of texts in a i , this embodiment realizes diversified sampling of a 1 and improves the inference ability of the subsequent trained semantic analysis model for the labels corresponding to a i,min .

[0060] In this embodiment, S339 further includes: if f(Δε1 / δ)×δ ≠ Δε1, then obtain the target sampled text of the i-th class according to a method similar to S350, which will not be elaborated here.

[0061] In this embodiment, S337 further includes: if s i i < f(Δε1 / δ), then obtain the target sampled text of the i-th class according to a method similar to S331 - S335, which will not be elaborated here.

[0062] In this embodiment, the text A to be sampled includes n types of texts to be sampled. Texts of the same type have the same label, and texts of different types have different labels. In this embodiment, when sampling A, according to formula s i =f((q i ) 0.5 / ((q i / (∑ n i= 1q i )) 1 / x Get the number of samples s of the i-th type of text to be sampled in A. i With q i ,∑ n i=1 q i Related to x, if the number of texts included in the i-th class of texts to be sampled is greater than or equal to s i Then, s is obtained from the i-th type of text to be sampled. i The target sampled texts of class i are composed of _s_ to be sampled; if the number of texts included in class i is less than s_i... i Then, the entire text to be sampled in the i-th category is determined as the target sampled text in the i-th category. Compared to methods that directly perform random sampling or proportional sampling on A, the formula s in this embodiment... i =f((q i ) 0.5 / ((q i / (∑ n i=1 q i )) 1 / x This method can extract as much text as possible from class A, including classes with fewer texts. When these sampled texts are used as training text for the semantic analysis model, it can improve the trained model's ability to infer labels corresponding to classes with fewer texts. Furthermore, based on formula s in this embodiment... i =f((q i ) 0.5 / ((q i / (∑ n i=1 q i )) 1 / x This can also achieve the goal of sampling more classes with a larger number of texts compared to classes with a smaller number of texts, thereby improving the consistency between the distribution of the number of texts corresponding to different labels in the sampled text and the distribution of the number of texts corresponding to different labels in the text to be sampled.

[0063] Example 2:

[0064] The above embodiment one in q i ≥s iIn the case of, adopt the method of clustering a i to obtain s i from a i target sampling texts of the i-th class to achieve diversified sampling of a i and improve the inference ability of the subsequent trained semantic analysis model for the i corresponding labels; however, for q i ≥s i and the case where q i has a small difference from s i , according to the method of clustering a i to obtain s i from a i target sampling texts of the i-th class has an insignificant effect, and will also increase the duration of obtaining the target sampling texts of the i-th class and reduce the efficiency of obtaining the target sampling texts of the i-th class; to solve this problem, in this embodiment, the smooth sampling method of the text is further optimized on the basis of the above Embodiment 1.

[0065] Specifically, before S310, the step of obtaining s i from a i target sampling texts of the i-th class further includes:

[0066] S303, obtaining the sampling ratio r i of the i-th class, r i =s i / q i .

[0067] S304, if r i <r0, then enter S310; r0 is a preset sampling ratio threshold; otherwise, randomly obtain s i from a i target sampling texts of the i-th class.

[0068] In this embodiment, r0 is an empirical value. Optionally, r0 is 5% or 10%.

[0069] Based on the above S303-S304, when r i <r0, that is, in the case of obtaining a relatively small proportion of target sampling texts from a i , only then obtain s i from a i by clustering a i target sampling texts of the i-th class. Compared with randomly obtaining s i from a i target sampling texts of the i-th class, according to clustering a iClustering can significantly improve the efficiency of obtaining target sampled text from class a. i The diversity of the sampled text significantly improves the subsequent training of the semantic analysis model for a. i The reasoning ability corresponding to the labels; and for r i ≥r0, that is, from a i When obtaining a large proportion of the text to be sampled, directly from a i Randomly obtain s i The sampled texts constitute the target sampled text of the i-th class, and the subsequent trained semantic analysis model is used to analyze a. i The reasoning ability of the corresponding tags is not greatly affected, but it helps to reduce the time to obtain the target sample text of the i-th class and improve the efficiency of obtaining the target sample text of the i-th class.

[0070] Example 3:

[0071] The above embodiment one in q i ≥s i In the case of a, adopt the method of a i Clustering methods from a i Get s from i The texts to be sampled constitute the target sampled text of the i-th class, so as to achieve the sampling of a i Diverse sampling improves the ability of the subsequently trained semantic analysis model to analyze a. i The reasoning ability corresponding to the labels; but for q i ≥s i And q i In cases where the repetition rate of Chinese texts is low, according to a i Clustering methods from a i Get s from i The effect of the sampled texts forming the target sampled text of the i-th class is not obvious, and it will increase the time to obtain the target sampled text of the i-th class and reduce the efficiency of obtaining the target sampled text of the i-th class. In order to solve this problem, this embodiment optimizes the text smoothing sampling method based on the above embodiment one.

[0072] Specifically, prior to S310, the preceding text refers to a. i Get s from i The target sampled texts constituting the i-th class of texts to be sampled also include:

[0073] S305, from a i Randomly obtain s i The texts to be sampled constitute the discriminant sampled text B for the i-th class. i .

[0074] S306, for B i Grouping is performed to obtain the grouping result R.i R i ={R i,1 ,R i,2 ,…,R i,t ,…,R i,v}, R i,t For B i The t-th group is obtained by grouping, where t ranges from 1 to v, and v is the preset number of groups.

[0075] Optional, for B i The included text is randomly grouped, so that each R i,t The number of texts included is greater than or equal to floor(s) i / v) and less than or equal to ceil(s) i ` / v`, `floor()` rounds down, and `ceil()` rounds up.

[0076] S307, according to R i The text similarity between the included groups is obtained by B. i The repetition between Chinese texts (sim) i .

[0077] Optionally, S307 includes:

[0078] S3071, Obtain the concatenated text CR i CR i ={CR i,1 ,CR i,2 ,…,CR i,t ,…,CR i,v}, CR i,t To make R i,t The text obtained by splicing together the included text.

[0079] Preferably, R i,t The text is concatenated from beginning to end to obtain CR. i,t .

[0080] S3072, Obtain CR i The text similarity between any two texts is calculated and appended to a predefined similarity set SH, resulting in SH={sh1,sh2,…,sh…} d ,…,sh D}, sh d For CR i The text similarity between the d-th pairs of texts, where d ranges from 1 to D, and D is the CR (text similarity score). i The corresponding number of text pairs, D = v × (v-1) / 2; SH is initialized as an empty set.

[0081] In this embodiment, from CR iChoose any two texts to form a text pair, CR i The number of texts included is v, therefore CR i The number of corresponding text pairs is v×(v-1) / 2.

[0082] Those skilled in the art will understand that any method for obtaining text similarity in the prior art falls within the protection scope of this invention.

[0083] S3073, obtain SIM i , sim i =sum(SH) / D, where sum() is for summation.

[0084] Based on S3071-S3073, this embodiment can obtain B. i The repetition between Chinese texts (sim) i , sim i The larger the value, the more likely B is to be active. i The higher the degree of repetition between Chinese texts.

[0085] S308, if sim i If ≤sim0, then B i The target sampled text is identified as the i-th class; sim0 is the preset similarity threshold; otherwise, proceed to S310.

[0086] In this embodiment, sim0 is an empirical value, and optionally, sim0=0.5.

[0087] Based on the above S305-S308, in sim i >sim0, that is, from a i Randomly obtain s i The discriminant sampled text B, consisting of the i-th class of texts to be sampled, i Only when the repetition rate of Chinese text is high will it be considered according to the case of a. i Clustering methods from a i Get s from i The sampled texts constitute the target sampled text of the i-th class, compared to the texts from class a. i Randomly obtain s i The texts to be sampled constitute the target sampled text of the i-th class, and are arranged according to a i Clustering can significantly improve the efficiency of obtaining target sampled text from class a. i The diversity of the sampled text significantly improves the subsequent training of the semantic analysis model for a. i The reasoning ability corresponding to the labels; while for sim i ≤sim0, that is, from a i Randomly obtain s i The discriminant sampled text B, consisting of the i-th class of texts to be sampled,i When the repetition degree of the Chinese text is relatively low, directly taking B i as the target sampling text of the i-th category is beneficial to reducing the time for obtaining the target sampling text of the i-th category and improving the efficiency of obtaining the target sampling text of the i-th category.

[0088] Preferably, before S305, obtaining s from a i and using the s i sampling texts to form the target sampling text of the i-th category further includes:

[0089] S301, obtaining the sum w of the number of sampling texts included in the top u categories with the largest number of sampling texts in A, where u is a preset category quantity threshold.

[0090] Optionally, u is an empirical value or u = f(r'×n), where r' is a preset label ratio threshold, and optionally, r' is 5%.

[0091] S302, if w / (∑ n i=1 q i )≥η, then proceed to S303; η is a preset ratio threshold; otherwise, proceed to S305.

[0092] Optionally, η is an empirical value, and optionally, η is 50%.

[0093] S303, obtaining the sampling ratio r of the i-th category i , r i = s i / q i .

[0094] S304, if r i <r0, then proceed to S310; r0 is a preset sampling ratio threshold; otherwise, randomly obtain s i sampling texts from a i to form the target sampling text of the i-th category.

[0095] In this embodiment, r0 is an empirical value, and optionally, r0 is 5% or 10%.

[0096] Based on S301 - S304, when w / (∑ n i=1 q iIf ≥ η, meaning the number of texts corresponding to different tags in A varies significantly, indicating an imbalance in the number of texts corresponding to different tags, then steps S303-S304 are executed. Based on a preset sampling ratio threshold, the n classes of texts to be sampled in A are divided into two classes: the first class has a sampling ratio less than the preset threshold (corresponding to classes with a large number of texts in A), and the second class has a sampling ratio greater than or equal to the preset threshold (corresponding to classes with a small number of texts in A). This method of determining whether to perform clustering based on the sampling ratio is highly efficient. Moreover, for classes with a sampling ratio greater than or equal to the preset threshold, since the sampling ratio is relatively large, even if random sampling is performed directly on this class, it will not significantly affect the inference performance of the semantic analysis model for the corresponding tags in the later trained model. And w / (∑ n i=1 q i If ) < η, meaning the difference in the number of texts corresponding to different tags in A is small, i.e., the number of texts corresponding to different tags is relatively balanced, then the difference in the sampling ratio of each category is relatively small. Executing S305-S308 does not require obtaining a preset sampling ratio threshold; instead, it applies to B. i The repetition rate is judged. If the repetition rate is high, cluster sampling is performed on the class to improve the reasoning effect of the semantic analysis model trained later on the corresponding tags of the class. The method of determining whether to perform cluster sampling based on repetition rate in this embodiment can improve the reasoning effect of the semantic analysis model trained later on the corresponding tags of each class.

[0097] Example 4:

[0098] This embodiment provides a text smoothing sampling device, including:

[0099] The first acquisition module is used to acquire the text set A to be sampled. A includes several classes of text to be sampled. Text to be sampled in the same class has the same label, while text to be sampled in different classes has different labels.

[0100] The first traversal module is used to obtain the number of samples s for the i-th class. i s i =f((q i ) 0.5 / ((q i / (∑ n i=1 q i )) 1 / x ), x is the preset first value, x is a positive integer, f() is the floor function; i ranges from 1 to n, n is the number of categories of the text to be sampled; q i denoted as the number of sampled texts included in the i-th type of sampled text.

[0101] Optionally, x can be an empirical value. Preferably, x = f( l g((max(Q)) 0.5 )) or x=f( l g((∑ n i=1 q i ) 0.5 Q is the sequence of sample numbers of A, Q=(q1,q2,…,q i ,…,q n `max()` is the function to find the maximum value. l g is the logarithm to the base 10. Small-scale experiments show that when x = f( l g((max(Q)) 0.5 )) or x=f( l g((∑ n i=1 q i ) 0.5 When sampling, the distribution of the number of texts corresponding to different labels in the sampled text is basically consistent with the distribution of the number of texts corresponding to different labels in A.

[0102] The first judgment module is used to determine if q i ≥s i Then, from the i-th type of text to be sampled, a i Get s from i The sampled texts of class i are constituted by the sampled texts of class i; otherwise, the sampled texts of class i a are used to form the target sampled texts. i The target sampled text is identified as the i-th class.

[0103] Preferably, the first judgment module includes:

[0104] The clustering module is used if q i ≥s i Then according to a i The text similarity between the texts to be sampled includes a. i Perform clustering to obtain clustering result G. i G i Includes m clusters, where m is the number of pairs of a. i The number of clusters obtained by clustering.

[0105] The second acquisition module is used to acquire G. i The number of texts to be sampled included in the smallest cluster. i,min .

[0106] The second judgment module is used if s i,min ≥f(s i If / m), then proceed to the second traversal module.

[0107] The second traversal module is used to traverse G.i From each g i,j f(s) i / m) texts to be sampled constitute the initial sampled text of the i-th class; g i,j For a i The j-th cluster obtained by clustering, where the value of j ranges from 1 to m.

[0108] The third judgment module is used to determine if m×f(s) i / m)=s i If so, the initial sampled text of class i is determined as the target sampled text of class i.

[0109] Example 5:

[0110] This embodiment provides an electronic device, including a memory, a processor, and a computer program stored in the memory and executable on the processor. When the processor executes the computer program, it performs the following steps:

[0111] S100, obtain the text set A to be sampled. A includes several classes of text to be sampled. Texts of the same class have the same label, and texts of different classes have different labels.

[0112] S200, obtain the number of samples s for the i-th class. i s i =f((q i ) 0.5 / ((q i / (∑ n i=1 q i )) 1 / x ), x is the preset first value, x is a positive integer, f() is the floor function; i ranges from 1 to n, n is the number of categories of the text to be sampled; q i denoted as the number of sampled texts included in the i-th type of sampled text.

[0113] S300, if q i ≥s i Then, from the i-th type of text to be sampled, a i Get s from i The sampled texts of class i are constituted by the sampled texts of class i; otherwise, the sampled texts of class i a are used to form the target sampled texts. i The target sampled text is identified as the i-th class.

[0114] Example 6:

[0115] This embodiment provides a computer-readable storage medium on which a computer program is stored. When the computer program is executed by a processor, it performs the following steps:

[0116] S100, obtain the text set A to be sampled. A includes several classes of text to be sampled. Texts of the same class have the same label, and texts of different classes have different labels.

[0117] S200, obtain the number of samples s for the i-th class. i s i =f((q i ) 0.5 / ((q i / (∑ n i=1 q i )) 1 / x ), x is the preset first value, x is a positive integer, f() is the floor function; i ranges from 1 to n, n is the number of categories of the text to be sampled; q i denoted as the number of sampled texts included in the i-th type of sampled text.

[0118] S300, if q i ≥s i Then, from the i-th type of text to be sampled, a i Get s from i The sampled texts of class i are constituted by the sampled texts of class i; otherwise, the sampled texts of class i a are used to form the target sampled texts. i The target sampled text is identified as the i-th class.

[0119] Example 7:

[0120] In Example 1, each text in the target sampled text has a corresponding label. However, the labels may be incorrect, meaning that the labels on the text may not match the text itself. To achieve text cleaning of the target sampled text, the text smoothing sampling method in this example further includes the following steps:

[0121] L100, retrieve the text to be cleaned, cle, cle=(cle1,cle2,…,cle…). ra ,…,cle to ), cle ra Let ra be the ra-th text to be cleaned, where ra ranges from 1 to to, and to is the number of texts to be cleaned.

[0122] In this embodiment, the target sampled text is defined as tex, and to is the number of target sampled texts.

[0123] L200, iterate through cle, and get cle ra The corresponding prompt word is "pro". ra pro ra Includes example text mod of mind chain ra and the text to be inferred (ans) ra modra =(mod ra,1 ,mod ra,2 ,…,mod ra,b ,…,mod ra,num ), mod ra,b For pro ra The example text includes the b-th thought chain, where b ranges from 1 to num, and num is the number of thought chains. ra The number of corresponding thought chain example texts; each mod ra,b Includes a corresponding target text tar ra,b A corresponding tag l ab ra,b and a corresponding judgment text tho ra,b ,tho ra,b Including a pair l ab ra,b Is it tar? ra,b The label identification identifier sig ra,b and sig ra,b The corresponding reasoning text; ans ra Including cle ra and cle ra tags l ab ra .

[0124] In this embodiment, if the value of num is small, that is, if the number of thought chain example texts included in the prompt words input to the trained large language model is small, it is not conducive to the trained large language model fully learning the thought process of judging whether the label is correct, thus affecting the accuracy of the judgment result; if the value of num is large, that is, if the number of thought chain example texts included in the prompt words input to the trained large language model is large, it takes a long time for the trained large language model to learn the thought process of judging whether the label is correct, which is not conducive to quickly giving a judgment result; as an optional specific implementation, num is an empirical value, which can be selected as 2≤num≤10.

[0125] As a preferred embodiment, each l ab ra,b and l ab ra As child tags under the same parent tag, pro ra When used as cue words in a trained large language model, it helps the model learn to think in relation to the text being reasoned about, further improving the accuracy of the model's output. For example, num=4, l ab ra For marital and family disputes. l ab ra,1For contract disputes, l ab ra,2 For property damage compensation disputes, l ab ra,3 Disputes over alimony, l ab ra,4 For marital and family disputes. l ab ra , l ab ra,1 , l ab ra,2 , l ab ra,3 and l ab ra,4 All are secondary tags. l ab ra , l ab ra,1 , l ab ra,2 , l ab ra,3 and l ab ra,4 All of the parent tags (i.e., first-level tags) are disputes. l ab ra , l ab ra,1 , l ab ra,2 , l ab ra,3 and l ab ra,4 All of these are sub-tags of the dispute tag.

[0126] As a specific implementation method, tar ra,1 Disputes arising between boyfriends and girlfriends due to relationship issues. l ab ra,1 entangled in pursuit of what was unsuccessful, sig ra,1 This is incorrect, sig ra,b The corresponding reasoning text is: the label belongs to the dispute caused by one party pursuing the other unsuccessfully, but the text mentions boyfriend and girlfriend, which conflicts with the unsuccessful pursuit. Therefore, the label is incorrect.

[0127] L300, will pro ra Input the trained large language model, and let the trained large language model make judgments. l ab ra Is it cle ra The tag.

[0128] Those skilled in the art will understand that any large language model in the prior art falls within the protection scope of this invention.

[0129] In this embodiment, pro ra These are prompts based on thought chains; in this embodiment, pro ra As input to a trained large language model, it helps the trained large language model learn to judge whether the labeled tags are text tags, thereby improving the accuracy of the output results of the trained large language model and thus improving the accuracy of cleaning.

[0130] L400, based on a trained large language model l ab ra Is it cle ra The result of the label judgment determines whether to include cle ra Wash it off.

[0131] This embodiment aims to use a large language model to determine whether the tags of the text to be cleaned are incorrect. Specifically, for each text to be cleaned, its corresponding prompt words are first obtained. These prompt words include *n* thought chain example texts and the text to be reasoned about. The *n* thought chain example texts are used to help the trained large language model better learn the thinking process of judging whether a tag is a tag of a text. Each thought chain text includes a target text, a tag, a judgment identifier indicating whether the tag is the target text, and the reason for making the judgment. Based on these *n* thought chain example texts, the trained large language model can learn the thinking process of judging whether a tag is a tag corresponding to a text, and has the ability to judge... l ab ra Is it cle ra The semantic analysis capability of the tags; therefore, by inputting the prompt words corresponding to the text to be judged into the trained large language model, the correctness of the text tag can be automatically judged, which solves the problem of the large amount of human resources required for manual judgment of the text tag in the existing technology.

[0132] As a preferred embodiment, L400 includes: if the trained large language model is l ab ra Is it cle ra If the result of the label judgment is yes, then proceed to L410.

[0133] L410, obtains the accuracy (tpr) of the trained large language model for the judgment result being yes.

[0134] In this embodiment, if the trained large language model is l ab ra Is it cle ra The label judgment result is "yes", indicating that the trained large language model has judged it as "yes". l ab ra For clera label

[0135] Optionally, the accuracy rate of the trained large language model for a "yes" judgment result is obtained based on the test text. When the accuracy rate tpr of the trained large language model for a "yes" judgment result is 90% and the trained large language model for l ab ra whether it is cle ra the judgment result of the label is "yes", it means l ab ra is cle ra the probability of the label is 90%; when the accuracy rate tpr of the trained large language model for a "yes" judgment result is 78% and the trained large language model for l ab ra whether it is cle ra the judgment result of the label is "yes", it means l ab ra is cle ra the probability of the label is 78%.

[0136] L420, if tpr ≥ tf, then judge not to wash away cle ra ; tf is a preset accuracy rate threshold.

[0137] In this embodiment, tf is an empirical value. Optionally, tf is 90% or 95%.

[0138] Based on L410 - L420, in this embodiment, when the accuracy rate of the trained large language model for a "yes" judgment result is relatively high, directly take the judgment result of the trained large language model as the standard. Thus, the text with a "yes" judgment result output by the corresponding trained large language model in cle can be retained, realizing the rapid cleaning of these texts.

[0139] In this embodiment, L420 further includes: if tpr < tf, then enter L421.

[0140] L421, obtain the trained large language model for l ab ra whether it is cle ra the qua - th judgment result of the label, qua is a preset number of repeated inferences, qua is an odd number and qua ≥ 3.

[0141] L422, if there are more than or equal to (qua + 1) / 2 times of "no" judgment results in the qua - th judgment results, then judge to wash away cle ra ; otherwise, judge not to wash away cle ra away.

[0142] Based on L421-L422, in this embodiment, when the accuracy rate of the trained large language model for a judgment result of "yes" is relatively low, instead of directly taking the judgment result of the trained large language model as the standard, the trained large language model is used to make multiple judgments on the prompt words corresponding to the text, and the judgment result with the most occurrences in the multiple judgments is used as the final judgment result. Thus, this embodiment can reduce the judgment deviation triggered by factors such as hallucinations in the trained large language model, and further improve the accuracy of cleaning.

[0143] As a preferred specific implementation, L400 further includes: if the judgment result of the trained large language model for l ab ra whether it is the label of cle ra is "no", then enter L430.

[0144] L430, obtain the false positive rate fpr of the trained large language model for a judgment result of "no".

[0145] In this embodiment, if the judgment result of the trained large language model for l ab ra whether it is the label of cle ra is "no", it means that the trained large language model judges l ab ra is not the label of cle ra of.

[0146] Optionally, the false positive rate of the trained large language model for a judgment result of "no" is obtained based on the test text. When the false positive rate fpr of the trained large language model for a judgment result of "no" is 68% and the judgment result of the trained large language model for l ab ra whether it is the label of cle ra is "no", it means that l ab ra is not the label of cle ra has a probability of 68%; when the true positive rate fpr of the trained large language model for a judgment result of "yes" is 92% and the judgment result of the trained large language model for l ab ra whether it is the label of cle ra is "no", it means that l ab ra is not the label of cle ra has a probability of 92%.

[0147] L440, if fpr < tf, then enter L450; otherwise, clean cle ra off.

[0148] In this embodiment, tf is an empirical value, and optionally, tf is 90% or 95%.

[0149] L450, acquiring trained large language model pairs l ab ra Is it cle ra The label is judged qua times, where qua is the preset number of repeated reasonings, and qua is odd and qua≥3.

[0150] In this embodiment, qua is an empirical value, and optionally, qua is 3 or 5.

[0151] L460, if any of the qua judgment results is negative, then the judgment will be changed to cle. ra Clean it up; otherwise, determine that the clean will not be removed. ra Wash it off.

[0152] In this embodiment, if there are more than or equal to (qua+1) / 2 negative judgments in the qua judgment results, it means that the majority of the judgment results in the qua judgment results are negative; if there are less than (qua+1) / 2 negative judgments in the qua judgment results, it means that the majority of the judgment results in the qua judgment results are positive.

[0153] Based on L430-L460, this embodiment does not directly rely on the judgment result of the trained large language model when the accuracy of the judgment result is low. Instead, it uses the trained large language model to make multiple judgments on the prompt words corresponding to the text, and takes the judgment result that appears most frequently among the multiple judgments as the final judgment result. Thus, this embodiment can also recall text from the text with the corresponding initial judgment result of no, reduce the judgment bias of the trained large language model triggered by the illusion light factor, and improve the accuracy of cleaning.

[0154] Example 8:

[0155] If the prompts used to input the trained large language model in Example 7 are manually constructed, there is still a problem of consuming a large amount of human resources. In order to further reduce the consumption of human resources, this example, based on Example 7, also includes automatically obtaining the prompts. ra The process; specifically, pro ra The acquisition process includes:

[0156] L210, will cle ra Input into the first trained model to obtain cle ra The first-level tag l ab 1ra The trained first model is used to obtain the first-level label of the input text, and the accuracy of the trained first model in obtaining the first-level label of the input text is greater than or equal to tf, where tf is a preset accuracy threshold.

[0157] In this embodiment, the first model trained to infer the first-level labels of the text has a high accuracy rate. This embodiment will use cle ra The output of the first model trained as input is used as cle ra The first-level tag l ab 1 ra .

[0158] In this embodiment, the trained first model is used to obtain the first-level label of the input text. The first-level label is a coarse label. The first-level label also includes several second-level labels. The second-level label is a refined label. In this embodiment, the accuracy of the trained first model inferring the second-level label of the text is low (i.e., less than tf). Therefore, in this embodiment, only the trained first model is used to obtain the first-level label of the text, and the trained first model is not used to obtain the second-level label of the text.

[0159] In this embodiment, the first model is a neural network model, and supervised training is used when training the first model. Optionally, the process of training the first model includes: obtaining a training text set, which includes a plurality of training texts; obtaining a training label set, which includes a first-level label corresponding to each training text; and training the first model based on the training text set and the training label set to obtain the trained first model.

[0160] L220, according to l ab 1 ra Match within the pre-defined thought chain example text library bas to obtain... l ab 1 ra Matching num example texts of thought chains mod ra ;bas=(bas1,bas2,…,bas ce ,…,bas he ), bas ce For the thought chain example text sub-library corresponding to the ce-th first-level tag of cle, bas ce =(bas ce,1 ,bas ce,2 ,…,bas ce,me ,…,bas ce,te ), bas ce,meThis is the example text of the thought chain corresponding to the me-th second-level tag included in the ce-th first-level tag corresponding to cle, where me ranges from 1 to te, te is the number of second-level tags included in the ce-th first-level tag corresponding to cle, ce ranges from 1 to he, and he is the number of first-level tags corresponding to cle; num is the thought chain of cle. ra The number of corresponding thought chain example texts.

[0161] In this embodiment, bas ce,me Includes several example texts of thought chains, bas ce,me The tag in each example text of the thought chain is the me-th second-level tag included in the ce-th first-level tag corresponding to cle, but bas ce,me The judgment identifiers in the different thought chain example texts may be the same or different, bas ce,me The judgment identifiers in the included thought chain example text are used to indicate whether the corresponding tags in the thought chain example text are tags of the corresponding target text in the thought chain example text. For example, if bas ce,me If the judgment marker in the included thought chain example text is correct or not, then it indicates that the corresponding tag in the thought chain example text is the tag of the target text corresponding to the thought chain example text; if bas ce,me If the judgment flag in the included thought chain example text is incorrect or not, it indicates that the tag in the thought chain example text is not the tag of the target text in the thought chain example text.

[0162] Optionally, the L220 includes:

[0163] L221, if bas ce and l ab 1 ra If a match is found, proceed to L222.

[0164] In this embodiment, if bas ce The corresponding first-level tag and l ab 1 ra If they are the same, then determine the value of bas. ce and l ab 1 ra Match; otherwise, check the base. ce and l ab 1 ra Mismatch.

[0165] L222, if te=num, then from each bas ce,me Get one example text of the thought chain to build a modra ; If te > num, enter L223; if te < num, enter L225.

[0166] L223, obtain the priority of each bas ce,me .

[0167] In this embodiment, the priority of each bas ce,me is known. Optionally, the more the number of example texts of the thought chain included in bas ce,me , the higher the priority of bas ce,me .

[0168] L224, obtain 1 example text of the thought chain from each target sub-library to construct mod ra , where the target sub-library is the top num example text sub-libraries of bas ce with the highest priority.

[0169] L225, obtain 1 example text of the thought chain from each bas ce,me to construct the initial text.

[0170] L226, obtain the text deviation quantity Δq, Δq = num - te;

[0171] L227, obtain Δq example texts of the thought chain from the remaining example texts of bas ce and append them to the initial text, and determine the appended initial text as mod ra ; The remaining example texts of bas <00​​​​​​​​​​​​​​​​​​​​​​​​​​​​​When input into a trained large language model, the large language model can learn more comprehensively the thinking process of judging whether a secondary label is a secondary label of text, so that the trained large language model can give a more accurate judgment result and improve the accuracy of cleaning.

[0173] L230, according to mod ra cle ra and cle ra secondary tags l ab 2 ra Build cle ra The corresponding prompt word is "pro". ra .

[0174] In this embodiment, cle ra secondary tags l ab 2 ra That is, cle ra tags l ab ra .

[0175] Based on L210-L230, this embodiment can automatically build pro ra This eliminates the need for manual word creation, improves the efficiency of word creation, and reduces the human resources required for text cleaning.

[0176] As a preferred embodiment, the process of obtaining num includes:

[0177] L201, retrieves the preset thought chain example text library bas and... l ab 1 ra Matching BAS ce The number of example texts for the included thought chain is pn ra .

[0178] L202, obtain the number of initial thought chain example texts (cn) ra ,cn ra =f(min(num max max(num) min ,num avg ×pn ra / pn avg ))), num max num represents the maximum number of sample texts for the preset thought chain. max =tok max / (min(tok avg,1 ,tok avg,2 ,…,tok avg,ce ,…,tokavg,he )), tok max tok is the total number of characters in the preset thought chain example text. avg,ce for bas ce The average number of characters in the example text of the thought chain included; num min num represents the minimum number of sample texts for the predefined thought chain. min =tok max / (max(tok avg,1 ,tok avg,2 ,…,tok avg,ce ,…,tok avg,he )); num avg num represents the average number of example texts in a predefined thought chain. avg =tok max / (avg(tok avg,1 ,tok avg,2 ,…,tok avg,ce ,…,tok avg,he )); pn avg The preset threshold for the number of example texts in the thought chain; max() is to take the maximum value, min() is to take the minimum value, avg() is to take the average value, and f() is to round down.

[0179] In this embodiment, the average number of thought chain example texts included in each thought chain example text sub-library in bas is determined as a preset threshold for the number of thought chain example texts.

[0180] L203, if cn ra Greater than or equal to l ab 1 ra The number of secondary tags included will be cn ra The value is determined to be num; if cn ra Less than l ab 1 ra The number of secondary tags included will be l ab 1 ra The number of secondary tags included is determined as num.

[0181] In this embodiment, if cn ra Less than l ab 1 ra The number of included secondary tags is prioritized from those with... l ab 1 ra Matching BAS ceSelect or reconstruct a thought chain example text with a shorter word count to form a mod. ra to make mod ra The number of characters included does not exceed tok max That's all.

[0182] Based on L201-L203, this embodiment can achieve the goal of setting different thought chain example texts according to different texts to be cleaned. Specifically, considering the character limit corresponding to the prompt words, the maximum, minimum and average number of thought chain example texts are used as reference factors. It can also set a larger number of thought chain example texts when the thought chain example texts corresponding to the first-level tags of the text to be cleaned include a large number of thought chain example texts, so as to improve the diversity of the set thought chain example texts. Considering the need for the trained large language model to learn the comprehensiveness of reasoning, the number of set thought chain example texts meets the requirement of being greater than or equal to the number of second-level tags included in the first-level tags of the text to be cleaned, so that the trained large language model can learn comprehensive tag judgment thinking, thereby improving the accuracy of judgment.

[0183] Example 9:

[0184] In Example 1, the labels of the target sampled text may be incorrect. To obtain correct and more comprehensive labels for each text in the target sampled text, the text smoothing sampling method in this example further includes:

[0185] F100, retrieves the text tex of the tag to be retrieved, tex=(tex1,tex2,…,tex ac ,…,tex ae ), tex ac Let be the text of the ac-th tag to be retrieved, where ac ranges from 1 to ae, and ae is the number of text tags to be retrieved; each tex ac This corresponds to several original tags.

[0186] In this embodiment, the target sampled text is defined as tex, and ae is the number of target sampled texts.

[0187] In this embodiment, each tex ac The number of corresponding original tags is greater than or equal to 1, and the original tag may be a tex. ac The correct corresponding label may also be tex. ac The corresponding error labels, and the proportion of correct labels in the original labels of all text corresponding to the tex is greater than the proportion of error labels in the original labels; as a specific implementation method, each tex ac The corresponding original labels are manually labeled.

[0188] F200, based on the text of the first tag to be acquired in the tex file. 1 Obtain the first labeled inference model mode1, which has been trained. mode1 = (mode 1,1 ,mode 1,2 ,…,mode 1,av ,…,mode 1,ax ), mode 1,av For based on tex 1 The obtained av-th trained first-label inference model, where av ranges from 1 to ax, and ax is the value according to tex. 1 The number of trained first-label inference models obtained; ax ≥ 2.

[0189] In this embodiment, the text containing the tags to be obtained in the tex file is divided into two parts, one of which is a tex file. 1 The other part is tex 2 ;Optional, tex 1 The number of texts with tags to be retrieved in the .tex file is half the number of texts with tags to be retrieved in the .tex file. Correspondingly, the .tex file... 2 The number of texts with tags to be retrieved in the middle is also half the number of texts with tags to be retrieved in the tex.

[0190] In this embodiment, each mode 1,av The training samples are from tex 1 Different modes 1,av The corresponding training samples differ; as a specific implementation, F200 includes:

[0191] F210, tex 1 The text is divided into subsets, resulting in a subset zc1, where zc1 = (zc... 1,1 ,zc 1,2 ,…,zc 1,av ,…,zc 1,ax ), zc 1,av To make tex 1 The ax-th text subset obtained by partitioning.

[0192] Optionally, tex 1 Each text is divided into ax subsets.

[0193] F220, initialize model variable ha to 1.

[0194] F230, Select from zc1 excluding zc 1,ha The ax-1 text subsets other than the ha-th text are used as the training samples.

[0195] F240. Use the $ha$-th training sample and the corresponding original label to train the $ha$-th first label inference model, and obtain the $ha$-th trained first label inference model mode 1,ha .

[0196] F250. If $ha < ax$, then $ha = ha + 1$, and repeat F230 - F240 until $ha = ax$.

[0197] Based on F210 - F250, when $ha$ is 1, executing F230 - F240 can obtain the 1st trained first label inference model mode 1,1 ; when $ha$ is 2, executing F230 - F240 can obtain the 2nd trained first label inference model mode 1,2 , and so on. When $ha$ is $ax$, executing F230 - F240 can obtain the $ax$-th trained first label inference model mode 1,ax ; thus, after executing F210 - F250, $ax$ trained first label inference models can be obtained.

[0198] F300. According to mode1, obtain the text $tex$ of the second label to be obtained in $tex$ 2 the inference label $qa$ of the text of the label to be obtained in 2 , $qa$ 2 = ($qa$ 2 1, $qa$ 2 2, …, $qa$ 2 er , …, $qa$ 2 zn ), $qa$ 2 er is the inference label of the text of the $er$-th label to be obtained in $tex$, and the value range of $er$ is from 1 to $zn$, where $zn$ is the number of texts of the labels to be obtained in $tex$ 2 , $qa$ 2 2 er = ($qa$ 2 er,1 2 , $qa$ er,2 2 , …, $qa$ er,av 2 , …, $qa$ er,ax 2 ), $qa$ er,av 1,av is the inference label of the text of the $er$-th label to be obtained according to mode 2 ; $tex$ 2 is the text of the $er$-th label to be obtained in $tex$; $tex$ 1 is the text of $tex$ except for $tex$ 1The text of the tags to be retrieved, other than those in the QA; each QA 2 er,av Includes several reasoning tags.

[0199] In this embodiment, tex 2 The text containing the er-th tag to be acquired is used as input to the first trained tag inference model to obtain the mode. 1,1 The inferred tex 2 The inferred label qa of the er-th text to be labeled 2 er,1 ; to tex 2 The text containing the er-th tag to be acquired is used as input to the second trained first tag inference model to obtain the mode. 1,2 The inferred tex 2 The inferred label qa of the er-th text to be labeled 2 er,2 ; and so on, tex 2 The text containing the er-th tag to be acquired is used as input to the ax-th trained first tag inference model to obtain the mode. 1,ax The inferred tex 2 The inferred label qa of the er-th text to be labeled 2 er,ax .

[0200] F400, iterate through qa 2 , for qa 2 er The filtering process yields the filtered inference tags nqa 2 er ;nqa 2 er =(nqa 2 er,1 ,nqa 2 er,2 ,…,nqa 2 er,bv ,…,nqa 2 er,bx ), nqa 2 er,bv For QA 2 er The remaining bv-th inference label after filtering, where bv ranges from 1 to bx, and bx represents the pair of qa. 2 er The number of inference tags remaining after filtering.

[0201] In this embodiment, qa 2 er The purpose of screening is to select QA2 er The process involves filtering out incorrect tags and retaining correct tags.

[0202] As a preferred embodiment, F400 includes:

[0203] F410, get qa 2 Each inference label appearing in QA 2 The number of times it appears in the text.

[0204] F420, if qa 2 A certain inference label appears in QA 2 If the number of occurrences in qa is greater than or equal to a preset threshold, then qa will be... 2 The inference tag appearing in the query is determined to be an inference tag that is retained after filtering; otherwise, qa 2 The inference tag that appears in the data is determined to be an inference tag that was filtered out after screening.

[0205] In this embodiment, qa 2 Inference tags that appear more than or equal to a preset threshold number of times are classified as tex. 2 The correct tag for the er-th text to be retrieved will be qa 2 Inference tags that appear less than a preset threshold number of times are classified as tex. 2 The er-th er-th text to be retrieved contains erroneous tags. Optionally, a preset threshold for the number of attempts is ax / 2.

[0206] Based on F410-F420, this embodiment implements qa 2 er The screening, because this embodiment will use qa 2 The inference tags that appear most frequently are judged as the correct tags, while qa 2 The inference labels that appear more frequently are consistent inference results from a large number of trained first-label inference models. Therefore, this embodiment is based on the nqa obtained from F410-F420. 2 er The Chinese label is tex 2 The probability of the correct label being found for the er-th text to be tagged is relatively high, which improves the accuracy of the final tagged text.

[0207] As a second preferred embodiment, F400 includes:

[0208] F401, Get QA 2 er The reasoning tag wqa appears in 2 er wqa 2er =(wqa 2 er,1 wqa 2 er,2 ,…,wqa 2 er,cv ,…,wqa 2 er,cx ), wqa 2 er,cv For qa 2 er The cv-th inference label that appears in the text, where cv ranges from 1 to cx, and cx is qa. 2 er The number of inference tags appearing in the text.

[0209] In this embodiment, different wqa 2 er,cv This corresponds to different inference labels; since different trained first-label inference models may infer the same or different inference labels, cx is less than or equal to qa. 2 er Each qa in 2 er,av The sum of the number of inference tags included.

[0210] F402, iterate through wqa 2 er Use a trained large language model to determine wqa 2 er,cv Is it a tex? 2 The tag of the erth text whose tag is to be retrieved.

[0211] Those skilled in the art will understand that any large language model in the prior art falls within the protection scope of this invention.

[0212] Preferably, thought chain-based prompts enable the trained large language model to determine wqa. 2 er,cv Is it a tex? 2 The tags of the text to be tagged in the erth case are provided, and the prompt words include several example texts of thought chains related to the content to be judged. Thus, by using the trained large language model, we can better learn the thought process to judge whether the tag is correct and improve the accuracy of the judgment result.

[0213] F403, if so, then wqa 2 er,cv Append to the preset er-th tag sequence; otherwise, do not add wqa. 2 er,cv Append to the preset er-th tag sequence; the preset er-th tag sequence is initialized as an empty sequence.

[0214] F404, the preset er-th label sequence is determined as nqa 2 er .

[0215] Based on F401-F404, this embodiment implements QA based on a trained large language model. 2 er The selection process uses a trained large language model to improve NQA. 2 er The accuracy of the inference labels.

[0216] F500, nqa 2 er Determined to be tex 2 The tag of the erth text to be judged.

[0217] In this embodiment, each text in the text tex to be tagged corresponds to an original tag. These original tags may contain incorrect tags or be incomplete. This embodiment utilizes a portion of the text tex. 1 Multiple trained first-label inference models can be obtained from the corresponding original labels. Each trained first-label inference model has the ability to infer labels. In this embodiment, another part of the text tex is obtained from the tex based on these multiple trained first-label inference models. 2 The inference tags are obtained by using multiple trained first label inference models to obtain inference tags for the text. Different trained first label inference models have different semantic analysis capabilities, and the inference tags obtained for the same text may also be different. In this embodiment, the inference tags obtained by multiple trained first label inference models for the same text are used together as the inference tags for the text. Therefore, the inference tags obtained by this embodiment are more comprehensive. Moreover, this embodiment also filters the inference tags obtained by multiple trained first label inference models to select the correct tags from the more comprehensive inference tags. Thus, this embodiment achieves the goal of obtaining correct and more comprehensive tags for the text.

[0218] As an optional specific implementation, ax is an empirical value, for example, 3≤ax≤5.

[0219] As a preferred embodiment, the method for obtaining ax includes:

[0220] F201, Get TeX 1 The number of texts containing the tags to be retrieved (shu) 1 .

[0221] F202, obtain the initial number of partitions hua0, hua0 = floor(shu 1 / shu0), where shu0 is the preset text quantity threshold, and floor() is for rounding down.

[0222] In this embodiment, shu0 is an empirical value, which corresponds to the minimum number of training samples required to train a first-label inference model to a model with an accuracy greater than or equal to a preset accuracy threshold.

[0223] F203, obtain the first partition count hua1, hua1=min(max(hua0,hua min ),hua max min() returns the minimum value, max() returns the maximum value. min The minimum number of partitions is preset, hua max This is the preset maximum number of divisions.

[0224] In this embodiment, hua min and hua max All are empirical values.

[0225] F204, from tex 1 The text of the tag to be obtained, which has a ratio of (hua1-1) / hua1, and the corresponding original tag are used to train the test tag inference model, resulting in the trained test tag inference model.

[0226] F205, if the accuracy of the trained test label inference model is greater than or equal to the preset accuracy threshold, then hua1 is determined as ax.

[0227] In this embodiment, if the accuracy of the trained test label inference model is less than a preset accuracy threshold, then from the tex... 1 The text of the tag to be obtained, which represents the ratio of hua1 / (hua1+1), and the corresponding original tag are used to train the test tag inference model. The trained test tag inference model is obtained. If the accuracy of the trained test tag inference model is greater than or equal to a preset accuracy threshold, then hua1+1 is determined as ax; otherwise, from tex... 1 The text of the tag to be obtained, which represents the ratio of (hua1+1) / (hua1+2), and the corresponding original tag are used to train the test tag inference model. This results in a trained test tag inference model. If the accuracy of the trained test tag inference model is greater than or equal to a preset accuracy threshold, then hua1+2 is determined as ax; otherwise, the value is changed from tex. 1The text of the tag to be acquired with the ratio of (hua1+2) / (hua1+3) and the corresponding original tag are used to train the test tag inference model to obtain the trained test tag inference model; this process is repeated until the accuracy of the trained test tag inference model is greater than or equal to the preset accuracy threshold, and the corresponding number of divisions is determined as ax.

[0228] Based on F201-F205, ax pairs of tex 1 Dividing the data allows the tex to... 1 The text with a high proportion of (hua1-1) / hua1 corresponds to a large number of texts, which improves the efficiency of subsequent TeX-based implementations. 1 The accuracy of the first label inference model trained on text with a ratio of (hua1-1) / hua1 is beneficial to improving the accuracy of the final text label.

[0229] As an optional specific implementation, after F500, the method for obtaining the text label further includes:

[0230] F600, traverse tex 2 The original label corresponding to the er-th label to be obtained in the text, if tex 2 The original tag corresponding to the er-th tag to be retrieved in nqa 2 er If it exists in the tex, then determine the tex. 2 If the original tag corresponding to the er-th tag to be retrieved in the text is correct; otherwise, check if the original tag in the text is correct. 2 The original tag corresponding to the text of the erth tag to be retrieved is incorrect.

[0231] Therefore, this embodiment is based on tex. 2 The tag nqa corresponding to the er-th tag to be retrieved in the text. 2 er Implemented for tex 2 Determine the original tag corresponding to the text of the er-th tag to be retrieved.

[0232] In this embodiment, the tex is obtained. 1 The method for obtaining the tag of each text to be tagged is the same as the method for obtaining the tag of the text described above. 2 The method for obtaining the tags of each text to be tagged is similar, the difference being: obtaining the tex... 1 In the process of obtaining the tag for each text to be tagged, based on the tex in the tex... 2 Obtain the trained second-label inference model mode2, which includes several models based on tex. 2 The acquired trained second-label inference model; the tex is obtained based on mode2.1 Inference tag qa of the text to be tagged 1 ,qa 1 Including the tex obtained from all trained second-label inference models 1 Infer the label for each text whose label is to be obtained; iterate through the QA function. 1 , for qa 1 er The filtering process yields the filtered inference tags nqa 1 er ; will nqa 1 er Determined to be tex 1 The tag of the er-th text to be judged. Get the tex. 1 The specific process for obtaining the tags for each text to be tagged is the same as the process described above for obtaining the tags in the text. 2 The specific process for obtaining the tags for each text to be tagged is similar and will not be repeated here.

[0233] Example 10:

[0234] In order to obtain a named entity recognition model that can perform various preset types of entity annotation on the target sampled text, the text smoothing sampling method in this embodiment further includes the following steps:

[0235] D100, obtain the training text set data of the trained named entity recognition model, data={data1,data2,…,data...} se ,…,data st}, data se Given the se-th training text set of the trained named entity recognition model, data se The dataset includes several training texts, where se ranges from 1 to st, and st is the number of training texts in the trained named entity recognition model. The trained named entity recognition model is a model trained using data. This model is used to identify entities of a preset type ty in the input text and label them accordingly. ty = (ty1, ty2, ..., ty...). mt , ...,ty ht ),ty mt This is the mt-th preset type, where mt ranges from 1 to ht, and ht is the number of preset types.

[0236] In this embodiment, the trained named entity recognition model is trained using the st training text sets included in data. The purpose of training the named entity recognition model using the st training text sets included in data is to enable the trained named entity recognition model to recognize ht entities of preset types.

[0237] In this embodiment, when training the named entity recognition model using the st training text sets included in data, at least one entity of a preset type is labeled when labeling each training text set, and entities other than ht entities of preset types are not labeled. Moreover, each entity of the ht preset types has been labeled by at least one training text set. Thus, the trained named entity recognition model has the function of recognizing ht entities of preset types.

[0238] D200, iterate through data, if using data se When training a named entity recognition model, the data se If the mt-th entity of the preset type is annotated, then the data will be... se The proportion of positive samples for the mt-th preset type entity in the dataset is determined as data. se The mt-th weight qz se,mt Otherwise, set qz se,mt It is 0.

[0239] In this embodiment, when training the named entity recognition model using the st training text sets included in data, not all training text sets are labeled with ht preset types of entities. For example, if st=2 and ht=4, when training the named entity recognition model using the first and second training text sets, only entities of the first and second preset types are labeled when labeling the first training text set, and only entities of the second, third, and fourth preset types are labeled when labeling the second training text set.

[0240] In this embodiment, data se The percentage of positive samples for the mt-th preset type entity in the dataset is data. se The number of entities labeled as the mt-th preset type and the data se The ratio of the number of entities in the middle; if data is used se When training a named entity recognition model, the data se If the mt-th entity of the preset type has been annotated, then the data... se The value of the positive sample proportion of the mt-th preset type entity is assigned to qz. se,mt If using data se No data was used when training the named entity recognition model. se To annotate the mt-th entity of the preset type, then qz se,mt Set to 0.

[0241] D300, obtain the percentage of positive samples cb of ht preset types of entities in the test text set, cb = (cb1, cb2, ..., cb...). mt ,…,cb ht ), cb mt This is used to determine the percentage of positive samples for the mt-th entity of a preset type in the test text set.

[0242] In this embodiment, the proportion of positive samples of the mt-th preset type entity in the test text set is the ratio of the number of entities in the test text set labeled as the mt-th preset type to the total number of entities in the test text set.

[0243] In this embodiment, the positive sample ratio of the mt-th preset type entity in the test text set can represent the positive sample ratio of the mt-th preset type entity in the subsequent text set to be identified by the trained named entity recognition (e.g., target sampled text). Optionally, the test text set is the text extracted from the subsequent text set to be identified by the trained named entity recognition. The ht-th preset type entities in the test text set are labeled by manual annotation, and the positive sample ratio of the ht-th preset type entities is obtained.

[0244] D400, retrieve the percentage of positive samples (zb) of ht preset types of entities in the newly added text set, zb = (zb1, zb2, ..., zb...). mt ,…,zb ht ), zb mt This represents the percentage of positive samples for the mt-th preset type entity in the newly added text set.

[0245] In this embodiment, the newly added text set is text obtained to enable the trained text set to recognize newly added entities of a preset type. The proportion of positive samples of the mt-th preset type entity in the newly added text set is the ratio of the number of entities in the newly added text set labeled as the mt-th preset type to the total number of entities in the newly added text set. As an optional specific implementation, D400 includes:

[0246] D410, extract a preset proportion of text from the newly added text set to form the first extracted text set cq.

[0247] Optionally, a first extracted text set cq is formed by randomly selecting a preset proportion of text from the newly added text set, where the preset proportion is an empirical value.

[0248] D420 uses a trained named entity recognition model to identify ht preset types of entities for each text in cq, and obtains the annotation results of ht preset types of entities for each text in cq.

[0249] In this embodiment, each text in cq is used as input to a trained named entity recognition model to obtain the annotation results of ht entities of the corresponding preset types.

[0250] D430, determined as zb based on the annotation results of each text in cq corresponding to the mt-th preset type entity. mt .

[0251] In this embodiment, zb mt =∑ fs fe=1 zh fe,mt / (∑ fs fe=1 qh fe ), zh fe,mt Let qh be the number of entities in the fe-th text of cq that are labeled with the mt-th preset type. fe Let fs be the number of entities contained in the fe-th text in cq, where fe ranges from 1 to fs, and fs is the number of texts contained in cq.

[0252] D500, according to qz se,mt、 cb and zb determine the optimal number of texts to obtain from the newly added text set for training the trained named entity recognition model.

[0253] In this embodiment, the trained named entity recognition model is trained on the training text set `data`, and it already has the ability to recognize `ht` preset entity types. The new text set is a set of texts obtained in this embodiment to enable the trained text set to recognize entities of new preset types other than the aforementioned `ht` preset types. When retraining the trained named entity recognition model using the new text set, the number of texts selected from the new text set will affect not only the retrained named entity recognition model's ability to recognize entities of new preset types, but also its ability to recognize entities of the aforementioned `ht` preset types. In this embodiment, the positive sample ratio of entities of the `ht` preset types in the test text set, the positive sample ratio of entities of the `ht` preset types in the new text set, and each training text in `data` are used as the basis for the model's recognition capabilities. This set determines the optimal number of texts to obtain from the newly added text set for training the trained named entity recognition model, based on the weights for each preset type. The proportion of positive samples of ht preset types in the newly added text set determines the degree of influence of training the trained named entity recognition model using the newly added text set on the recognition accuracy of the original ht preset types of entities. The proportion of positive samples of ht preset types in the test text set and the weights of each training text set in data corresponding to each preset type reflect the recognition accuracy of the trained named entity recognition model for the original ht preset types of entities. Thus, this embodiment can achieve the goal of balancing the recognition accuracy of the retrained named entity recognition model for the original ht preset types of entities and the recognition accuracy for newly added preset types of entities.

[0254] In a preferred embodiment, D500 includes:

[0255] D510, obtain the loss dif for the newly added text, dif=(∑ ht mt=1 |cb mt -((∑ st se=1 qz se,mt ×mu se )+zb mt ×zq) / (su se + zq)|)+ke / zq,mu se For data se The number of texts included, su se For the corresponding qz in data se,mt The training text set that is not zero includes the sum of the number of texts; ke is a preset adjustment coefficient, ke>0; zq is the number of texts to be obtained from the newly added text set for training the trained named entity recognition model.

[0256] In this embodiment, ke is an empirical value, which is optional and can be 0. <ke<1。

[0257] D520, the value of zq when dif reaches its minimum value is determined as the optimal number of texts obtained from the newly added text set for training the trained named entity recognition model.

[0258] Based on the above preferred embodiments, the loss of the newly added text corresponding to the optimal number of texts is minimized. Texts obtained from the newly added text set according to this optimal number of texts are used as training samples for the trained named entity recognition model. The proportion of positive samples for each preset type of entity in the named entity recognition model is relatively close to the proportion of positive samples for the corresponding preset type of entity in the test samples. This results in a higher recognition accuracy for the original preset type of entity in the named entity recognition model trained using the optimal number of texts from the newly added text set. Furthermore, obtaining texts from the newly added text set according to this optimal number of texts also results in a larger number of texts obtained from the newly added text set, leading to a higher recognition accuracy for the newly added preset type of entity in the named entity recognition model trained using the optimal number of texts from the newly added text set. Therefore, the optimal number of texts obtained based on this preferred embodiment can achieve the goal of balancing the recognition accuracy of the named entity recognition model for both the original preset type of entity and the newly added preset type of entity.

[0259] As an optional specific implementation, after D500, when the computer-readable instructions are executed by the processor, the following steps are further performed:

[0260] D600: Obtain fk texts from the newly added text set to form the text set to be labeled, where fk is the optimal number of texts.

[0261] D700, retrieves the annotation results res corresponding to the text set to be annotated. res includes the annotation results of ty corresponding to the text set to be annotated and the annotation results of the newly added preset type corresponding to the text set to be annotated; the newly added preset type and any ty mt They are all different.

[0262] In this embodiment, the annotation result of ty corresponding to the text set to be annotated includes each ty corresponding to the text set to be annotated. mt The annotation results.

[0263] D800 uses the text set to be labeled and res to train the trained named entity recognition model.

[0264] Based on D600-D800, the trained named entity recognition model not only has the function of recognizing newly added preset types of entities, but also makes the recognition accuracy of the trained named entity recognition model for the original preset types of entities decrease less or even improve, thus improving the overall recognition function of the trained named entity recognition model.

[0265] While specific embodiments of the invention have been described in detail by way of example, those skilled in the art should understand that the examples are for illustrative purposes only and not intended to limit the scope of the invention. It should also be understood that various modifications can be made to the embodiments without departing from the scope and spirit of the invention. The scope of the invention is defined by the appended claims.

Claims

1. A method of smoothing sampling of text, characterized by, The method comprises the following steps: S100, acquiring a set of to-be-sampled texts A, the set A comprising a plurality of classes of to-be-sampled texts, the same class of to-be-sampled texts having the same label, and different classes of to-be-sampled texts having different labels; S200, obtain the number of samples s for the i-th class. i s i =f((q i ) 0.5 / ((q i / (∑ n i=1 q i )) 1 / x ), x is the preset first value, x is a positive integer, f() is the floor function; i ranges from 1 to n, n is the number of categories of the text to be sampled; q i Let x be the number of sampled texts included in the i-th class of sampled texts; x ≥ 3; S300, if q i ≥ s i , s i target sampling texts of the i-th category are obtained from the i-th category of to-be-sampled texts a i ; otherwise, the i-th category of to-be-sampled texts a i is determined as the target sampling texts of the i-th category.

2. The method of claim 1, wherein, x = f( l g((max(Q)) 0.5 )), x ≥ 3, Q is a sequence of sampling number of A, Q is composed of the number of to-be-sampled texts included in each type of to-be-sampled texts, max( ) is a maximum value function, l g is a logarithm with base 10.

3. The method of claim 1, wherein, x = f( l g((∑ n i=1 q i ) 0.5 )), x ≥ 3, l g is the logarithm to the base 10.

4. The method of claim 1, wherein, If q i ≥s i Then, from the i-th type of text to be sampled, a i Get s from i The target sampled texts of the i-th class consist of the following: S310, according to a i The text similarity between the included to-be-sampled texts is a i Clustering is performed to obtain a clustering result G i G i The m clusters include m, which is the number of clusters obtained by clustering a i ​ S320, obtaining G i The number s of the to-be-sampled texts included in the minimum cluster i,min ; S330, if s i,min ≥ f(s i / m), then go to S340; S340, traversing G i , obtaining f(s i,j / m) to-be-sampled texts from each g i , the initial sampling texts of the i-th category; g i,j is the j-th cluster obtained by clustering a i , j ranges from 1 to m; S350, if m x f(s i / m) = s i the initial sampling text of the i-th category is determined as the target sampling text of the i-th category.

5. An apparatus for smoothing sampling of text, characterized by The method comprises the following steps: The first acquisition module is configured to acquire a set of to-be-sampled texts A, the set A comprising a plurality of classes of to-be-sampled texts, the same class of to-be-sampled texts having the same label, and different classes of to-be-sampled texts having different labels; The first traversal module is configured to obtain a sampling quantity s of the i-th category i , s i =f((q i ) 0.5 / ((q i / (∑ n i=1 q i )) 1 / x )), x is a preset first value, x is a positive integer, f() is a rounding function; the value range of i is 1 to n, n is the category quantity of the to-be-sampled text; q i is the quantity of the to-be-sampled text included in the i-th category of to-be-sampled text; x≥3; The first judging module is configured to acquire s target sampling texts of the i-th type from the i-th type of to-be-sampled texts a if q i ≥ s i ; otherwise, determine the i-th type of to-be-sampled texts a as the target sampling texts of the i-th type. i i i ​​​ 6. The apparatus for smoothing sampling of text of claim 5, wherein, x = f( l g((max(Q)) 0.5 )), x ≥ 3, Q is a sequence of sampling number of A, Q is composed of the number of to-be-sampled texts included in each type of to-be-sampled texts, max( ) is a maximum value function, l g is a logarithm with base 10.

7. The apparatus for smoothing sampling of text of claim 5, wherein, x = f( l g((∑ n i=1 q i ) 0.5 )), x ≥ 3, l g is the logarithm to the base 10.

8. The apparatus for smoothing sampling of text of claim 5, wherein, The first judgment module comprises: a clustering module configured to, if q i ≥ s i , cluster a i according to text similarity between texts included in a i to obtain a clustering result G i , G i including m clusters, m being a number of clusters obtained by clustering a i . The second acquisition module is configured to acquire G i The minimum cluster includes the number s of to-be-sampled texts i,min ; The second judging module is configured to enter the second traversal module if s i,min ≥ f(s i / m). The second traversal module is configured to traverse G i , and obtain f(s i,j / m) to-be-sampled texts from each g i , and the to-be-sampled texts constitute initial sampling texts of the i-th category; g i,j is the j-th cluster obtained by clustering a i , and j ranges from 1 to m. a third determining module, configured to determine the initial sampling text of the i-th category as the target sampling text of the i-th category if mx f(s i m)=s i category.

9. An electronic device comprising a memory, a processor, and a computer program stored in the memory and executable on the processor, characterized in that, The processor executes the computer program to implement the text smoothing sampling method according to any one of claims 1 to 4.

10. A computer-readable storage medium storing a computer program, the computer program comprising instructions that, when executed by a computer, cause the computer to perform the method of any one of claims 1-9. The computer program is executed by the processor to implement the text smoothing sampling method according to any one of claims 1 to 4.

Citation Information

Patent Citations

  • Data enhancement method and device for medical text data, equipment and medium

    CN116796205A

  • Text classification model training method and device, storage medium and computer equipment

    CN111522942A

  • Sampling method and device, electronic equipment and storage medium

    CN115147593A