Text processing method and device based on text repetition degree and storage medium
Through the methods of random acquisition and group judgment, the problems of high similarity and low efficiency in text sampling are solved, and the reasoning ability and sampling efficiency of the semantic analysis model are improved.
Patent Information
- Application Number
- CN202410997378.7
- 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 the existing technology samples the text collection corresponding to the tag, it may lead to greater similarity between the texts, affecting the reasoning ability of the semantic analysis model. At the same time, the efficiency of the clustering method to obtain the sampled text is low, and it is difficult to take into account the sampling text. Differentiation and efficiency.
By obtaining the ratio between the number of texts to be sampled and the number of samples, the discriminative sampling text is randomly obtained, and the text is grouped and text similarity is judged. If the similarity is low, it is determined as the target sampling text to avoid the clustering method in high repetition situations. Use it below to improve sampling efficiency.
It improves the reasoning ability of the semantic analysis model for labels, takes into account the difference and acquisition efficiency of sampled text, and avoids the inefficiency of the clustering method in high-repetition situations.
Smart Images

Figure FT_1
Abstract
Description
Technical Field
[0001] The present invention relates to the technical field of electronic digital data processing, and in particular to a text processing method, device and storage medium based on text repetitiveness. Background Art
[0002] When sampling a text set corresponding to a certain label for training a semantic analysis model, the following problem may arise: the texts in the text set corresponding to the label have a high degree of repetition. If random sampling is used to sample from the text set corresponding to the label, the sampled texts may have high similarities, affecting the reasoning ability of the semantic analysis model trained based on the sampled texts about the label.
[0003] The prior art has disclosed a method for clustering texts based on text similarity. For example, a Chinese patent application with publication number CN16401565A discloses a method for training a text clustering model and a text clustering method based thereon. The patent obtains a text clustering model with stronger semantic analysis capability based on a pre-trained BERT model, and clustering of the texts to be clustered can be achieved based on the text clustering model. Although the method of clustering a text set corresponding to a certain label is conducive to improving the text differences between the obtained sampled texts, the efficiency of obtaining sampled texts by clustering a text set corresponding to a certain label is lower than the efficiency of obtaining sampled texts by random sampling. How to balance the differences between the sampled texts and the efficiency of obtaining the sampled texts is an urgent problem to be solved. Summary of the invention
[0004] The purpose of the present invention is to provide a text processing method, device and storage medium based on text repetition, so as to take into account the differences between sampled texts and the efficiency of obtaining sampled texts, improve the efficiency of obtaining sampled texts and improve the reasoning ability of semantic analysis models trained based on sampled texts.
[0005] According to a first aspect of the present invention, a text processing method based on text repetition comprises the following steps: P100, get the i-th type of text to be sampled a i , a i The 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 labels of the texts to be sampled are different, and the value of i ranges from 1 to n, where n is the number of categories of the texts to be sampled.
[0006] P200, get the number of samples s of the i-th categoryi .
[0007] P300, if q i >s i , then from a i Randomly obtain s i The texts to be sampled constitute the discriminant sample text B of the i-th category. i .
[0008] P400, for B i Perform grouping and obtain the grouping result R i , R i It includes v groups, where v is the preset number of groups.
[0009] P500, according to R i The text similarity between the included groups is obtained by B i The repetition between Chinese texts is i .
[0010] P600, if sim i ≤sim 0 , then enter P700; sim 0 is the preset similarity threshold.
[0011] P700, B i Determine the target sample text for the i-th category.
[0012] According to a second 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 processing method based on text repetition when executing the computer program.
[0013] According to a third 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 text processing method based on text repetition is implemented.
[0014] The present invention has at least the following beneficial effects: The present invention is for the i-th type of sampled text a i , if a i The number of texts to be sampled is q i Greater than the number of samples s of the i-th class i , then start from a i Randomly obtain s i The texts to be sampled constitute the discriminant sample text B of the i-th category. i ; Through B i By grouping and judging the text similarity between groups, the present invention obtains B iThe repetition between Chinese texts is i , and further sim i Similarity threshold sim 0 The size of the comparison; if sim i ≤sim 0 , 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 Only when the repetition of Chinese text is low, B i Determine the target sample text for the i-th category to solve the problem in B i If the Chinese text has a high degree of repetition, directly change B i The trained semantic analysis model is determined to be a target sample text of the i-th category i The problem of low reasoning ability of the corresponding labels; moreover, the B of the present invention i It is obtained by random sampling method, and the sampling efficiency of random sampling method is relatively high. i ≤sim 0 This can be avoided by i The clustering method is used to obtain sample text, thereby achieving the purpose of taking into account the efficiency of obtaining sample text. BRIEF DESCRIPTION OF THE DRAWINGS
[0015] 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.
[0016] Figure 1 This is a flowchart of a text processing method based on text repetition provided in Example 1 of the present invention. DETAILED DESCRIPTION
[0017] 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.
[0018] Embodiment 1: According to this embodiment, a text processing method based on text repetition is provided, such as Figure 1 As shown, including: P100, get the i-th type of text to be sampled ai , a i The 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 labels of the texts to be sampled are different, and the value of i ranges from 1 to n, where n is the number of categories of the texts to be sampled.
[0019] In this embodiment, the text to be sampled is A, A=(a 1 ,a 2 ,…,a i ,…,a n ), a i is the i-th type of text to be sampled.
[0020] P200, get the number of samples s of the i-th category i .
[0021] In this embodiment, s i For experience value.
[0022] P300, if q i >s i , then from a i Randomly obtain s i The texts to be sampled constitute the discriminant sample text B of the i-th category. i .
[0023] In this embodiment, P300 further includes: if q i ≤s i , then a i Determine the target sample text for the i-th category.
[0024] P400, for B i Perform grouping and obtain the grouping result R i , R i It includes v groups, where v is the preset number of groups.
[0025] 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.
[0026] P500, according to R i The text similarity between the included groups is obtained by B i The repetition between Chinese texts is i .
[0027] Optionally, the P500 includes: P510, get the spliced text CR i , CR i Including v concatenated texts, CR i Include the tth concatenated text CR i,t To R i,t The text obtained by concatenating the included texts; R i,t For B i The tth group is obtained by grouping; the value range of t is 1 to v.
[0028] In this embodiment, CR i ={CR i,1 ,CR i,2 ,…,CR i,t ,…,CR i,v}.
[0029] Preferably, R i,t The included text is concatenated from beginning to end to get CR i,t .
[0030] P520, Get CR i The text similarity of any two texts in SH is added to the preset similarity set SH. The obtained SH includes D text similarities. SH includes the d-th text similarity 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.
[0031] In this embodiment, SH={sh 1 ,sh 2 ,…,sh d ,…,sh D}.
[0032] 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.
[0033] 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.
[0034] P530, get sim i ,sim i =sum(SH) / D, sum( ) is the sum.
[0035] Based on P510-P530, 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.
[0036] P600, if sim i ≤sim 0 , then enter P700; sim 0 is the preset similarity threshold.
[0037] P700, B i Determine the target sample text for the i-th category.
[0038] In this embodiment, for the i-th type of sampled text a i , if a i The number of texts to be sampled is q i Greater than the number of samples s of the i-th class i , then start from a i Randomly obtain s i The texts to be sampled constitute the discriminant sample text B of the i-th category. i ; Through B i To group and determine the text similarity between groups, this embodiment obtains B i The repetition between Chinese texts is i , and further sim i Similarity threshold sim 0 The size of the comparison; if sim i ≤sim 0 , 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 Only when the repetition of Chinese text is low, B i Determine the target sample text for the i-th category to solve the problem in B i If the Chinese text has a high degree of repetition, directly change B i The trained semantic analysis model is determined to be a target sample text of the i-th category i The corresponding label has a low reasoning ability; moreover, B in this embodiment i It is obtained by random sampling, which has a relatively high sampling efficiency. i ≤sim 0 This can be avoided by iThe clustering method is used to obtain sample text, thereby achieving the purpose of taking into account the efficiency of obtaining sample text.
[0039] In this embodiment, P600 also includes: if sim i >sim 0 , then enter P800.
[0040] P800, 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 =(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, and m is the value of a i The number of clusters obtained by clustering.
[0041] 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.
[0042] 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.
[0043] P810, Get G i The number of texts to be sampled in the smallest cluster s i,min .
[0044] In this embodiment, G i The smallest cluster in G i The cluster with the least amount of text is included.
[0045] P820, if s i,min ≥f(s i / m), then go to P830; f( ) is the rounding function.
[0046] Optionally, f( ) is a floor function or a round-to-nearest function.
[0047] P830, traverse G i , from g i,j Get f(s i / m) texts to be sampled constitute the initial sampling text of the i-th category.
[0048] Optional, randomly selected from g i,j Get f(s i / m) texts to be sampled constitute the initial sampling text of the i-th category.
[0049] P840, 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; if m×f(s i / m)>s i , then randomly delete m×f(s i / m)-s i text, 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.
[0050] Based on P800-P840, this embodiment is in sim i >sim 0 In the case of a i The text similarity between the texts to be sampled includes a i Perform clustering, and for the m clusters obtained, obtain the number of texts s included in the cluster with the least number of texts (i.e., the smallest cluster) among these m clusters i,min , if s i,min ≥f(s i / m), then from each g 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 initial sampled text of the i-th category is determined as the target 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. 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.
[0051] In this embodiment, P820 further includes: if s i,min <f(s i / m), then enter P821.
[0052] P821, traverse G i , from each g i,j Get s i,min The texts to be sampled constitute the first sampled text of the i-th category.
[0053] Optional, randomly selected from each g i,j Get s i,min The texts to be sampled constitute the first sampled text of the i-th category.
[0054] P822, obtain the first remaining sampling quantity Δε 1 , Δε 1 =s i -m×s i,min .
[0055] P823, get 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 s i,min The clusters are composed of the remaining texts after the texts to be sampled.
[0056] 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.
[0057] P824, Get G 1 i The number of non-empty clusters in δ.
[0058] P825, 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.
[0059] Based on P821-P825, this embodiment is in 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 s 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 , then obtain one sampled text from each non-empty cluster and append it to the first sampled text of the i-th category. Thus, this embodiment minimizes 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.
[0060] In this embodiment, P825 also 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 Δε is randomly selected from the δ non-empty clusters 1 A non-empty cluster.
[0061] 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 s 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 <δ, then a small adjustment is made to the first 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.
[0062] Preferably, P825 further comprises: if Δε 1 >δ, then proceed to P826.
[0063] P826, Get G 1 i The number of texts to be sampled in the smallest non-empty cluster s 1 i,min .
[0064] P827, if s 1 i,min ≥f(Δε 1 / δ), then go to P828.
[0065] P828, from G 1 i Get f(Δε) from each non-empty cluster in 1 / δ) texts to be sampled are appended to the first sampled text of the i-th category.
[0066] P829, if f(Δε 1 / δ)×δ=Δε 1 , then the first sampled text of the i-th category after the appending is determined as the target sampled text of the i-th category.
[0067] Based on P826-P829, this embodiment is in 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 si,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 , then get G 1 i The number of texts to be sampled in the smallest non-empty cluster s 1 i,min , if s 1 i,min ≥f(Δε 1 / δ), then f(Δε 1 / δ) samples to be sampled are appended to the first sampled text of the i-th category. If f(Δε 1 / δ)×δ=Δε 1 , then the first sampled text of the i-th category after the addition is determined as the target sampled text of the i-th category; thus, this embodiment minimizes 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.
[0068] In this embodiment, P829 also includes: if f(Δε 1 / δ)×δ≠Δε 1 , then obtain the target sample text of the i-th category according to a method similar to P840, which will not be repeated here.
[0069] In this embodiment, P827 also includes: if s 1 i,min <f(Δε 1 / δ), then the target sample text of the i-th category is obtained according to the method similar to P821-P825, which will not be repeated here.
[0070] Embodiment 2: Considering that when sampling a text collection including different labels for training a semantic analysis model, if the number of texts corresponding to different labels is quite different, 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 smaller number of corresponding texts in the sampled texts is relatively small, resulting in poor reasoning ability of the trained semantic analysis model for labels with a smaller number of corresponding texts; and if the number of texts corresponding to different labels is quite different, if a quantity threshold is directly set based on experience, when the number of texts corresponding to a certain label is greater than the quantity threshold, a small proportion of texts is 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 is sampled from the texts corresponding to the label; this sampling method is relatively rough, so that the quantity distribution of texts corresponding to different labels in the sampled text is quite different from the quantity distribution of texts corresponding to different labels in the original text collection; therefore, on the basis of the first embodiment, this embodiment further samples the number of samples s of the i-th category. i The acquisition process of 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, and f( ) is the rounding function.
[0071] Based on the formula s of 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 text set including different labels in a class with a small number of texts. When the sampled text is subsequently used as training text for training a semantic analysis model, the reasoning ability of the trained semantic analysis model for labels corresponding to classes 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.
[0072] Optionally, x is an empirical value, for example, x=3.
[0073] 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=(q 1 ,q 2 ,…,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.
[0074] Embodiment three: Considering that in the first embodiment, based on B i The repetition between Chinese texts is i Determine whether a i The process of cluster sampling is relatively complicated, which affects the efficiency of obtaining the target sampled text of the i-th category. Based on the first embodiment, after P200 and before P300, the text processing method based on text repetition also includes: P201, obtain the text set A to be sampled, A includes n types of texts to be sampled, and the i-th type of text to be sampled included in A is a i .
[0075] In this embodiment, A={a 1 ,a 2 ,…,a i ,…,a n}.
[0076] P202, obtaining the sum w of the number of texts to be sampled included in the first u categories with the largest number of texts to be sampled in A, where u is a preset category quantity threshold.
[0077] Optionally, u is an empirical value or u=f(r'×n), r' is a preset label ratio threshold, and optionally, r' is 5%.
[0078] P203, if w / (∑ n i=1 q i )<η, then enter P300; η is the preset ratio threshold; otherwise, enter P204.
[0079] Optional, η is an empirical value, optional, η is 50%.
[0080] P204, get the sampling ratio r of the i-th category i , r i =s i / q i .
[0081] P205, if r i <r 0 , then enter P800; r 0 is the preset sampling ratio threshold; otherwise, from a i Randomly obtain s i The texts to be sampled constitute the target sampled text of the i-th category.
[0082] In this embodiment, r 0 is the experience value, optional, r 0 5% or 10%.
[0083] Based on P202-P203, in 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, execute P204-P205 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 qi )<η, that is, the number of texts corresponding to different labels included in A is relatively small, that is, when the number of texts corresponding to different labels is relatively balanced, the difference in sampling ratio of each category is relatively small, and P300-P700 is executed without obtaining the preset sampling ratio threshold, but i If the repetition is high, cluster sampling is performed on the class to improve the inference effect of the later trained semantic analysis model on the label corresponding to the class.
[0084] Embodiment 4: 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: P100, get the i-th type of text to be sampled a i , a i The 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, the value range of i is from 1 to n, and n is the number of categories of the texts to be sampled.
[0085] P200, get the number of samples s of the i-th category i .
[0086] P300, if q i >s i , then from a i Randomly obtain s i The texts to be sampled constitute the discriminant sample text B of the i-th category. i .
[0087] P400, for B i Perform grouping and obtain the grouping result R i , R i It includes v groups, where v is the preset number of groups.
[0088] P500, according to R i The text similarity between the included groups is obtained by B i The repetition between Chinese texts is i .
[0089] P600, if sim i ≤sim 0 , then enter P700; sim 0 is the preset similarity threshold.
[0090] P700, B i Determine the target sample text for the i-th category.
[0091] Embodiment five: 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: P100, get the i-th type of text to be sampled a i , a i The 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, the value range of i is from 1 to n, and n is the number of categories of the texts to be sampled.
[0092] P200, get the number of samples s of the i-th category i .
[0093] P300, if q i >s i , then from a i Randomly obtain s i The texts to be sampled constitute the discriminant sample text B of the i-th category. i .
[0094] P400, for B i Perform grouping and obtain the grouping result R i , R i It includes v groups, where v is the preset number of groups.
[0095] P500, according to R i The text similarity between the included groups is obtained by B i The repetition between Chinese texts is i .
[0096] P600, if sim i ≤sim 0 , then enter P700; sim 0 is the preset similarity threshold.
[0097] P700, B i Determine the target sample text for the i-th category.
[0098] Embodiment six: Each text in the target sample text obtained in Example 1 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 sample text, the text processing method based on text repetition in this embodiment also includes the following steps: L100, get the text to be cleaned cle, cle=(cle 1 ,cle 2,…,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.
[0099] In this embodiment, the target sample text is determined as tex, and to is the number of the target sample text.
[0100] 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 ra Includes 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 .
[0101] 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.
[0102] 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.
[0103] 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.
[0104] 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 .
[0105] 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.
[0106] In this embodiment, ra It is a prompt word based on the thought chain. In this embodiment, pro ra As 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.
[0107] 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.
[0108] In this embodiment, for each text to be cleaned, the corresponding prompt word is first obtained, and the prompt word 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 a label is a label of the text, so that the trained large language model can give a more accurate judgment result; the text to be inferred includes the text to be judged itself and the label corresponding to the text to be judged; 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, thereby solving 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.
[0109] 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.
[0110] L410, obtain the accuracy rate tpr of the trained large language model for the judgment result of yes.
[0111] 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 .
[0112] Optionally, the accuracy of the trained large language model for judging the result as yes is obtained based on the test text. When the accuracy tpr of the trained large language model for judging the result as yes is 90% and the trained large language model l ab ra Is it cle ra When the judgment result of the label is yes, it means l ab ra for cle ra The probability of the label is 90%; when the trained large language model judges that the accuracy rate tpr is 78% and the trained large language model is l ab ra Is it cle ra When the judgment result of the label is yes, it means l ab ra for cle ra The probability of the label is 78%.
[0113] L420, if tpr ≥ tf, then it is determined not to clean cle ra ; tf is a preset accuracy threshold.
[0114] In this embodiment, tf is an empirical value. Optionally, tf is 90% or 95%.
[0115] Based on L410 - L420, in this embodiment, when the accuracy of the trained large language model for the judgment result of "yes" is relatively high, the judgment result of the trained large language model is directly used as the standard. Thus, the text corresponding to the judgment result of "yes" output by the trained large language model in cle can be retained, realizing the rapid cleaning of these texts.
[0116] In this embodiment, L420 further includes: if tpr < tf, then enter L421.
[0117] L421, obtain the qua - time judgment result of the trained large language model on 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.
[0118] L422, if there are more than or equal to (qua + 1) / 2 times of judgment results of "no" in the qua - time judgment results, then it is determined to clean cle ra ; otherwise, it is determined not to clean cle ra
[0119] Based on L421 - L422, in this embodiment, when the accuracy of the trained large language model for the judgment result of "yes" is relatively low, the judgment result of the trained large language model is not directly used as the standard. Instead, 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.
[0120] As a preferred specific implementation manner, L400 further includes: if the judgment result of the trained large language model on l ab ra whether it is the label of cle ra is "no", then enter L430.
[0121] L430, obtain the false positive rate fpr of the trained large language model for the judgment result of "no".
[0122] In this embodiment, if the trained large language model on l ab ra Whether it is cle ra The judgment result of the label is no, indicating that the trained large language model judges l ab ra is not cle ra of the label.
[0123] Optionally, the accuracy rate of the trained large language model for the judgment result of no is obtained based on the test text. When the accuracy rate fpr of the trained large language model for the judgment result of no is 68% and the trained large language model for l ab ra Whether it is cle ra The judgment result of the label is no, indicating l ab ra is not cle ra the probability of the label is 68%; when the accuracy rate fpr of the trained large language model for the judgment result of yes is 92% and the trained large language model for l ab ra Whether it is cle ra The judgment result of the label is no, indicating l ab ra is not cle ra the probability of the label is 92%.
[0124] L440, if fpr < tf, then enter L450; otherwise, clean cle ra up.
[0125] In this embodiment, tf is an empirical value. Optionally, tf is 90% or 95%.
[0126] L450, obtain the qua - th judgment result of the trained large language model for l ab ra Whether it is cle ra of the label, where qua is the preset number of repeated inferences, qua is an odd number and qua ≥ 3.
[0127] In this embodiment, qua is an empirical value. Optionally, qua is 3 or 5.
[0128] L460, if there are more than or equal to (qua + 1) / 2 times of judgment results of no among the qua - th judgment results, then judge to clean cle ra up; otherwise, judge not to clean cle ra up.
[0129] 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.
[0130] 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.
[0131] Embodiment seven: If the prompt words used to input into the trained large language model in the sixth embodiment are constructed manually, there is still a problem of occupying a lot of human resources. In order to further reduce the occupation of human resources, this embodiment, based on the sixth 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.
[0132] 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 .
[0133] 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.
[0134] 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.
[0135] 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=(bas 1 ,bas 2 ,…,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,me is 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.
[0136] In this embodiment, bas ce,me Includes several thought chain sample texts, bas ce,meEach example text of the thought chain included corresponds to the $ce$-th first-level tag included in $cle$ and the $me$-th second-level tag, however, $bas$ ce,me The judgment identifiers corresponding to different example texts of the thought chain included may be the same or different, $bas$ ce,me The judgment identifier corresponding to the example text of the thought chain included is used to indicate whether the tag corresponding to the example text of the thought chain is the tag of the target text corresponding to the example text of the thought chain. For example, if $bas$ ce,me the judgment identifier corresponding to the example text of the thought chain included is correct or yes, it indicates that the tag corresponding to the example text of the thought chain is the tag of the target text corresponding to the example text of the thought chain; if $bas$ ce,me the judgment identifier corresponding to the example text of the thought chain included is wrong or no, it indicates that the tag corresponding to the example text of the thought chain is not the tag of the target text corresponding to the example text of the thought chain.
[0137] Optionally, $L220$ includes: $L221$, if $bas$ ce matches l $ab$ 1 ra then enter $L222$.
[0138] In this embodiment, if $bas$ ce the corresponding first-level tag is the same as l $ab$ 1 ra then it is judged that $bas$ ce matches l $ab$ 1 ra ; otherwise, it is judged that $bas$ ce does not match l $ab$ 1 ra .
[0139] $L222$, if $te = num$, then obtain 1 example text of the thought chain from each $bas$ ce,me to construct $mod$ ra ; if $te > num$, then enter $L223$; if $te < num$, then enter $L225$.
[0140] $L223$, obtain the priority of each $bas$ ce,me .
[0141] 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 .
[0142] L224, get 1 thought chain example text build mod from each target sub-library ra , the target sub-library is bas ce The top num thought chain example text sub-libraries with the highest priority.
[0143] L225, from every bas ce,me Get 1 thought chain example text to build the initial text.
[0144] L226, obtain the text deviation quantity Δq, Δq=num-te; L227, from bas ce The remaining thought chain example texts are obtained from Δq thought chain example texts and appended to the initial text, and the appended initial text is determined as mod ra bas ce The remaining thought chain example text is bas ce Example texts of thought chains other than the initial text.
[0145] Based on L221-L227, this embodiment is from l ab 1 ra Matching bas ce num thought chain example texts were obtained from the code and mod ra Automatic construction, eliminating the need to manually build mods ra Moreover, this embodiment takes as much as possible from l ab 1 ra Matching bas ce Get the thought chain sample text of different secondary tags in order to make the mod ra Includes example text of thought chains corresponding to various secondary tags, which is helpful for including mod later ra Prompt words included ra When 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.
[0146] L230, according to mod ra cle ra andcle ra Secondary tags l ab 2 ra Build cle ra Corresponding prompt word pro ra .
[0147] 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.
[0148] 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 .
[0149] 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 avgis 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.
[0150] 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.
[0151] L203, if cn ra Greater than or equal to l ab 1 ra The number of secondary tags included, then cn ra Determined to be num; if cn ra Less than l ab 1 ra The number of secondary tags included will be l ab 1 ra The number of secondary tags included is identified as num.
[0152] 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 words ra To enable the mod ra The number of characters included does not exceed tok max That's it.
[0153] 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.
[0154] Embodiment eight: In the first embodiment, the label of the target sample text may be wrong. In order to obtain a correct and more comprehensive label for each text in the target sample text, the text processing method based on text repetition in this embodiment further includes: F100, get the text tex of the label to be obtained, tex=(tex 1 ,tex 2 ,…,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.
[0155] In this embodiment, the target sample text is determined as tex, and ae is the number of the target sample text.
[0156] 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.
[0157] F200, according to the text of the first label to be obtained in tex 1 Get the trained first label inference model mode 1 , mode 1 =(mode 1,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.
[0158] 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 with tags to be obtained in [text] is also 1 / 2 of the number of texts with tags to be obtained in [tex].
[0159] In this embodiment, each [mode] 1,av the training samples come from [tex] 1 , and the training samples corresponding to different [modes] 1,av are different; as a specific implementation, F200 includes: F210, which divides [tex] 1 to obtain the divided text subsets [zc] 1 , [zc] 1 = ([zc] 1,1 , [zc] 1,2 , …, [zc] 1,av , …, [zc] 1,ax ), and [zc] 1,av is the ax-th text subset obtained by dividing [tex] 1 .
[0160] Optionally, [tex] 1 is evenly divided into ax text subsets.
[0161] F220, initializes the model variable [ha] to 1.
[0162] F230, selects ax - 1 text subsets from [zc] 1 except [zc] 1,ha as the ha-th training sample.
[0163] F240, uses the ha-th training sample and the corresponding original tags to train the ha-th first label inference model, and obtains the ha-th trained first label inference model [mode] 1,ha .
[0164] F250, if [ha] < [ax], then [ha] = [ha] + 1, and repeats F230 - F240 until [ha] = [ax].
[0165] Based on F210 - F250, when [ha] is 1, executing F230 - F240 can obtain the 1st trained first label inference model [mode] 1,1 ; when [ha] is 2, executing F230 - F240 can obtain the 2nd trained first label inference model [mode] 1,2 , and so on. When [ha] is [ax], executing F230 - F240 can obtain the ax-th trained first label inference model [mode] 1,ax ; thus, ax trained first label inference models can be obtained after executing F210 - F250.
[0166] F300, according to mode 1 Get the text tex of the second label to be obtained in tex 2 The inference label qa of the text to be labeled in 2 ,qa 2 =(qa 2 1 ,qa 2 2 ,…,qa 2 er ,…,qa 2 zn ), qa 2 er For tex 2 The inference label of the erth text to be labeled, er ranges from 1 to zn, zn is tex 2 The number of texts to be labeled, qa 2 er =(qa 2 er,1 ,qa 2 er,2 ,…,qa 2 er,av ,…,qa 2 er,ax ), qa 2 er,av According to mode 1,av Get tex 2 The inference label of the text to be labeled in erth; tex 2 Remove tex from tex 1 The text of the tag to be obtained outside the qa 2 er,av Includes several inference tags.
[0167] In this embodiment, tex 2 The 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 2The 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 .
[0168] 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.
[0169] 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.
[0170] 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 .
[0171] 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.
[0172] In this embodiment, qa 2The 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.
[0173] 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.
[0174] 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 2 er,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 .
[0175] 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 erEach qa in 2 er,av The sum of the number of included inference labels.
[0176] F402, traverse wqa 2 er , use 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.
[0177] Those skilled in the art know that any large language model in the prior art falls within the protection scope of the present invention.
[0178] 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.
[0179] 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.
[0180] F404, determine the preset erth label sequence as nqa 2 er .
[0181] Based on F401-F404, this embodiment implements qa based on the trained large language model 2 er The screening of NQA is improved through the trained large language model 2 er The accuracy of the inference labels in .
[0182] F500, nqa 2 er Determine as tex 2 The label of the erth text to be judged.
[0183] In this embodiment, each text in the text tex to be labeled corresponds to an original label, and a part of the text tex in tex is used. 1A plurality of trained first label inference models can be obtained from the corresponding original labels, and another part of the text tex in tex can be obtained according to the plurality of trained first label inference models. 2 inference labels; since the present embodiment uses multiple trained first label inference models to obtain inference labels for texts, different trained first label inference models may obtain different inference labels for texts, and therefore the inference labels for texts obtained by the present embodiment are relatively comprehensive; moreover, the present embodiment also screens the inference labels obtained according to multiple trained first label inference models to select the correct labels from the relatively comprehensive inference labels; thus, the present embodiment achieves the purpose of obtaining correct and relatively comprehensive labels for texts.
[0184] As an optional specific implementation, ax is an empirical value, for example, 3≤ax≤5.
[0185] 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 .
[0186] F202, get the initial number of divisions hua 0 ,hua 0 =floor(shu 1 / shu 0 ), shu 0 is the preset text quantity threshold, and floor() is rounding down.
[0187] In this embodiment, 0 is an empirical value, corresponding 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.
[0188] F203, obtain the first division quantity hua 1 ,hua 1 =min(max(hua 0 ,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.
[0189] In this embodiment, hua min and hua max All are experience values.
[0190] F204, from tex 1 Get 1 -1) / hua 1 The test label inference model is trained based on the text of the to-be-acquired label and the corresponding original label to obtain a trained test label inference model.
[0191] F205, if the accuracy of the trained test label inference model is greater than or equal to the preset accuracy threshold, then 1 Determined to be ax.
[0192] In this embodiment, if the accuracy of the trained test label inference model is less than the preset accuracy threshold, 1 Get hua 1 / (hua 1 +1) is used to train the test label inference model with the text of the label to be obtained and the corresponding original label 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, then hua 1 +1 for ax; otherwise, from tex 1 Get 1 +1) / (hua 1 +2) The text of the to-be-acquired label 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, the hua 1 +2 to confirm ax; otherwise, from tex 1 Get 1 +2) / (hua 1 +3) The text of the to-be-acquired label 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.
[0193] Based on the ax obtained from F201-F205, tex 1 Divide it so that tex 1 in (hua 1 -1) / hua 1 The proportion of text corresponds to a large number of texts, which improves the subsequent tex-based 1 in (hua 1 -1) / hua 1 The accuracy of the first label inference model trained on the text with a certain percentage is conducive to improving the accuracy of the final text label.
[0194] 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.
[0195] 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.
[0196] 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 mode 2 , mode 2 Including some according to tex 2 The trained second label inference model obtained; according to mode 2 Get tex 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 er Filter 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 1The 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.
[0197] Embodiment nine: In order to obtain a named entity recognition model capable of performing entity annotation of multiple preset types on the target sample text, the text processing method based on text repetition in this embodiment further includes the following steps: D100, get the training text set data of the trained named entity recognition model, data={data 1 ,data 2 ,…,data se ,…,data st}, data se is the se-th training text set of the trained named entity recognition model, data se The training set includes several training texts, 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 trained using data, and the trained named entity recognition model is used to identify entities of a preset type ty in the input text and mark the corresponding labels; ty=(ty 1 ,ty 2 ,…,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.
[0198] 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.
[0199] 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.
[0200] D200, traverse data, if using data seWhen training a 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 mt-th weight qz se,mt ; Otherwise, set qz se,mt is 0.
[0201] 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.
[0202] 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 a 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.
[0203] D300, obtain the positive sample ratio cb of ht preset types of entities in the test text set, cb=(cb 1 ,cb 2 ,…,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.
[0204] 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.
[0205] 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.
[0206] D400, obtain the positive sample ratio zb of ht preset types of entities in the newly added text set, zb=(zb 1 ,zb 2 ,…,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.
[0207] 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.
[0208] 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.
[0209] 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.
[0210] In this embodiment, each text in cq is used as the input of the trained named entity recognition model to obtain the corresponding annotation results of ht preset types of entities.
[0211] 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 .
[0212] 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.
[0213] 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.
[0214] The trained named entity recognition model in this embodiment is obtained by training based on the training text set data, which 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 the newly added preset type of entities. This embodiment determines the optimal number of texts to be obtained from the newly added text set for training the trained 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 zb of ht preset types of entities in the newly added text set, and the weight of each training text set corresponding to each preset type in data, wherein the newly added text set has the optimal number of texts to be obtained from the newly added text set for training the trained named entity recognition model. The proportion of positive samples of ht preset types of entities determines the extent of the impact 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. 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 re-trained named entity recognition model for the original ht preset types of entities and the recognition accuracy of the newly added preset types of entities.
[0215] As a preferred embodiment, D500 includes: D510, get the loss dif of the newly added text, dif=(∑ ht mt=1 |cb mt -((∑ st se=1 qz se,mt ×mu se )+zb mt ×zq) / (su se + zq)|)+ke / zq,mu se For data se The amount of text included, suse 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.
[0216] In this embodiment, ke is an empirical value, optional, 0 <ke<1。
[0217] 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.
[0218] 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.
[0219] 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.
[0220] 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.
[0221] 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.
[0222] D800: train the trained named entity recognition model using the to-be-annotated text set and res.
[0223] 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.
[0224] 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 processing method based on text repetition, characterized in that: The following steps are involved: P100, get the i-th type of text to be sampled a i , a i The 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 labels of the texts to be sampled are different, and the value range of i is 1 to n, where n is the number of categories of the texts to be sampled; P200, get the number of samples s of the i-th category i ; P300, if q i >s i , then from a i Randomly obtain s i The texts to be sampled constitute the discriminant sample text B of the i-th category. i ; P400, for B i Perform grouping and obtain the grouping result R i , R i Includes v groups, where v is the preset number of groups; P500, according to R i The text similarity between the included groups is obtained by B i The repetition between Chinese texts is i ; P600, if sim i ≤sim0, then enter P700; sim0 is the preset similarity threshold; P700, B i Determine the target sample text for the i-th category.
2. The text processing method based on text repetition according to claim 1, characterized in that: P500 includes: P510, get the spliced text CR i , CR i Including v concatenated texts, CR i Include the tth concatenated text CR i,t To R i,t The text obtained by concatenating the included texts; R i,t For B i The tth group is obtained by grouping; the value range of t is 1 to v; P520, Get CR i The text similarity of any two texts in SH is added to the preset similarity set SH. The obtained SH includes D text similarities. SH includes the d-th text similarity 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 number of corresponding text pairs, D = v × (v-1) / 2; SH is initialized to an empty set; P530, get sim i ,sim i =sum(SH) / D, sum( ) is the sum.
3. The text processing method based on text repetition according to claim 1, characterized in 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.
4. The text processing method based on text repetition according to claim 1, characterized in that: After P200 and before P300, the method further includes: P201, obtain the text set A to be sampled, A includes n types of texts to be sampled, and the i-th type of text to be sampled included in A is a i ; P202, obtaining the sum w of the number of texts to be sampled included in the first u categories with the largest number of texts to be sampled in A, where u is a preset category number threshold; P203, if w / (∑ n i=1 q i )<η, then enter P300; η is the preset ratio threshold.
5. The text processing method based on text repetition according to claim 1, characterized in that: P300 also includes: If q i ≤s i , then a i Determine the target sample text for the i-th category.
6. 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 processing method based on text repetition as described in any one of claims 1 to 5 is implemented.
7. A computer-readable storage medium storing a computer program, characterized in that: When the computer program is executed by a processor, the text processing method based on text repetition as claimed in any one of claims 1 to 5 is implemented.
Citation Information
Patent Citations
Text sampling method and device for improving annotation efficiency
CN112069785A
Text structuring technology based on sliding window and random discrete sampling
CN113239192A
Text enhancement processing method and device, equipment and storage medium
CN114817527A
Semantic similarity model training set obtaining method and device and computer equipment
CN115935190A
Text processing method based on stratified sampling
CN118070781A
Cited By
Text processing method based on sampling ratio
CN118690737A
A Text Processing Method Based on Sampling Ratio
CN118690737B
