Smooth text sampling method and device, electronic equipment and storage medium
Through the smooth sampling method, the problem of poor reasoning ability and inconsistent sampling distribution of the semantic analysis model for a small number of text tags is solved, and better model performance and distribution consistency are achieved.
Patent Information
- Application Number
- CN202410997376.8
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2024-07-24
- Publication Date
- 2024-09-24
- Estimated Expiration
- 2044-07-24
AI Technical Summary
When sampling text collections with different labels, the number of texts differs greatly, resulting in the semantic analysis model having poor reasoning ability for labels with a small number of texts. Moreover, the existing sampling methods are rough, resulting in different labels in the sampled texts. The quantity distribution is inconsistent with the quantity distribution of the text to be sampled.
Adopt a text smooth sampling method and obtain the sampling number of each type of text to be sampled through the formula si=f((qi)0.5/((qi/(∑ni=1qi))1/x). If the number of texts is greater than or equal to This number is used to obtain the corresponding number of texts from this class, otherwise this class is used as the target sampling text to ensure that as much text as possible is extracted from classes with a smaller number of texts.
It improves the reasoning ability of the semantic analysis model for tags with a small number of texts, and makes the number distribution of different tags in the sampled text more consistent with the number distribution of the text to be sampled.
Smart Images

Figure CN118690022A
Abstract
Description
Technical Field
[0001] The present invention relates to the technical field of electronic digital data processing, and in particular to a text smoothing sampling method, device, electronic equipment and storage medium. Background Art
[0002] When sampling a text collection including 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 collection is randomly sampled or sampled proportionally according to the number of texts corresponding to different labels, the proportion of texts corresponding to labels with a small number of corresponding texts in the sampled texts is small, resulting in the trained semantic analysis model having poor reasoning ability for labels with a small number of corresponding texts. For example, Chinese patent application with publication number CN116796205A discloses a data enhancement method, device, equipment and medium for medical texts. The patent application clusters existing medical texts and determines the weight of each medical text based on the clustering results. Specifically, the medical texts with stronger representativeness are given higher weights. When sampling existing medical texts, the medical texts with higher corresponding weights are used as sampled texts. This sampling method allows more medical texts in clusters with a larger number of medical texts to be sampled, so that the medical texts in clusters with a larger number of medical texts are sampled. (1) The medical texts in the clusters with fewer medical texts are sampled less frequently, resulting in a smaller proportion of the medical texts in the clusters with fewer 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 the 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 the label; this sampling method is relatively rough, resulting in a large difference between the quantity distribution of texts corresponding to different labels in the sampled text and the quantity distribution of texts corresponding to different labels in the to-be-sampled text; how to improve the consistency between the quantity distribution of texts corresponding to different labels in the sampled text and the quantity distribution of texts corresponding to different labels in the to-be-sampled text, and how to improve the reasoning ability of the semantic analysis model trained based on the sampled text for labels with fewer corresponding texts, are issues that need to be addressed urgently. Summary of the invention
[0003] The purpose of the present invention is to provide a smooth sampling method, device, electronic device and storage medium for text, which are used to improve the consistency between the quantity distribution of texts corresponding to different labels in the sampled text and the quantity distribution of texts corresponding to different labels in the text to be sampled, and to improve the reasoning ability of a semantic analysis model trained based on the sampled text for labels with a small number of corresponding texts.
[0004] According to a first aspect of the present invention, a text smoothing sampling method comprises the following steps: S100, obtaining a text set A to be sampled, where A includes several types of texts to be sampled, the texts to be sampled of the same type have the same label, and the texts to be sampled of different types have different labels.
[0005] S200, obtain the number of samples 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 the 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 number of categories of the text to be sampled; q i is the number of texts to be sampled included in the i-th category of texts to be sampled.
[0006] S300, if q i ≥s i , then from the i-th type of text to be sampled a i Get i The sampled texts constitute the target sampled text of the i-th category; otherwise, the i-th category sampled text a i Determine the target sample text for the i-th category.
[0007] According to a second aspect of the present invention, a text smoothing sampling device comprises: The first acquisition module is used to acquire a text set A to be sampled, where A includes several types of text to be sampled, the labels of the same type of text to be sampled are the same, and the labels of different types of text to be sampled are different.
[0008] The first traversal module is used to obtain the number of samples 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 the 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 number of categories of the text to be sampled; q i is the number of texts to be sampled included in the i-th category of texts to be sampled.
[0009] The first judgment module is used if q i ≥s i , then from the i-th type of text to be sampled ai Get i The sampled texts constitute the target sampled text of the i-th category; otherwise, the i-th category sampled text a i Determine the target sample text for the i-th category.
[0010] 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 implements the above-mentioned text smoothing sampling method when executing the computer program.
[0011] According to a fourth aspect of the present invention, a computer-readable storage medium stores a computer program, and when the computer program is executed by a processor, the above-mentioned text smoothing sampling method is implemented.
[0012] The present invention has at least the following beneficial effects: In the present invention, the text to be sampled A includes n types of text to be sampled. The labels of the text to be sampled of the same type are the same, and the labels of the text to be sampled of different types are different. When sampling A, the present invention uses the formula s i =f((q i ) 0.5 / ((q i / (∑ n i=1 q i )) 1 / x )) Get the number of samples of the i-th type of text to be sampled in A, s i With q i ,∑ n i=1 q i Related to x, if the number of texts included in the i-th type of text to be sampled is greater than or equal to s i , then get s from the i-th type of text to be sampled i The sampled texts constitute the target sampled text of the i-th category; if the number of texts included in the i-th category of sampled text is less than s i , then the i-th type of to-be-sampled text is determined as the i-th type of target sampled text. Compared with the method of directly performing random sampling or proportional sampling on A, the formula s i =f((q i ) 0.5 / ((q i / (∑ n i=1 q i )) 1 / x)) can extract as much text as possible from A in the class with a small number of texts, and when the sampled text is subsequently used as training text for semantic analysis model training, the reasoning ability of the trained semantic analysis model for the label corresponding to the class with a small number of texts can be improved, and based on the formula s of the present invention i =f((q i ) 0.5 / ((q i / (∑ n i=1 q i )) 1 / x )) can also achieve the purpose of sampling more classes that include a larger number of texts than classes that include a smaller number of texts, and can improve 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. BRIEF DESCRIPTION OF THE DRAWINGS
[0013] In order to more clearly illustrate the technical solutions in the embodiments of the present invention, the following briefly introduces the drawings required for use in the description of the embodiments. Obviously, the drawings described below are only some embodiments of the present invention. For ordinary technicians in this field, other drawings can be obtained based on these drawings without creative work.
[0014] Figure 1 This is a flowchart of a text smoothing sampling method provided in Embodiment 1 of the present invention. DETAILED DESCRIPTION
[0015] The following will be combined with the drawings in the embodiments of the present invention to clearly and completely describe the technical solutions in the embodiments of the present invention. Obviously, the described embodiments are only part of the embodiments of the present invention, not all of the embodiments. Based on the embodiments of the present invention, all other embodiments obtained by those skilled in the art without creative work are within the scope of protection of the present invention.
[0016] Embodiment 1: According to this embodiment, a text smoothing sampling method is provided, such as Figure 1 As shown, including: S100, obtaining a text set A to be sampled, where A includes several types of texts to be sampled, the texts to be sampled of the same type have the same label, and the texts to be sampled of different types have different labels.
[0017] In this embodiment, A={a1, a2, …, a i ,…,a n}, a i is the i-th type of text to be sampled, the value range of i is 1 to n, and n is the number of categories of text to be sampled; a iThe number of texts to be sampled is q i , a i Included q i The labels of the texts to be sampled are the same, but different i The included text to be sampled has different labels.
[0018] S200, obtain the number of samples 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 the 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 number of categories of the text to be sampled; q i is the number of texts to be sampled included in the i-th category of texts to be sampled.
[0019] Optionally, x is an empirical value, for example, x=3.
[0020] Optionally, f( ) is a floor function or a round-to-nearest function.
[0021] Preferably, x=f( l g((max(Q)) 0.5 )) or x=f( l g((∑ n i=1 q i ) 0.5 )), Q is the sampling number sequence of A, Q is composed of the number of texts to be sampled in each category of texts to be sampled, Q=(q1,q2,…,q i ,…,q n ), max() is the maximum value function, l g is the logarithm to 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 )), the quantity distribution of texts corresponding to different labels in the sampled text is basically consistent with the quantity distribution of texts corresponding to different labels in A.
[0022] S300, if q i ≥s i , then from the i-th type of text to be sampled a i Geti The sampled texts constitute the target sampled text of the i-th category; otherwise, the i-th category sampled text a i Determine the target sample text for the i-th category.
[0023] Optional, randomly selected from a i Get i The texts to be sampled constitute the target sampled text of the i-th category.
[0024] Preferably, if q i ≥s i , then from a i Get i The target sampled texts of the i-th category are composed of the following: S310, according to a i The text similarity between the texts to be sampled includes a i Perform clustering and obtain the clustering result G i , G i Includes m clusters, m is the number of a i The number of clusters obtained by clustering.
[0025] In this embodiment, G i =(g i,1 ,g i,2 ,…,g i,j ,…,g i,m ), g i,j For a i The jth cluster obtained by clustering, the value of j ranges from 1 to m.
[0026] Those skilled in the art are aware that any method for obtaining text similarity in the prior art falls within the protection scope of the present invention.
[0027] Those skilled in the art know that any clustering method in the prior art falls within the protection scope of the present invention. Optionally, a density-based clustering method (such as DBSCAN) is used to cluster a i Clustering is performed, where a i Each of the texts to be sampled is taken as a point, and the distance between the two texts to be sampled is used to realize a i The distance between two to-be-sampled texts is negatively correlated with the text similarity between the two to-be-sampled texts. Therefore, a i The sampled texts with higher text similarity are clustered into one cluster, a i The sampled texts with lower text similarity are clustered into different clusters.
[0028] S320, Get G i The number of texts to be sampled in the smallest cluster s i,min .
[0029] In this embodiment, G i The smallest cluster in G i The cluster with the least amount of text is included.
[0030] S330, if s i,min ≥f(s i / m), then enter S340.
[0031] S340, traverse G i , from each g i,j Get f(s i / m) texts to be sampled constitute the initial sampled text of the i-th category; g i,j For a i The jth cluster obtained by clustering, the value of j ranges from 1 to m.
[0032] Optional, randomly selected from each g i,j Get f(s i / m) texts to be sampled constitute the initial sampling text of the i-th category.
[0033] S350, if m×f(s i / m)=s i , then the initial sampled text of the i-th category is determined as the target sampled text of the i-th category.
[0034] Based on S310-S350, this embodiment is in G i The number of texts to be sampled in the smallest cluster s i,min Greater than or equal to f(s i / m) in the case of i,j Get f(s i / m) samples of texts to be sampled constitute the initial sampled text of the i-th category. If m×f(s i / m)=s i , then the value from a i The purpose of uniformly sampling text in m clusters is i The m clusters represent a i m kinds of text in a, so this embodiment realizes i The diverse sampling improves the subsequent trained semantic analysis model i The reasoning ability of the corresponding label.
[0035] Preferably, S350 further includes: if m×f(s i / m)>s i , then randomly delete m×f(s i / m)-s itext, the initial sampled text of the i-th category after deletion is determined as the target sampled text of the i-th category, and the deleted m×f(s 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 get s from the remaining text i -m×f(s i / m) to-be-sampled texts are added to the initial sampled text of the i-th category, and the added initial sampled text of the i-th category is determined as the target sampled text of the i-th category; a i The remaining text is a i The text except the initial sampled text of the i-th category.
[0036] In this embodiment, G i The number of texts to be sampled in the smallest cluster s i,min Greater than or equal to f(s i / m) in the case of i,j Get f(s i / m) samples of texts to be sampled constitute the initial sampled text of the i-th category. If m×f(s i / m)≠s i , then a small adjustment is made based on the initial sampled text of the i-th category, minimizing the i The difference in the number of texts sampled in different clusters due to a i The m clusters represent a i m kinds of text in a, so this embodiment realizes i The diverse sampling improves the subsequent trained semantic analysis model i The reasoning ability of the corresponding label.
[0037] Preferably, S330 further includes: if s i,min <f(s i / m), then enter S331.
[0038] S331, traverse G i , from each g i,j Get i,min The texts to be sampled constitute the first sampled text of the i-th category.
[0039] Optional, randomly selected from each g i,j Get i,min The texts to be sampled constitute the first sampled text of the i-th category.
[0040] S332, obtaining the first remaining sampling quantity Δε1, Δε1=s i -m×s i,min .
[0041] 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 From g i,j Get i,min The clusters are composed of the remaining texts after the texts to be sampled.
[0042] In this embodiment, if g i,j The amount of text included is greater than s i,min , then g 1 i,j is a non-empty cluster; if g i,j Includes an amount of text equal to s i,min , then g 1 i,j An empty cluster.
[0043] S334, Get G 1 i The number of non-empty clusters in δ.
[0044] S335, if Δε1=δ, then from G 1 i Obtain one to-be-sampled text from each non-empty cluster and append it to the first sampled text of the i-th category, and determine the first sampled text of the i-th category after the appending as the target sampled text of the i-th category.
[0045] Based on S331-S335, this embodiment uses G i The number of texts to be sampled in the smallest cluster s i,min Less than f(s i / m) in the case of i,j Get i,min The texts to be sampled constitute the first sampled text of the i-th category, and then obtain the first remaining sample number Δε1 and the number of non-empty clusters δ. If δ=Δε1, then obtain 1 text to be sampled from each non-empty cluster and append it to the first sampled text of the i-th category. Therefore, this embodiment minimizes the number of samples from a iThe difference in the number of texts sampled in different clusters due to a i The m clusters represent a i m kinds of text in a, so this embodiment realizes i The diverse sampling improves the subsequent trained semantic analysis model i The reasoning ability of the corresponding label.
[0046] Preferably, S335 further includes: if Δε1<δ, then from G 1 i Obtain one to-be-sampled text from each target cluster of G and append it to the first sampled text of the i-th category, and determine the first sampled text of the i-th category after appending as the target sampled text of the i-th category; the target cluster is 1 i Δε1 non-empty clusters are randomly selected from the δ non-empty clusters.
[0047] In this embodiment, G i The number of texts to be sampled in the smallest cluster s i,min Less than f(s i / m) in the case of i,j Get i,min The texts to be sampled constitute the first sampled text of the i-th category, and then obtain the first remaining sample quantity Δε1 and the number of non-empty clusters δ. If Δε1<δ, a small adjustment is made to the first sampled text of the i-th category to minimize the number of samples from a i The difference in the number of texts sampled in different clusters due to a i The m clusters represent a i m kinds of text in a, so this embodiment realizes i The diverse sampling improves the subsequent trained semantic analysis model i The reasoning ability of the corresponding label.
[0048] Preferably, S335 also includes: if Δε1>δ, entering S336.
[0049] S336, Get G 1 i The number of texts to be sampled in the smallest non-empty cluster s 1 i,min .
[0050] S337, if s 1 i,min ≥f(Δε1 / δ), then enter S338.
[0051] S338, from G 1 iObtain f(Δε1 / δ) texts to be sampled from each non-empty cluster and append them to the first sampled text of the i-th class.
[0052] 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.
[0053] Based on S336 - S339, in this embodiment, when the number s of texts to be sampled included in the smallest cluster in G i is less than f(s i,min / m), first obtain s i texts to be sampled from each g i,j 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 i,min of texts to be sampled included in the smallest non-empty cluster in G 1 i ; if s 1 i,min ≥ f(Δε1 / δ), then obtain f(Δε1 / δ) texts 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; thus, this embodiment minimizes the difference in the number of texts sampled from different clusters of a 1 i,min . Since the m clusters of a i represent m types of texts in a i , this embodiment realizes diversified sampling of a i , and improves the inference ability of the subsequent trained semantic analysis model for the labels corresponding to a i . i
[0054] 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.
[0055] In this embodiment, S337 further includes: if s 1 i,min < 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.
[0056] In this embodiment, the texts to be sampled A include n types of texts to be sampled. The labels of texts to be sampled of the same class are the same, and the labels of texts to be sampled of different classes are different. When sampling A in this embodiment, according to the formula s i = f((qi ) 0.5 / ((q i / (∑ n i= 1q i )) 1 / x )) Get the number of samples of the i-th type of text to be sampled in A, s i With q i ,∑ n i=1 q i Related to x, if the number of texts included in the i-th type of text to be sampled is greater than or equal to s i , then get s from the i-th type of text to be sampled i The sampled texts constitute the target sampled text of the i-th category; if the number of texts included in the i-th category of sampled text is less than s i , then the i-th type of to-be-sampled text is determined as the i-th type of target sampled text. Compared with the method of directly performing random sampling or proportional sampling on A, the formula s based on this embodiment i =f((q i ) 0.5 / ((q i / (∑ n i=1 q i )) 1 / x )) can extract as much text as possible from A in the class with a small number of texts. When the sampled text is subsequently used as training text for semantic analysis model training, the reasoning ability of the trained semantic analysis model for the labels corresponding to the class with a small number of texts can be improved. Moreover, based on the formula s of this embodiment, i =f((q i ) 0.5 / ((q i / (∑ n i=1 q i )) 1 / x )) can also achieve the purpose of sampling more classes that include a larger number of texts than classes that include a smaller number of texts, and can improve 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.
[0057] Embodiment 2: In the above embodiment 1, i ≥s i In the case of a i The clustering method starts from a i Get i The sampled texts constitute the target sampled text of the i-th category, so as to achieve iDiversified sampling improves the inference ability of the subsequent trained semantic analysis model for a i corresponding label; however, for q i ≥s i and q i has a small difference with s i In the case, the effect of obtaining s i target sampling texts of the i-th class by clustering a i from a i is not obvious, and it will also increase the time to obtain 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, on the basis of the above Embodiment 1, the smooth sampling method of the text is further optimized.
[0058] Specifically, before S310, obtaining s i from a i target sampling texts of the i-th class further includes: S303, obtaining the sampling ratio r i of the i-th class, r i =s i / q i .
[0059] 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.
[0060] In this embodiment, r0 is an empirical value. Optionally, r0 is 5% or 10%.
[0061] Based on the above S303 - S304, when r i <r0, that is, when it is intended to obtain a smaller proportion of target sampling texts from a i , only then obtain s i target sampling texts of the i-th class by clustering a i from a i . Compared with randomly obtaining s i target sampling texts of the i-th class from a i , obtaining the target sampling texts of the i-th class by clustering a i can significantly improve the diversification of the sampled texts from a i , and thus significantly improve the inference ability of the subsequent trained semantic analysis model for a i corresponding label; and for r i≥r0, that is, from a i In the case of obtaining a large proportion of the sampled text, directly from a i Randomly obtain s i The sampled texts constitute the target sampled text of the i-th category, and the semantic analysis model trained later is used to analyze a i The reasoning ability of the corresponding label is not greatly affected, but it is beneficial to reduce the time for obtaining the target sample text of the i-th category and improve the efficiency of obtaining the target sample text of the i-th category.
[0062] Embodiment three: In the above embodiment 1, i ≥s i In the case of a i The clustering method starts from a i Get s i The sampled texts constitute the target sampled text of the i-th category, so as to achieve i Diversified sampling improves the subsequent trained semantic analysis model i The reasoning ability of the corresponding label; but for q i ≥s i And q i In the case of low repetition of Chinese text, i The clustering method starts from a i Get s i The effect of using the sampled texts to form the target sampled text of the i-th category is not obvious, and it will also increase the time for obtaining the target sampled text of the i-th category and reduce the efficiency of obtaining the target sampled text of the i-th category. In order to solve this problem, this embodiment further optimizes the smoothing sampling method of the text on the basis of the above-mentioned embodiment one.
[0063] Specifically, before S310, the i Get s i The target sampled texts of the i-th category are composed of the following texts: S305, from a i Randomly obtain s i The texts to be sampled constitute the discriminant sample text B of the i-th category. i .
[0064] S306, to B i Perform grouping and 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 iThe t-th group is obtained by grouping, where the value of t ranges from 1 to v, and v is the preset number of groups.
[0065] Optional, for B i The included texts are randomly grouped so that each R i,t The number of included texts is greater than or equal to floor(s i / v) and less than or equal to ceil(s) i / v), floor() is used to round down, and ceil() is used to round up.
[0066] S307, according to R i The text similarity between the included groups is obtained by B i The repetition between Chinese texts is i .
[0067] Optionally, S307 includes: S3071, get the spliced text CR i , CR i ={CR i,1 ,CR i,2 ,…,CR i,t ,…,CR i,v}, CR i,t To R i,t The text obtained by concatenating the included texts.
[0068] Preferably, R i,t The included text is concatenated from beginning to end to get CR i,t .
[0069] S3072, Get CR i The text similarity of any two texts in , and append them to the preset similarity set SH, and get SH={sh1,sh2,…,sh d ,…,sh D}, sh d CR i The text similarity between the d-th pair of texts in , where d ranges from 1 to D, and D is CR i The corresponding number of text pairs, D=v×(v-1) / 2; SH is initialized to an empty set.
[0070] In this embodiment, from CR i Choose any two texts to form a pair of texts, CR i The amount of text included is v, so CR i The corresponding number of text pairs is v×(v-1) / 2.
[0071] Those skilled in the art are aware that any method for obtaining text similarity in the prior art falls within the protection scope of the present invention.
[0072] S3073, get sim i ,sim i =sum(SH) / D, sum( ) is the sum.
[0073] Based on S3071-S3073, this embodiment can obtain B i The repetition between Chinese texts is i ,sim i The larger the value, the higher the B i The higher the repetition between Chinese texts.
[0074] S308, if sim i ≤sim0, then B i Determine the target sample text of the i-th category; sim0 is a preset similarity threshold; otherwise, enter S310.
[0075] In this embodiment, sim0 is an empirical value, and optionally, sim0=0.5.
[0076] Based on the above S305-S308, in sim i >sim0, that is, from a i Randomly obtain s i The discriminant sample text B of the i-th category is composed of the texts to be sampled i When the repetition rate of Chinese text is high, i The clustering method starts from a i Get s i The sampled texts constitute the target sampled text of the i-th category. i Randomly obtain s i The sampled texts constitute the target sampled text of the i-th category. i The clustering method to obtain the target sample text of the i-th category can significantly improve the i The diversity of the text sampled in the text analysis can significantly improve the subsequent semantic analysis model trained on a i The reasoning ability of the corresponding label; and for sim i ≤sim0, that is, from a i Randomly obtain s i The discriminant sample text B of the i-th category is composed of the texts to be sampled i If the repetition rate of Chinese text is low, directly replace B i Determining the target sample text as the i-th category is conducive to reducing the time for obtaining the target sample text of the i-th category and improving the efficiency of obtaining the target sample text of the i-th category.
[0077] Preferably, before S305, obtain s from a i The target sampling texts of the i-th category composed of s to-be-sampled texts further include: i S301, obtain the sum w of the number of to-be-sampled texts included in the top u categories with the largest number of to-be-sampled texts in A, where u is a preset category quantity threshold.
[0078] Optionally, u is an empirical value or u = f(r'×n), where r' is a preset label ratio threshold. Optionally, r' is 5%.
[0079] S302, if w / (∑ n i=1 q i )≥η, then enter S303; η is a preset ratio threshold; otherwise, enter S305.
[0080] Optionally, η is an empirical value. Optionally, η is 50%.
[0081] S303, obtain the sampling ratio r of the i-th category i , r i =s i / q i .
[0082] S304, if r i <r0, then enter S310; r0 is a preset sampling ratio threshold; otherwise, randomly obtain s i from a i to-be-sampled texts to form the target sampling texts of the i-th category.
[0083] In this embodiment, r0 is an empirical value. Optionally, r0 is 5% or 10%.
[0084] Based on S301 - S304, when w / (∑ n i=1 q i )≥η, that is, the number of texts corresponding to different labels included in A is quite different, that is, the number of texts corresponding to different labels is relatively unbalanced, S303-S304 is executed to divide the n types of texts to be sampled included in A into 2 categories based on the preset sampling ratio threshold. The first category is the class with a sampling ratio less than the preset sampling ratio threshold (corresponding to the class with a large number of texts in A), and the other category is the class with a sampling ratio greater than or equal to the preset sampling ratio threshold (corresponding to the class with a small number of texts in A); the method of judging whether to perform cluster sampling based on the sampling ratio is more efficient, and for the class with a sampling ratio greater than or equal to the preset sampling ratio threshold, since the sampling ratio is relatively large, even if the class is directly randomly sampled, it will not have much impact on the reasoning effect of the label corresponding to the class by the later trained semantic analysis model. And in w / (∑ n i=1 q i )<η, that is, the difference in the number of texts corresponding to different labels included in A is small, that is, when the number of texts corresponding to different labels is relatively balanced, the difference in sampling ratios of various categories is relatively small, and S305-S308 are executed without obtaining a preset sampling ratio threshold, but instead i The repetition degree is judged. If the repetition degree is high, cluster sampling is performed on the class to improve the reasoning effect of the later trained semantic analysis model on the label corresponding to the class; the method of judging whether to perform cluster sampling based on the repetition degree in this embodiment can improve the reasoning effect of the later trained semantic analysis model on the labels corresponding to each class.
[0085] Embodiment 4: This embodiment provides a text smoothing sampling device, including: The first acquisition module is used to acquire a text set A to be sampled, where A includes several types of text to be sampled, the labels of the same type of text to be sampled are the same, and the labels of different types of text to be sampled are different.
[0086] The first traversal module is used to obtain the number of samples 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 the 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 number of categories of the text to be sampled; q i is the number of texts to be sampled included in the i-th category of texts to be sampled.
[0087] Optionally, x is an empirical value. Preferably, x=f( lg((max(Q)) 0.5 )) or x=f( l g((∑ n i=1 q i ) 0.5 )), Q is the sampling number sequence of A, Q=(q1,q2,…,q i ,…,q n ), max() is the maximum value function, l g is the logarithm to 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 )), the quantity distribution of texts corresponding to different labels in the sampled text is basically consistent with the quantity distribution of texts corresponding to different labels in A.
[0088] The first judgment module is used if q i ≥s i , then from the i-th type of text to be sampled a i Get s i The sampled texts constitute the target sampled text of the i-th category; otherwise, the i-th category sampled text a i Determine the target sample text for the i-th category.
[0089] Preferably, the first judgment module includes: Clustering module, 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 and obtain the clustering result G i , G i Includes m clusters, m is the number of a i The number of clusters obtained by clustering.
[0090] The second acquisition module is used to obtain G i The number of texts to be sampled in the smallest cluster s i,min .
[0091] The second judgment module is used if s i,min ≥f(s i / m), then enter the second traversal module.
[0092] The second traversal module is used to traverse G i , from each g i,j Get f(si / m) texts to be sampled constitute the initial sampled text of the i-th category; g i,j For a i The jth cluster obtained by clustering, the value of j ranges from 1 to m.
[0093] The third judgment module is used to determine if m×f(s i / m)=s i , then the initial sampled text of the i-th category is determined as the target sampled text of the i-th category.
[0094] Embodiment five: 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, the following steps are implemented: S100, obtaining a text set A to be sampled, where A includes several types of texts to be sampled, the texts to be sampled of the same type have the same label, and the texts to be sampled of different types have different labels.
[0095] S200, obtain the number of samples 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 the 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 number of categories of the text to be sampled; q i is the number of texts to be sampled included in the i-th category of texts to be sampled.
[0096] S300, if q i ≥s i , then from the i-th type of text to be sampled a i Get s i The sampled texts constitute the target sampled text of the i-th category; otherwise, the i-th category sampled text a i Determine the target sample text for the i-th category.
[0097] Embodiment six: This embodiment provides a computer-readable storage medium, on which a computer program is stored. When the computer program is executed by a processor, the following steps are implemented: S100, obtaining a text set A to be sampled, where A includes several types of texts to be sampled, the texts to be sampled of the same type have the same label, and the texts to be sampled of different types have different labels.
[0098] S200, obtain the number of samples s of the i-th categoryi ,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 a rounding function; the value range of i is 1 to n, n is the number of categories of the text to be sampled; q i is the number of texts to be sampled included in the i-th category of texts to be sampled.
[0099] S300, if q i ≥s i , then from the i-th type of text to be sampled a i Get s i The sampled texts constitute the target sampled text of the i-th category; otherwise, the i-th category sampled text a i Determine the target sample text for the i-th category.
[0100] Embodiment seven: Each text in the target sampled text obtained in the first embodiment has a corresponding labeled label, but the labeled label may be wrong, that is, the label annotated on the text does not match the text. In order to clean the target sampled text, the text smoothing sampling method of this embodiment also includes the following steps: L100, get the text to be cleaned cle, cle=(cle1,cle2,…,cle ra ,…,cle to ),cle ra is the rath text to be cleaned, the value range of ra is 1 to to, and to is the number of texts to be cleaned.
[0101] In this embodiment, the target sample text is determined as tex, and to is the number of the target sample text.
[0102] L200, traverse cle, get cle ra Corresponding prompt word pro ra , pro ra Includes thought chain example text mod ra and the text to be inferred ans ra , mod ra =(mod ra,1 ,mod ra,2 ,…,mod ra,b ,…,mod ra,num ), mod ra,b For pro raIncludes the b-th thought chain example text, where b ranges from 1 to num, and num is cle ra The number of corresponding thought chain example texts; each mod ra,b Includes a corresponding target text tar ra,b , a corresponding label 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's judgment mark sig ra,b and sig ra,b Corresponding reasoning text; ans ra Including cle ra andcle ra Tags l ab ra .
[0103] In this embodiment, if the value of num is small, that is, the number of thought chain example texts included in the prompt words input into the trained large language model is small, it is not conducive to the trained large language model to comprehensively learn the thinking of judging whether the label is correct, affecting the accuracy of the judgment result; if the value of num is large, that is, the number of thought chain example texts included in the prompt words input into the trained large language model is large, the trained large language model learns the thinking of judging whether the label is correct. It takes a long time, which is not conducive to quickly giving a judgment result; as an optional specific implementation method, num is an empirical value, optional, 2≤num≤10.
[0104] As a preferred embodiment, each l ab ra,b and l ab ra is a sub-tag under the same parent tag, so pro ra When used as a prompt word for a trained large language model, it is helpful for the trained large language model to learn the thinking that is more relevant to the text to be inferred, and further improve the accuracy of the output results of the trained large language model. For example, num=4, l ab ra For marriage and family disputes, l ab ra,1 For contract disputes, l ab ra,2 Disputes over compensation for property damage, l ab ra,3 For maintenance disputes, l ab ra,4 For marriage and family disputes,l ab ra , l ab ra,1 , l ab ra,2 , l ab ra,3 and l ab ra,4 They are all secondary tags. l ab ra , l ab ra,1 , l ab ra,2 , l ab ra,3 and l ab ra,4 The parent tags (i.e. first-level tags) of are all disputes. l ab ra , l ab ra,1 , l ab ra,2 , l ab ra,3 and l ab ra,4 All are sub-tags of the dispute tag.
[0105] As a specific implementation, tar ra,1 For boyfriends and girlfriends who have disputes over emotional issues, l ab ra,1 In pursuit of unsuccessful entanglement, sig ra,1 For error, sig ra,b The corresponding reasoning text is: The label belongs to the dispute problem caused by the continuous entanglement when one of the men and women pursues the other party unsuccessfully, but the text mentions boyfriend and girlfriend, which conflicts with the unsuccessful pursuit. Therefore, the label is wrong.
[0106] L300, pro ra Input the trained large language model to be judged by the trained large language model l ab ra Is it cle ra .
[0107] Those skilled in the art are aware that any large language model in the prior art falls within the protection scope of the present invention.
[0108] In this embodiment, ra It is a prompt word based on the thought chain. In this embodiment, pro raAs the input of the trained large language model, it is helpful for the trained large language model to learn the thinking of judging whether the annotated label is the label of the text, improve the accuracy of the output result of the trained large language model, and then improve the accuracy of cleaning.
[0109] L400, based on the trained large language model l ab ra Is it cle ra The result of the label judgment determines whether to cle ra Wash it off.
[0110] This embodiment intends to use a large language model to realize the judgment of whether the label of the text to be cleaned is wrong. Specifically, for each text to be cleaned, first obtain its corresponding prompt word, which includes num thought chain example texts and the text to be inferred. The num thought chain example texts are used to enable the trained large language model to better learn the thinking of judging whether the label is the label of the text. Each thought chain text includes a target text, a label, a judgment mark of whether the label is the target text, and the reason for making the judgment. Based on the num thought chain example texts, the trained large language model can learn the thinking of judging whether the label is the label corresponding to the text, and has the ability to judge. l ab ra Is it cle ra The semantic analysis capability of the label; thus, by inputting the prompt word corresponding to the text to be judged into the trained large language model, it is possible to automatically judge whether the label of the text is correct, which solves the problem of manual judgment of whether the label of the text is correct in the prior art, which occupies a lot of manual resources.
[0111] As a preferred specific implementation, L400 includes: if the trained large language model is l ab ra Is it cle ra If the judgment result of the tag is yes, enter L410.
[0112] L410, obtain the accuracy rate tpr of the trained large language model for the judgment result of yes.
[0113] In this embodiment, if the trained large language model l ab ra Is it cle ra The result of the label is yes, indicating that the trained large language model judges l ab ra for cle ra .
[0114] Optionally, the accuracy rate of the trained large language model for a positive judgment result is obtained based on the test text. When the accuracy rate (tpr) of the trained large language model for a positive judgment result is 90% and the trained large language model's l ab ra judgment result for whether it is the label of cle ra is positive, it means that l ab ra the probability of the label being cle ra is 90%; when the accuracy rate (tpr) of the trained large language model for a positive judgment result is 78% and the trained large language model's l ab ra judgment result for whether it is the label of cle ra is positive, it means that l ab ra the probability of the label being cle ra is 78%.
[0115] L420, if tpr ≥ tf, then it is judged not to wash away cle ra ; tf is a preset accuracy threshold.
[0116] In this embodiment, tf is an empirical value. Optionally, tf is 90% or 95%.
[0117] Based on L410 - L420, in this embodiment, when the accuracy rate of the trained large language model for a positive judgment result is relatively high, the judgment result of the trained large language model is directly used as the standard. Thus, the text with a positive judgment result output by the trained large language model corresponding to cle can be retained, realizing the rapid cleaning of these texts.
[0118] In this embodiment, L420 further includes: if tpr < tf, then proceed to L421.
[0119] L421, obtain the qua - time judgment results of the trained large language model for l ab ra whether it is the label of cle ra , where qua is a preset number of repeated inferences, qua is an odd number and qua ≥ 3.
[0120] L422, if there are more than or equal to (qua + 1) / 2 negative judgment results among the qua - time judgment results, then it is judged to wash away cle ra ; otherwise, it is judged not to wash away cle ra .
[0121] 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.
[0122] 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.
[0123] L430, obtain the false positive rate fpr of the trained large language model for a judgment result of "no".
[0124] 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 .
[0125] 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 with a probability of 68%; when the false 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 with a probability of 92%.
[0126] L440, if fpr < tf, then enter L450; otherwise, clean cle ra off.
[0127] In this embodiment, tf is an empirical value, and optionally, tf is 90% or 95%.
[0128] L450, obtain the trained large language model pair l ab ra Is it cle ra qua judgment results of the label, qua is the preset number of repeated reasoning, qua is an odd number and qua≥3.
[0129] In this embodiment, qua is an empirical value, and optionally, qua is 3 or 5.
[0130] L460, if there is a negative result greater than (qua+1) / 2 times among the qua judgment results, then the judgment will be cle ra Clean it; otherwise, judge not to clean ra Wash it off.
[0131] In this embodiment, if there are greater than or equal to (qua+1) / 2 negative judgment results among qua judgment results, it means that most of the judgment results among the qua judgment results are negative; if there are less than (qua+1) / 2 negative judgment results among the qua judgment results, it means that most of the judgment results among the qua judgment results are positive.
[0132] Based on L430-L460, when the accuracy of the trained large language model in judging the result of "no" is low, this embodiment does not directly take the judgment result of the trained large language model as the standard, but reuses the trained large language model to make multiple judgments on the prompt words corresponding to the text, and takes the judgment result with the largest number of occurrences in the multiple judgments as the final judgment result. Therefore, this embodiment can also recall the text from the text whose corresponding preliminary judgment result is "no", reduce the judgment deviation of the trained large language model triggered by the illusion light factor, and improve the accuracy of cleaning.
[0133] Embodiment eight: If the prompt words used to input into the trained large language model in the seventh embodiment are constructed manually, there is still a problem of occupying a lot of human resources. In order to further reduce the problem of occupying human resources, this embodiment, based on the seventh embodiment, also includes automatically obtaining pro ra process; specific, pro ra The acquisition process includes: L210, will cle ra Input to the first trained model to obtain cle ra First-level label l ab 1 ra; The trained first model is used to obtain the primary label of the input text, and the accuracy of the trained first model in obtaining the primary label of the input text is greater than or equal to tf, where tf is a preset accuracy threshold.
[0134] In this embodiment, the accuracy of the first-level label of the text inferred by the trained first model is relatively high. ra The output of the first model trained with ra First-level label l ab 1 ra .
[0135] 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 rough 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 second-level label of the text inferred by the trained first model is low (i.e., less than tf). Therefore, this embodiment only uses the trained first model to obtain the first-level label of the text, and does not use the trained first model to obtain the second-level label of the text.
[0136] In this embodiment, the first model is a neural network model, and a supervised training method is used when training the first model. Optionally, the process of training the first model includes: obtaining a training text set, the training text set includes a plurality of training texts; obtaining a training label set, the training label set includes a primary label corresponding to each training text; training the first model according to the training text set and the training label set to obtain a trained first model.
[0137] L220, according to l ab 1 ra Match in the preset thinking chain sample text library bas to obtain l ab 1 ra Matching num thought chain example text mod ra ; bas=(bas1,bas2,…,bas ce ,…,bas he ),bas ce The sub-library of example texts of the thinking chain corresponding to the ceth first-level label corresponding to cle, bas ce =(bas ce,1 ,bas ce,2 ,…,bas ce,me ,…,bas ce,te ),bas ce,meis the example text of the thinking chain corresponding to the meth second-level label included in the ceth first-level label corresponding to cle, the value range of me is 1 to te, te is the number of second-level labels included in the ceth first-level label corresponding to cle, the value range of ce is 1 to he, he is the number of first-level labels corresponding to cle; num is the value of cle ra The number of corresponding thought chain example texts.
[0138] In this embodiment, bas ce,me Includes several thought chain sample texts, bas ce,me The corresponding labels in each thought chain example text are the meth second-level labels included in the ceth first-level labels of cle, but bas ce,me The corresponding judgment marks in the included different thought chain example texts may be the same or different, bas ce,me The corresponding judgment mark in the included thinking chain example text is used to mark whether the corresponding label in the thinking chain example text is the label of the corresponding target text in the thinking chain example text. For example, if bas ce,me The corresponding judgment mark in the included thinking chain example text is correct or yes, then the corresponding label in the thinking chain example text is the label of the corresponding target text in the thinking chain example text; if bas ce,me If the corresponding judgment mark in the included thinking chain example text is wrong or no, it indicates that the corresponding label in the thinking chain example text is not the label of the corresponding target text in the thinking chain example text.
[0139] Optionally, the L220 includes: L221, if bas ce and l ab 1 ra If matched, enter L222.
[0140] In this embodiment, if bas ce The corresponding first-level label and l ab 1 ra If they are the same, then the bas ce and l ab 1 ra Match; otherwise, judge bas ce and l ab 1 ra No match.
[0141] L222, if te=num, then from each bas ce,me Get 1 thought chain example text build mod in ra; If te > num, enter L223; if te < num, enter L225.
[0142] L223, obtain the priority of each bas ce,me .
[0143] 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 .
[0144] 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.
[0145] L225, obtain 1 example text of the thought chain from each bas ce,me to construct the initial text.
[0146] L226, obtain the text deviation quantity Δq, Δq = num - te; 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 initial text after appending as mod ra ; The remaining example texts of bas ce are the example texts of the thought chain in bas ce except the initial text.
[0147] Based on L221 - L227, this embodiment obtains num example texts of the thought chain from the bas l matched with 1 ra ab ce to realize the automatic construction of mod ra , saving the process of manually constructing mod ra ; Moreover, this embodiment obtains example texts of the thought chain with different secondary labels from the bas l matched with 1 ra ab ce as much as possible, so that mod ra includes example texts of the thought chain corresponding to multiple secondary labels, which is beneficial to later use of the prompt word pro ra including mod raWhen input into the trained large language model, the large language model can more comprehensively learn the thinking of judging whether the secondary label is the secondary label of the text, so that the trained large language model can give a more accurate judgment result and improve the accuracy of cleaning.
[0148] L230, according to mod ra cle ra andcle ra Secondary tags l ab 2 ra Build cle ra Corresponding prompt word pro ra .
[0149] In this embodiment, cle ra Secondary tags l ab 2 ra That is, cle ra Tags l ab ra .
[0150] Based on L210-L230, this embodiment can automatically build pro ra , which eliminates the process of manually constructing prompt words, improves the efficiency of constructing prompt words, and reduces the manual resources occupied in the text cleaning process.
[0151] As a preferred specific implementation, the process of obtaining num includes: L201, get the preset thinking chain sample text library bas l ab 1 ra Matching bas ce Number of thought chain example texts included pn ra .
[0152] L202, get 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 The maximum number of preset thought chain sample texts, num max =tok max / (min(tok avg,1 ,tok avg,2 ,…,tok avg,ce ,…,tok avg,he)), tok max is the total number of characters in the preset thought chain sample text, tok avg,ce For bas ce The average number of characters in the example text of the thought chain included; num min The minimum number of preset thought chain sample texts, num min =tok max / (max(tok avg,1 ,tok avg,2 ,…,tok avg,ce ,…,tok avg,he )); num avg is the average number of preset thought chain sample texts, num avg =tok max / (avg(tok avg,1 ,tok avg,2 ,…,tok avg,ce ,…,tok avg,he )); pn avg is the preset threshold value of the number of thought chain example texts; max() is the maximum value, min() is the minimum value, avg() is the average value, and f() is the integer.
[0153] In this embodiment, the average number of example thinking chain texts included in each example thinking chain text sub-library in bas is determined as the preset number threshold of example thinking chain texts.
[0154] L203, if cn ra Greater than or equal to l ab 1 ra The number of secondary tags included, then cn ra Determined as 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 identified as num.
[0155] In this embodiment, if cn ra Less than l ab 1 ra The number of secondary tags included is prioritized from l ab 1 ra Matching bas ce Select or reconstruct a thought chain example text composition mod containing a small number of wordsra To enable the mod ra The number of characters included does not exceed tok max That's it.
[0156] Based on L201-L203, this embodiment can achieve the purpose of setting different thinking chain example texts according to the text to be cleaned. Specifically, considering the character number limit corresponding to the prompt word, the maximum number, minimum number and average number of thinking chain example texts are used as reference factors. It can also set a larger number of thinking chain example texts when the thinking chain example texts corresponding to the first-level label of the text to be cleaned include a large number of thinking chain example texts, so as to improve the diversity of the set thinking chain example texts; considering the requirements of comprehensive learning and reasoning of the trained large language model, the number of set thinking chain example texts meets the requirement of being greater than or equal to the number of second-level labels included in the first-level label of the text to be cleaned, so that the trained large language model can learn comprehensive label judgment thinking, thereby improving the accuracy of judgment.
[0157] Embodiment nine: In the first embodiment, the label of the target sampled text may be wrong. In order to obtain a correct and more comprehensive label for each text in the target sampled text, the text smoothing sampling method of this embodiment further includes: F100, get the text tex of the label to be obtained, tex=(tex1,tex2,…,tex ac ,…,tex ae ),tex ac is the text of the acth label to be obtained, the value range of ac is 1 to ae, ae is the number of texts of the label to be obtained; each tex ac Corresponding to several original labels.
[0158] In this embodiment, the target sample text is determined as tex, and ae is the number of the target sample text.
[0159] In this embodiment, each tex ac The number of corresponding original labels is greater than or equal to 1, and the original label may be tex ac The corresponding correct label may also be tex ac The corresponding wrong label, and the proportion of correct labels in the original labels of all texts corresponding to tex is greater than the proportion of wrong labels in the original labels; as a specific implementation method, each tex ac The corresponding original labels are manually annotated labels.
[0160] F200, according to the text of the first label to be obtained in tex 1 Get the trained first label inference model mode1, mode1=(mode1,1 ,mode 1,2 ,…,mode 1,av ,…,mode 1,ax ), mode 1,av According to tex 1 Get the avth trained first label inference model, where av ranges from 1 to ax, and ax is the value of tex 1 The number of trained first-label inference models obtained; ax ≥ 2.
[0161] In this embodiment, the text to be obtained in the tex tag is divided into two parts, one of which is tex 1 , the other part is tex 2 ; optional, tex 1 The number of texts to be labeled in is 1 / 2 of the number of texts to be labeled in tex. 2 The number of texts to be labeled in is also 1 / 2 of the number of texts to be labeled in tex.
[0162] In this embodiment, each mode 1,av The training samples come from tex 1 , different modes 1,av There are differences in the corresponding training samples; as a specific implementation, F200 includes: F210, tex 1 Divide and obtain the divided text subset zc1, zc1=(zc 1,1 ,zc 1,2 ,…,zc 1,av ,…,zc 1,ax ), zc 1,av To tex 1 The axth text subset obtained by partitioning.
[0163] Optionally, add tex 1 Divide into ax text subsets.
[0164] F220, initialize the model variable ha to 1.
[0165] F230, select from zc1 except zc 1,ha The ax-1 text subsets other than are taken as the hath training samples.
[0166] F240, train the hath first label inference model using the hath training sample and the corresponding original label, and obtain the hath trained first label inference model mode 1,ha .
[0167] F250, if ha < ax, then ha = ha + 1, repeat F230 - F240 until ha = ax.
[0168] 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 axth trained first label inference model mode 1,ax ; thus, ax trained first label inference models can be obtained after executing F210 - F250.
[0169] F300, obtain the text tex of the second label to be obtained in tex according to mode1 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 erth 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 = (qa 2 er = (qa 2 er,1 , qa 2 er,2 , …, qa 2 er,av , …, qa 2 er,ax ), qa 2 er,av is the inference label of the text of the erth label to be obtained according to mode 1,av ; tex 2 is the text of the labels to be obtained in tex except tex 2 ; each qa 1 includes several inference labels. 2 er,av In this embodiment, tex
[0170] will be 2The text of the erth label to be obtained in is used as the input of the first trained first label inference model, and mode 1,1 Inferred tex 2 The inference label qa of the erth text to be labeled 2 er,1 ; 2 The text of the erth label to be obtained is used as the input of the second trained first label inference model, and mode 1,2 Inferred tex 2 The inference label qa of the erth text to be labeled 2 er,2 ; And so on, tex 2 The text of the erth label to be obtained is used as the input of the axth trained first label inference model, and mode can be obtained. 1,ax Inferred tex 2 The inference label qa of the erth text to be labeled 2 er,ax .
[0171] F400, traverse qa 2 , for qa 2 er Filter and get the filtered inference label 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 bvth inference label remaining after screening, the value range of bv is 1 to bx, bx is the value of qa 2 er The number of inference labels remaining after filtering.
[0172] In this embodiment, qa 2 er The purpose of screening is to 2 er The wrong labels are filtered out and the correct labels are retained.
[0173] As a first preferred specific implementation, F400 includes: F410, get qa 2 Each inference label that appears in qa 2 The number of times it appears in .
[0174] F420, if qa 2 A certain inference label appears in qa 2 If the number of occurrences in is greater than or equal to the preset threshold, qa 2 The inference label that appears in is determined as the inference label retained after screening; otherwise, qa 2 The inference label that appears in is determined to be the inference label that is filtered out after filtering.
[0175] In this embodiment, qa 2 The inference tags whose occurrence times in the list are greater than or equal to the preset threshold are judged as tex 2 The correct label of the text to be labeled in er is qa 2 The inference tags whose occurrence times are less than the preset threshold are judged as tex 2 The wrong label of the text of the erth label to be obtained in . Optionally, the preset number of times threshold is ax / 2.
[0176] Based on F410-F420, this embodiment realizes the 2 er Screening, since this embodiment will qa 2 The inference labels that appear more often in qa are judged as correct labels, while 2 The inference labels that appear more often in the above are consistent inference results of a large number of trained first label inference models. Therefore, the nqa obtained based on F410-F420 in this embodiment is 2 er The label is tex 2 The probability of the correct label of the erth text to be labeled is higher, which improves the accuracy of the label of the text finally obtained.
[0177] As a second preferred specific implementation, F400 includes: F401, get qa 2 er The inference tag wqa appears in 2 er , wqa 2 er =(wqa 2 er,1 ,wqa 2 er,2 ,…,wqa 2 er,cv ,…,wqa 2er,cx ), wqa 2 er,cv For QA 2 er The cvth inference label appears in , the value range of cv is 1 to cx, and cx is qa 2 er The number of inference labels that appear in .
[0178] In this embodiment, different wqa 2 er,cv 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 labels included.
[0179] F402, traverse wqa 2 er , using the trained large language model to judge wqa 2 er,cv Is it tex 2 The label of the text of the erth label to be obtained.
[0180] Those skilled in the art know that any large language model in the prior art falls within the protection scope of the present invention.
[0181] Preferably, the cue words based on the thought chain make the trained large language model judge wqa 2 er,cv Is it tex 2 The label of the erth text to be labeled is included in the prompt word, and several example texts of the thought chain related to the content to be judged are included. Therefore, the trained large language model can be used to better learn the thinking of judging whether the label is correct and improve the accuracy of the judgment result.
[0182] F403, if yes, then wqa 2 er,cv Append to the preset erth tag sequence; otherwise, wqa is not appended. 2 er,cv Append to the preset erth label sequence; the preset erth label sequence is initialized to an empty sequence.
[0183] F404, determine the preset erth label sequence as nqa 2 er .
[0184] Based on F401-F404, this embodiment implements qa based on the trained large language model2 er The screening of NQA is improved through the trained large language model. 2 er The accuracy of the inference labels in .
[0185] F500, nqa 2 er Determine as tex 2 The label of the erth text to be judged.
[0186] In this embodiment, each text in the text tex to be labeled corresponds to an original label, and these original labels may contain erroneous labels or incomplete labels. In this embodiment, a part of the text tex in tex is used. 1 The corresponding original labels can obtain multiple trained first label inference models, each of which has the ability to infer labels. This embodiment obtains another part of the text tex in tex according to the multiple trained first label inference models. 2 inference labels; since the present embodiment utilizes multiple trained first label inference models to obtain inference labels for texts, different trained first label inference models have different semantic analysis capabilities, and the corresponding inference labels for the texts obtained when performing label inference on the same text may also be different, the present embodiment uses the inference labels obtained by multiple trained first label inference models for the same text as the inference labels for the text, so the inference labels for the texts obtained by the present embodiment are more comprehensive; moreover, the present embodiment also screens the inference labels obtained according to the multiple trained first label inference models to select the correct labels from the more comprehensive inference labels; thus, the present embodiment achieves the purpose of obtaining correct and more comprehensive labels for the texts.
[0187] As an optional specific implementation, ax is an empirical value, for example, 3≤ax≤5.
[0188] As a preferred specific implementation, the method for obtaining ax includes: F201, get tex 1 The number of texts to be included in the tags to be obtained 1 .
[0189] F202, get the initial number of divisions hua0, hua0=floor(shu 1 / shu0), shu0 is the preset text quantity threshold, and floor() is rounding down.
[0190] 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 into a model with an accuracy greater than or equal to a preset accuracy threshold.
[0191] F203, obtain the first division quantity hua1, hua1=min(max(hua0,hua min ),hua max ), min() is the minimum value, max() is the maximum value, min is the preset minimum number of divisions, max The preset maximum number of divisions.
[0192] In this embodiment, hua min and hua max All are experience values.
[0193] F204, from tex 1 The text of the to-be-acquired label with a ratio of (hua1-1) / hua1 and the corresponding original label are used to train the test label inference model to obtain a trained test label inference model.
[0194] F205, if the accuracy of the trained test label inference model is greater than or equal to a preset accuracy threshold, hua1 is determined as ax.
[0195] In this embodiment, if the accuracy of the trained test label inference model is less than the preset accuracy threshold, 1 The text of the to-be-acquired label with the proportion of hua1 / (hua1+1) and the corresponding original label are used to train the test label inference model to obtain a trained test label inference model. If the accuracy of the trained test label inference model is greater than or equal to the preset accuracy threshold, hua1+1 is determined as ax; otherwise, tex 1 The text of the to-be-acquired label with a proportion of (hua1+1) / (hua1+2) and the corresponding original label are used to train the test label inference model to obtain a trained test label inference model. If the accuracy of the trained test label inference model is greater than or equal to the preset accuracy threshold, hua1+2 is determined as ax; otherwise, tex 1 The text of the to-be-obtained label with a proportion of (hua1+2) / (hua1+3) and the corresponding original label are used to train the test label inference model to obtain a trained test label inference model; and so on, until the accuracy of the trained test label inference model is greater than or equal to the preset accuracy threshold, the corresponding number of divisions is determined as ax.
[0196] Based on the ax obtained from F201-F205, tex 1 Divide it so that tex 1 The number of texts corresponding to the proportion of (hua1-1) / hua1 is relatively large, which improves the subsequent tex-based 1 The accuracy of the first label inference model trained on text with a ratio of (hua1-1) / hua1 is conducive to improving the accuracy of the final text label.
[0197] As an optional specific implementation, after F500, the method for obtaining the text label further includes: F600, traverse tex 2 The original label corresponding to the text of the erth label to be obtained in tex 2 The original label corresponding to the text of the erth label to be obtained in nqa 2 er If it exists in 2 The original label corresponding to the text of the erth label to be obtained is correct; otherwise, judge tex 2 The original label corresponding to the text of the erth label to be obtained is wrong.
[0198] Therefore, this embodiment is based on tex 2 The label nqa corresponding to the text of the erth label to be obtained 2 er Implemented the tex 2 Determine the original label corresponding to the text of the erth label to be obtained.
[0199] In this embodiment, tex is obtained 1 The method of obtaining the label of each text to be labeled is the same as the above method of obtaining the text 2 The method of obtaining the label of each text to be labeled is similar, except that: 1 In the process of labeling each text to be labeled, according to the tex 2 Get the trained second label inference model mode2, which includes several 2 Obtain the trained second label inference model; obtain tex according to mode2 1 The inference label qa of the text to be labeled in 1 ,qa 1 Includes all tex obtained by the trained second label inference model 1 The inference label of each text to be labeled; traverse qa 1 , for qa 1 erFilter and get the filtered inference label nqa 1 er ; will nqa 1 er Determine as tex 1 The label of the erth text to be judged in . Get tex 1 The specific process of obtaining the label of each text to be labeled is the same as the above-mentioned process of obtaining the text label of the tex 2 The specific process of labeling each text to be labeled is similar and will not be repeated here.
[0200] Embodiment ten: In order to obtain a named entity recognition model capable of performing entity annotation of multiple preset types on the target sampled text, the text smoothing sampling method of this embodiment further includes the following steps: D100, obtain the training text set data of the trained named entity recognition model, data={data1,data2,…,data se ,…,data st}, data se is the se-th training text set of the trained named entity recognition model, data se The invention comprises a plurality of training texts, wherein the value range of se is 1 to st, and st is the number of training text sets of the trained named entity recognition model; the trained named entity recognition model is a model obtained by training using data, and the trained named entity recognition model is used to recognize entities of a preset type ty in the input text and mark the corresponding labels; ty=(ty1, ty2, ..., ty mt ,…,ty ht ),ty mt It is the mtth preset type, the value range of mt is 1 to ht, and ht is the number of preset types.
[0201] In this embodiment, the trained named entity recognition model is obtained by training using the st training text sets included in the data. The purpose of training the named entity recognition model using the st training text sets included in the data is to enable the trained named entity recognition model to have the function of recognizing ht preset types of entities.
[0202] In this embodiment, when the named entity recognition model is trained using the st training text sets included in data, at least one entity of a preset type is annotated when each training text set is annotated, and entities other than ht entities of the preset types are not annotated, and each entity of the ht preset types has been annotated by at least one training text set. Thus, the trained named entity recognition model has and only has the function of recognizing entities of ht preset types.
[0203] D200, traverse data, if using data se When training the named entity recognition model, se The entity of the mtth preset type is labeled, then the data se The proportion of positive samples of the mt-th preset type of entity in data is determined as data se The mtth weight qz se,mt ; Otherwise, set qz se,mt is 0.
[0204] In this embodiment, when the named entity recognition model is trained using the st training text sets included in data, not all entities of ht preset types are annotated when each training text set is annotated. For example, st=2, ht=4, when the named entity recognition model is trained using the first training text set and the second training text set, only entities of the first preset type and the second preset type are annotated when the first training text set is annotated, and only entities of the second preset type, the third preset type, and the fourth preset type are annotated when the second training text set is annotated.
[0205] In this embodiment, data se The proportion of positive samples of the mt-th preset type of entity in data is se The number of entities marked as entities of the mtth preset type in data se The ratio of the number of entities in se When training the named entity recognition model, se The entity of the mtth preset type is labeled, then the data se The value of the positive sample ratio of the mt-th preset type of entity in is assigned to qz se,mt ; If you use data se When training the named entity recognition model, there is no data se To label the entity of the mtth preset type, then qz se,mt Set to 0.
[0206] D300, obtain the positive sample proportion cb of ht preset types of entities in the test text set, cb=(cb1,cb2,…,cb mt ,…,cb ht ), cb mt is the proportion of positive samples of the mt-th preset type of entity in the test text set.
[0207] In this embodiment, the positive sample ratio of the mt-th preset type of entity in the test text set is the ratio of the number of entities in the test text set that are marked as entities of the mt-th preset type to the number of entities in the test text set.
[0208] In this embodiment, the proportion of positive samples of the mt-th preset type of entity in the test text set can represent the proportion of positive samples of the mt-th preset type of entity in the text set to be subsequently recognized by the trained named entity recognition (for example, the target sampling text). Optionally, the test text set is a text extracted from the text set to be subsequently recognized by the trained named entity recognition, and the ht preset types of entities in the test text set are annotated by manual annotation methods, and the positive sample proportions of the ht preset types of entities are obtained.
[0209] D400, obtain the positive sample ratio zb of ht preset types of entities in the newly added text set, zb=(zb1,zb2,…,zb mt ,…,zb ht ), zb mt It is the proportion of positive samples of the mt-th preset type of entity in the newly added text set.
[0210] In this embodiment, the newly added text set is a text obtained in order to enable the trained text set to have the function of identifying entities of the newly added preset type, and the positive sample ratio of the mt-th preset type entity in the newly added text set is the ratio of the number of entities marked as entities of the mt-th preset type in the newly added text set to the number of entities in the newly added text set. As an optional specific implementation, D400 includes: D410, obtaining a preset proportion of text from the newly added text set to form a first extracted text set cq.
[0211] Optionally, a random extraction method is used to obtain a preset proportion of texts from the newly added text set to form a first extracted text set cq, where the preset proportion is an empirical value.
[0212] D420, using the trained named entity recognition model to perform ht preset types of entity recognition on each text in cq, and obtain labeling results of ht preset types of entities corresponding to each text in cq.
[0213] In this embodiment, each text in cq is used as the input of the trained named entity recognition model to obtain the corresponding labeling results of ht preset types of entities.
[0214] D430, according to the annotation result of each text in cq corresponding to the entity of the mt-th preset type, it is determined as zb mt .
[0215] In this embodiment, zb mt =∑fs fe=1 en fe,mt / (∑ fs fe=1 q fe ),zh fe,mt is the number of entities annotated as entities of the mtth preset type in the feth text in cq, qh fe It is the number of entities included in the fe-th text in cq. The value range of fe is 1 to fs, and fs is the number of texts included in cq.
[0216] D500, according to qz se,mt、 cb and zb determine the optimal amount of text to be obtained from the newly added text set for training the trained named entity recognition model.
[0217] The trained named entity recognition model in this embodiment is obtained by training based on the training text set data, and it already has the function of identifying ht preset types of entities; the newly added text set is the text obtained in this embodiment in order to enable the trained text set to have the function of identifying newly added preset types of entities in addition to the above-mentioned ht preset types. When the trained named entity recognition model is retrained using the newly added text set, the number of texts selected from the newly added text set will not only affect the recognition ability of the retrained named entity recognition model for the newly added preset types of entities, but also affect the recognition ability of the retrained named entity recognition model for the above-mentioned ht preset types of entities; this embodiment selects the named entity recognition model based on the positive sample ratio of ht preset types of entities in the test text set, the positive sample ratio of ht preset types of entities in the newly added text set zb and each training text in data. This set corresponds to the weight of each preset type to determine the optimal number of texts to be obtained from the newly added text set for training the trained named entity recognition model, wherein the proportion of positive samples of ht preset types of entities in the newly added text set determines the degree of influence of using the newly added text set to train the trained named entity recognition model on the recognition accuracy of the original ht preset types of entities, and the proportion of positive samples of ht preset types of entities in the test text set and the weight of each training text set corresponding to each preset type in the data reflect the recognition accuracy of the trained named entity recognition model for the original ht preset types of entities. Therefore, this embodiment can achieve the purpose of taking into account the recognition accuracy of the named entity recognition model after re-training for the original ht preset types of entities and the recognition accuracy of the newly added preset types of entities.
[0218] As a preferred embodiment, D500 includes: D510, get the loss dif of the newly added text, dif=(∑ ht mt=1 |cbmt -((∑ st se=1 qz se,mt ×mu se )+zb mt ×zq) / (su se + zq)|)+ke / zq,mu se For data se The amount of text included, su se is the corresponding qz in data se,mt The sum of the number of texts included in the training text set that is not 0; ke is a preset adjustment coefficient, ke>0, and zq is the number of texts to be obtained from the newly added text set for training the trained named entity recognition model.
[0219] In this embodiment, ke is an empirical value, optional, 0 <ke<1。
[0220] D520, determining the value of zq when dif takes the minimum value as the optimal number of texts obtained from the newly added text set for training the trained named entity recognition model.
[0221] Based on the above preferred specific implementation manner, the loss of newly added texts corresponding to the optimal number of texts obtained is minimal. Obtaining texts from the newly added text set according to the optimal number of texts as training samples for the trained named entity recognition model can make the proportion of positive samples of entities of each preset type used for the named entity recognition model closer to the proportion of positive samples of entities of the corresponding preset type in the test sample, so that the named entity recognition model trained with the texts of the optimal number of texts in the newly added text set has a higher recognition accuracy rate for entities of the original preset type; obtaining texts from the newly added text set according to the optimal number of texts as training samples for the trained named entity recognition model can also make the number of texts obtained from the newly added text set larger, so that the named entity recognition model trained with the texts of the optimal number of texts in the newly added text set has a higher recognition accuracy rate for entities of the newly added preset type; therefore, the optimal number of texts obtained based on this preferred specific implementation manner can achieve the purpose of taking into account the recognition accuracy rate of the named entity recognition model for both entities of the original preset type and entities of the newly added preset type.
[0222] As an optional specific implementation, after D500, when the computer readable instructions are executed by the processor, the following steps are further implemented: D600, fk texts are obtained from the newly added text set to form a text set to be annotated, where fk is the optimal number of texts.
[0223] D700, obtaining the annotation result res corresponding to the text set to be annotated, res including the annotation result ty corresponding to the text set to be annotated and the annotation result of the newly added preset type corresponding to the text set to be annotated; the newly added preset type and any ty mt Are different.
[0224] In this embodiment, the annotation result of ty corresponding to the to-be-annotated text set includes each ty corresponding to the to-be-annotated text set. mt The labeling results.
[0225] D800: train the trained named entity recognition model using the to-be-annotated text set and res.
[0226] Based on D600-D800, the obtained trained named entity recognition model not only has the function of identifying entities of newly added preset types, but also enables the trained named entity recognition model to reduce or improve the recognition accuracy of entities of the original preset types, thereby improving the recognition function of the trained named entity recognition model as a whole.
[0227] Although some specific embodiments of the present invention have been described in detail by way of example, it will be appreciated by those skilled in the art that the above examples are for illustration only and are not intended to limit the scope of the present invention. It will also be appreciated by those skilled in the art that various modifications may be made to the embodiments without departing from the scope and spirit of the present invention. The scope of the present invention is defined by the appended claims.
Claims
1. A text smoothing sampling method, characterized in that: The following steps are involved: S100, obtaining a text set A to be sampled, where A includes several types of texts to be sampled, the labels of the same type of texts to be sampled are the same, and the labels of different types of texts to be sampled are different; S200, obtain the number of samples 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 the 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 number of categories of the text to be sampled; q i is the number of texts to be sampled included in the i-th category of texts to be sampled; S300, if q i ≥s i , then from the i-th type of text to be sampled a i Get i The sampled texts constitute the target sampled text of the i-th category; otherwise, the i-th category sampled text a i Determine the target sample text for the i-th category.
2. The text smoothing sampling method according to claim 1, characterized in that: x=f( l g((max(Q)) 0.5 )), Q is the sampling number sequence of A, Q is composed of the number of texts to be sampled in each category of texts to be sampled, max() is the maximum value function, l g is the base 10 logarithm.
3. The text smoothing sampling method according to claim 1, characterized in that: x=f( l g((∑ n i=1 q i ) 0.5 )), l g is the base 10 logarithm.
4. The text smoothing sampling method according to claim 1, characterized in that: If q i ≥s i , then from the i-th type of text to be sampled a i Get i The target sampled texts of the i-th category are composed of the following: S310, according to a i The text similarity between the texts to be sampled includes a i Perform clustering and obtain the clustering result G i , G i Includes m clusters, m is the number of a i The number of clusters obtained by clustering; S320, Get G i The number of texts to be sampled in the smallest cluster s i,min ; S330, if s i,min ≥f(s i / m), then enter S340; S340, traverse G i , from each g i,j Get f(s i / m) texts to be sampled constitute the initial sampled text of the i-th category; g i,j For a i The jth cluster obtained by clustering, the value of j ranges from 1 to m; S350, if m×f(s i / m)=s i , then the initial sampled text of the i-th category is determined as the target sampled text of the i-th category.
5. A text smoothing sampling device, characterized in that: include: The first acquisition module is used to acquire a text set A to be sampled, where A includes several types of texts to be sampled, the labels of the same type of texts to be sampled are the same, and the labels of different types of texts to be sampled are different; The first traversal module is used to obtain the number of samples 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 the 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 number of categories of the text to be sampled; q i is the number of texts to be sampled included in the i-th category of texts to be sampled; The first judgment module is used if q i ≥s i , then from the i-th type of text to be sampled a i Get i The sampled texts constitute the target sampled text of the i-th category; otherwise, the i-th category sampled text a i Determine the target sample text for the i-th category.
6. The text smoothing sampling device according to claim 5, characterized in that: x=f( l g((max(Q)) 0.5 )), Q is the sampling number sequence of A, Q is composed of the number of texts to be sampled included in each type of text to be sampled, max() is the maximum value function, l g is the base 10 logarithm.
7. The text smoothing sampling device according to claim 5, characterized in that: x=f( l g((∑ n i=1 q i ) 0.5 )), l g is the base 10 logarithm.
8. The text smoothing sampling device according to claim 5, characterized in that: The first judgment module includes: Clustering module, 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 and obtain the clustering result G i , G i Includes m clusters, m is the number of a i The number of clusters obtained by clustering; The second acquisition module is used to obtain G i The number of texts to be sampled in the smallest cluster s i,min ; The second judgment module is used if s i,min ≥f(s i / m), then enter the second traversal module; The second traversal module is used to traverse G i , from each g i,j Get f(s i / m) texts to be sampled constitute the initial sampled text of the i-th category; g i,j For a i The jth cluster obtained by clustering, the value of j ranges from 1 to m; The third judgment module is used to determine if m×f(s i / m)=s i , then the initial sampled text of the i-th category is determined as the target sampled text of the i-th 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: When the processor executes the computer program, the text smoothing sampling method according to any one of claims 1 to 4 is implemented.
10. A computer-readable storage medium storing a computer program, characterized in that: When the computer program is executed by a processor, the smoothing sampling method of text as claimed in any one of claims 1 to 4 is implemented.
Citation Information
Patent Citations
Corpus data sampling method and model training method
CN107704869A
Text classification model training method and device, storage medium and computer equipment
CN111522942A
Sampling method and device, electronic equipment and storage medium
CN115147593A
Sample determination method and device, computer equipment and computer readable storage medium
CN116204648A
Method for industry text increment and electronic device
US20220027766A1
Cited By
Text processing method based on sampling ratio
CN118690737A
A Text Processing Method Based on Sampling Ratio
CN118690737B
