Text detection model training method, electronic equipment and storage medium
By collecting and calibrating text data from multiple fields, dividing training, verification and test sets, and training and verification of text detection models multiple times, using technologies such as Bayesian optimization and adaptive learning rate to optimize model performance, the problem of low accuracy in traditional machine learning models when processing high-dimensional text data is solved, and more efficient text detection and classification is achieved.
Patent Information
- Application Number
- CN202411868234.8
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2024-12-17
- Publication Date
- 2025-04-15
AI Technical Summary
In the prior art, traditional machine learning models have low accuracy when processing high-dimensional text data and complex semantic relationships, and it is difficult to effectively distinguish between normal text and exception text.
By collecting text data from multiple fields, performing calibration and preprocessing, a calibration text data set is generated. Then, the training set, verification set and test set are divided, the initial text detection model is trained and verified multiple times, and the hyperparameters are adjusted using Bayesian optimization algorithm, and the model performance is optimized through the adaptive learning rate adjustment algorithm and adversarial training mechanism.
It improves the accuracy and generalization ability of the text detection model, and can more effectively identify and classify normal and abnormal texts.
Smart Images

Figure CN119831003A_ABST
Abstract
Description
Technical Field
[0001] The present application relates to the field of computer processing technology, and in particular to a training method, electronic device and storage medium for a text detection model. Background Art
[0002] With the rapid progress of Internet technology and computer science, the application of network information technology in various fields of society is becoming more and more common. Given the openness of the Internet and the characteristics of resource sharing, text information on the Internet can spread quickly on the Internet. When these texts contain sensitive content such as fraud, false statements, and lies, they may indicate that criminal activities are about to occur, which may pose a major threat to social security. Therefore, a major challenge currently faced is how to accurately and quickly identify abnormal text information, improve detection efficiency, and effectively prevent the occurrence of criminal incidents.
[0003] In the prior art, text detection models mostly detect target text based on simple machine learning models.
[0004] However, in the prior art, traditional machine learning models have low accuracy when processing high-dimensional text data and complex semantic relationships, and cannot effectively distinguish normal text from abnormal text. Therefore, the prior art has a technical problem of low detection accuracy of text detection models. Summary of the invention
[0005] The embodiments of the present application provide a text detection model training method, an electronic device, and a storage medium to achieve the technical effect of improving the accuracy of the text detection model.
[0006] In a first aspect, an embodiment of the present application provides a method for training a text detection model, comprising:
[0007] Collect text data from multiple fields, calibrate each text data, and obtain calibrated text data; wherein the content of each text data calibration includes data field, text type and whether it is abnormal text;
[0008] According to the multiple calibrated text data, a training set, a validation set and a test set for model training are obtained; wherein the training set, the validation set and the test set respectively include multiple normal texts and multiple abnormal texts;
[0009] The initial text detection model is trained according to the training set and the validation set to obtain an intermediate text detection model;
[0010] The intermediate text detection model is evaluated according to the test set to obtain multiple evaluation results, and it is determined whether the multiple evaluation results meet the preset conditions. If not, the intermediate text detection model is trained again according to the training set to obtain a new intermediate text detection model. This step is repeated until the evaluation results meet the preset conditions and the target text training model is determined.
[0011] In a possible implementation, before training the initial text detection model according to the training set and the validation set, the method further includes:
[0012] Perform data analysis on each text data to determine the language feature information, text length distribution information and vocabulary complexity information of each text data;
[0013] Selecting a basic text detection model from multiple basic models according to the language feature information, text length distribution information and vocabulary complexity information of each text data;
[0014] The hyperparameters of the basic text detection model are adjusted according to the Bayesian optimization algorithm to obtain the initial text detection model.
[0015] In a possible implementation, training the initial text detection model according to the training set and the validation set includes:
[0016] Step a: training the initial text detection model according to the training set to obtain a trained text detection model;
[0017] Step b: verifying the trained text detection model according to the verification set to obtain a harmonic mean of the first accuracy and the recall rate, and a first cross entropy loss value;
[0018] Step c, determining the trained text detection model as a new initial text detection model, training the new initial text detection model according to the training set, and verifying the trained text detection model according to the verification set, to obtain a harmonic mean of a second precision and a recall rate, and a second cross entropy loss value;
[0019] Step d, calculating the training cycle difference between the first cross entropy loss value and the second cross entropy loss value, and determining the harmonic mean of the second accuracy and recall rate as the new harmonic mean of the first accuracy and recall rate;
[0020] Step e: If there are no consecutive preset number of zeros in the obtained multiple training cycle differences or the harmonic mean of the new first accuracy and recall rate is less than the first preset threshold, repeat steps a to d until there are consecutive preset number of zeros in the obtained multiple training cycle differences and the harmonic mean of the new first accuracy and recall rate is greater than or equal to the first preset threshold, and the training is completed.
[0021] In a possible implementation, the initial text detection model is trained according to the training set to obtain a trained text detection model, including:
[0022] Divide the training set into multiple training groups, train the initial text detection model multiple times according to the multiple training groups, and obtain the cross entropy loss value of each training;
[0023] According to multiple cross entropy loss values, the learning rate information of the initial text detection model is adjusted through an adaptive learning rate adjustment algorithm to determine an adjusted text detection model;
[0024] Build the generator network and the discriminator network;
[0025] Generate corresponding adversarial samples based on each abnormal text in the training set through the generator network;
[0026] Input each abnormal text and the corresponding adversarial sample into the discriminator network to generate the corresponding discriminant information;
[0027] The multiple discriminant information are input into the adjusted text detection model to obtain a trained text detection model.
[0028] In a possible implementation, the intermediate text detection model is evaluated based on the test set to obtain multiple evaluation results, including:
[0029] The intermediate text detection model is evaluated according to the test set to obtain the evaluation index results of each text data; the evaluation index results include accuracy information, recall information, false positive rate information, the harmonic mean of accuracy and recall rate, false positive rate information and false negative rate information;
[0030] Determine the ROC curve based on multiple false positive rate information and multiple recall rate information;
[0031] Determine the PR curve based on multiple recall rate information;
[0032] Multiple evaluation results are determined based on multiple evaluation indicator results, ROC curves and PR curves.
[0033] In a possible implementation, the method further includes:
[0034] Obtaining a text to be detected, preprocessing the text to be detected, and obtaining the preprocessed text to be detected;
[0035] Input the preprocessed text to be detected into the target text training model to obtain the probability information of the preprocessed text to be detected belonging to normal text and the probability information of the text to be detected belonging to abnormal text; wherein the probability information belonging to the abnormal text includes multiple items, and each probability information corresponds to a type of abnormal text;
[0036] Determine whether the probability information of belonging to normal text meets the second preset threshold value, and if so, determine the text to be detected as normal text, and determine the detection result of determining the text to be detected as normal text as the first detection result;
[0037] If not, the text to be detected is determined as an abnormal text, and it is determined whether each piece of probability information belonging to the abnormal text satisfies the corresponding third preset threshold;
[0038] If there is at least one probability information that satisfies the corresponding third preset threshold, the text to be detected is determined as abnormal text, and the type corresponding to the probability information is determined as the abnormal text type of the text to be detected;
[0039] The detection result that the text to be detected is determined to be an abnormal text is determined as a second detection result; wherein the second detection result includes at least one abnormal text type and associated information result of the text to be detected; the associated information result is obtained by performing an association analysis between the text to be detected and multiple associated texts according to an association rule mining algorithm;
[0040] The first detection result or the second detection result is output to the user end.
[0041] In a second aspect, an embodiment of the present application provides a training device for a text detection model, including:
[0042] The collection module is used to collect text data from multiple fields, calibrate each text data, and obtain the calibrated text data; wherein the content of each text data calibration includes the data field, text type and whether it is an abnormal text;
[0043] A first processing module is used to obtain a training set, a validation set and a test set for model training based on a plurality of calibrated text data; wherein the training set, the validation set and the test set respectively include a plurality of normal texts and a plurality of abnormal texts;
[0044] The second processing module is used to train the initial text detection model according to the training set and the validation set to obtain an intermediate text detection model;
[0045] The third processing module is used to evaluate the intermediate text detection model according to the test set, obtain multiple evaluation results, and determine whether the multiple evaluation results meet the preset conditions. If not, the intermediate text detection model is trained again according to the training set to obtain a new intermediate text detection model. This step is repeated until the evaluation results meet the preset conditions and the target text training model is determined.
[0046] In a possible implementation manner, the first processing module is further configured to:
[0047] Perform data analysis on each text data to determine the language feature information, text length distribution information and vocabulary complexity information of each text data;
[0048] Selecting a basic text detection model from multiple basic models according to the language feature information, text length distribution information and vocabulary complexity information of each text data;
[0049] The hyperparameters of the basic text detection model are adjusted according to the Bayesian optimization algorithm to obtain the initial text detection model.
[0050] In a possible implementation manner, the second processing module is further used for:
[0051] Step a: training the initial text detection model according to the training set to obtain a trained text detection model;
[0052] Step b: verifying the trained text detection model according to the verification set to obtain a harmonic mean of the first accuracy and the recall rate, and a first cross entropy loss value;
[0053] Step c, determining the trained text detection model as a new initial text detection model, training the new initial text detection model according to the training set, and verifying the trained text detection model according to the verification set, to obtain a harmonic mean of a second precision and a recall rate, and a second cross entropy loss value;
[0054] Step d, calculating the training cycle difference between the first cross entropy loss value and the second cross entropy loss value, and determining the harmonic mean of the second accuracy and recall rate as the new harmonic mean of the first accuracy and recall rate;
[0055] Step e: If there are no consecutive preset number of zeros in the obtained multiple training cycle differences or the harmonic mean of the new first accuracy and recall rate is less than the first preset threshold, repeat steps a to d until there are consecutive preset number of zeros in the obtained multiple training cycle differences and the harmonic mean of the new first accuracy and recall rate is greater than or equal to the first preset threshold, and the training is completed.
[0056] In a possible implementation manner, the second processing module is further used for:
[0057] Divide the training set into multiple training groups, train the initial text detection model multiple times according to the multiple training groups, and obtain the cross entropy loss value of each training;
[0058] According to multiple cross entropy loss values, the learning rate information of the initial text detection model is adjusted through an adaptive learning rate adjustment algorithm to determine an adjusted text detection model;
[0059] Build the generator network and the discriminator network;
[0060] Generate corresponding adversarial samples based on each abnormal text in the training set through the generator network;
[0061] Input each abnormal text and the corresponding adversarial sample into the discriminator network to generate the corresponding discriminant information;
[0062] The multiple discriminant information are input into the adjusted text detection model to obtain a trained text detection model.
[0063] In a possible implementation manner, the third processing module is further configured to:
[0064] The intermediate text detection model is evaluated according to the test set to obtain the evaluation index results of each text data; the evaluation index results include accuracy information, recall information, false positive rate information, the harmonic mean of accuracy and recall rate, false positive rate information and false negative rate information;
[0065] Determine the ROC curve based on multiple false positive rate information and multiple recall rate information;
[0066] Determine the PR curve based on multiple recall rate information;
[0067] Multiple evaluation results are determined based on multiple evaluation indicator results, ROC curves and PR curves.
[0068] In a possible implementation manner, the third processing module is further configured to:
[0069] Obtaining a text to be detected, preprocessing the text to be detected, and obtaining the preprocessed text to be detected;
[0070] Input the preprocessed text to be detected into the target text training model to obtain the probability information of the preprocessed text to be detected belonging to normal text and the probability information of the text to be detected belonging to abnormal text; wherein the probability information belonging to the abnormal text includes multiple items, and each probability information corresponds to a type of abnormal text;
[0071] Determine whether the probability information of belonging to normal text meets the second preset threshold value, and if so, determine the text to be detected as normal text, and determine the detection result of determining the text to be detected as normal text as the first detection result;
[0072] If not, the text to be detected is determined as an abnormal text, and it is determined whether each piece of probability information belonging to the abnormal text satisfies the corresponding third preset threshold;
[0073] If there is at least one probability information that satisfies the corresponding third preset threshold, the text to be detected is determined as abnormal text, and the type corresponding to the probability information is determined as the abnormal text type of the text to be detected;
[0074] The detection result that the text to be detected is determined to be an abnormal text is determined as a second detection result; wherein the second detection result includes at least one abnormal text type and associated information result of the text to be detected; the associated information result is obtained by performing an association analysis between the text to be detected and multiple associated texts according to an association rule mining algorithm;
[0075] The first detection result or the second detection result is output to the user end.
[0076] In a third aspect, an embodiment of the present application provides an electronic device, including: a memory, a processor;
[0077] The memory stores computer-executable instructions;
[0078] The processor executes the computer-executable instructions stored in the memory, so that the processor executes the above first aspect and / or various possible implementations of the first aspect.
[0079] In a fourth aspect, an embodiment of the present application provides a computer-readable storage medium, in which computer-executable instructions are stored. When the computer-executable instructions are executed by a processor, they are used to implement the first aspect above and / or various possible implementations of the first aspect.
[0080] In a fifth aspect, an embodiment of the present application provides a computer program product, including a computer program, which, when executed by a processor, implements the above first aspect and / or various possible implementation methods of the first aspect.
[0081] The training method, electronic device and storage medium of the text detection model provided in the embodiment of the present application collect text data from multiple different fields and annotate them one by one to generate an annotated text data set. Using these annotated text data, we divide them into a training set for model training, a verification set for verifying model performance, and a test set for testing model accuracy. The initial text detection model is trained with the training set and the verification set to obtain a preliminary intermediate text detection model; the intermediate model is evaluated with the test set to obtain a series of evaluation results. If these evaluation results do not meet the preset standards, we use the training set to train the intermediate model again to generate a new intermediate model, and repeat this evaluation and training process until the evaluation results meet the preset conditions, and finally determine the target text detection model. Through the method of the present application, by obtaining text data from multiple fields, the extensiveness of the text detection model training data is expanded, and at the same time, the text detection model is multiple trained and verified with the training set and the verification set, and the model is evaluated with evaluation indicators in multiple dimensions, thereby improving the accuracy of the text detection model. BRIEF DESCRIPTION OF THE DRAWINGS
[0082] The accompanying drawings, which are incorporated in and constitute a part of this specification, illustrate embodiments consistent with the present application and, together with the description, serve to explain the principles of the present application.
[0083] Figure 1 Schematic diagram of the training method of the text detection model provided in this application Figure 1 ;
[0084] Figure 2 Schematic diagram of the training method of the text detection model provided in this application Figure 2 ;
[0085] Figure 3 A flowchart of an application method of a text detection model provided in this application;
[0086] Figure 4 A schematic diagram of the structure of a training device for a text detection model provided in this application;
[0087] Figure 5 A hardware diagram of a training device for a text detection model provided in this application.
[0088] The above drawings have shown clear embodiments of the present application, which will be described in more detail later. These drawings and text descriptions are not intended to limit the scope of the present application in any way, but to illustrate the concept of the present application to those skilled in the art by referring to specific embodiments. DETAILED DESCRIPTION
[0089] Exemplary embodiments will be described in detail herein, examples of which are shown in the accompanying drawings. When the following description refers to the drawings, unless otherwise indicated, the same numbers in different drawings represent the same or similar elements. The implementations described in the following exemplary embodiments do not represent all implementations consistent with the present application. Instead, they are merely examples of methods and methods consistent with some aspects of the present application as detailed in the appended claims.
[0090] In the prior art, for the construction and application of text detection models, there is a general tendency to use methods based on simple machine learning models to detect target texts. Although this method can achieve basic text classification and recognition functions to a certain extent, its limitations gradually become apparent when faced with high-dimensional, large-scale text data rich in complex semantic relationships. Specifically, when traditional machine learning models process this type of high-level text information, due to the limitations of the algorithm itself and insufficient feature extraction capabilities, it is difficult for the model to accurately capture the subtle differences and deep connections between texts. This is not only reflected in the fact that the model does not clearly divide the boundary between normal text and abnormal text, which can easily lead to false positives or negative reports, but also in the fact that the model has a weak ability to recognize new or variant abnormal texts and is difficult to adapt to the rapidly changing network environment.
[0091] Therefore, the existing text detection models generally have the technical problem of low detection accuracy, which not only affects the effectiveness and reliability of text detection tasks, but also limits the wide application of related technologies in fields such as network content review and information security monitoring.
[0092] The training method, electronic device and storage medium of the text detection model provided in the embodiment of the present application collect text data from multiple different fields and annotate them one by one to generate an annotated text data set. Using these annotated text data, we divide them into a training set for model training, a verification set for verifying model performance, and a test set for testing model accuracy. The initial text detection model is trained with the training set and the verification set to obtain a preliminary intermediate text detection model; the intermediate model is evaluated with the test set to obtain a series of evaluation results. If these evaluation results do not meet the preset standards, we use the training set to train the intermediate model again to generate a new intermediate model, and repeat this evaluation and training process until the evaluation results meet the preset conditions, and finally determine the target text detection model. Through the method of the present application, by obtaining text data from multiple fields, the extensiveness of the text detection model training data is expanded, and at the same time, the text detection model is multiple trained and verified with the training set and the verification set, and the model is evaluated with evaluation indicators in multiple dimensions, thereby improving the accuracy of the text detection model.
[0093] The technical solution of the present application and how the technical solution of the present application solves the above-mentioned technical problems are described in detail below with specific embodiments. The following specific embodiments can be combined with each other, and the same or similar concepts or processes may not be repeated in some embodiments. The embodiments of the present application will be described below in conjunction with the accompanying drawings.
[0094] Figure 1 Schematic diagram of the training method of the text detection model provided in this application Figure 1 ,like Figure 1 As shown, the method includes:
[0095] S101, collecting text data from multiple fields, calibrating each text data, and obtaining calibrated text data;
[0096] In this embodiment, for multiple fields, including but not limited to news, academic papers, social media, literary works and medical records, for example, for text data in the news field, combined with news-related keywords and search rules, keywords include but are not limited to current affairs, international news and financial news, and news reports are collected from the official websites of major news organizations. At the same time, news content in different language versions is collected, and the languages include but are not limited to English, Chinese, French and Spanish; after collecting text data in multiple fields, each text data is calibrated by automatic annotation tools combined with rules and machine learning algorithms, and the calibrated content includes data field, text type and whether it is abnormal text; for example, the calibration information of a text data is news field, entertainment news, and normal text; the marking of abnormal text needs to be more accurate, and the types of abnormal text include but are not limited to false information text, attack text and junk advertising text; for example, for false information text, the type of its false content needs to be calibrated; for attack text, the target type and attack method of the attack are marked; for junk advertising text, the category of the advertisement and possible fraud attributes are marked.
[0097] S102, obtaining a training set, a validation set, and a test set for model training according to the plurality of calibrated text data;
[0098] In this embodiment, by dividing a plurality of calibrated text data according to a preset ratio, a training set, a validation set and a test set are obtained. Through the training set, the model can learn the inherent laws and characteristics of the data, thereby improving the generalization ability of the model; through the validation set, the model can be continuously optimized during the training process to avoid overfitting, thereby improving the generalization ability of the model on unseen data; the test set provides an independent data set that does not overlap with the training set and the validation set, which is used to finally evaluate the performance of the model, which helps to ensure the stability and reliability of the model in practical applications. Optionally, the training set, the validation set and the test set include multiple normal texts and multiple abnormal texts respectively. In the division process, the distribution of the text data tag content and the abnormal text is fully considered to ensure that each data set can reasonably represent the characteristics of the entire text data. For example, it is ensured that the training set contains sufficient samples of various fields and types of texts, and the proportion of abnormal text types is similar to that in the overall data; the validation set and the test set also have similar distribution characteristics, which are used to accurately evaluate the performance of the model on different data subsets.
[0099] S103, training the initial text detection model according to the training set and the validation set to obtain an intermediate text detection model;
[0100] In this embodiment, the initial text detection model is trained with the training set to obtain a trained text detection model, and the trained text detection model is further verified according to the verification set. After the verification passes, the trained text detection model is determined as the intermediate text detection model. If the verification fails, a new round of training is performed on the trained text detection model according to the training set, and the obtained model is determined as the new trained text detection model. The new trained text detection model is continuously verified according to the verification set until it passes, thereby obtaining an intermediate text detection model.
[0101] S104. Evaluate the intermediate text detection model according to the test set to obtain multiple evaluation results, and determine whether the multiple evaluation results meet the preset conditions. If not, train the intermediate text detection model again according to the training set to obtain a new intermediate text detection model. Repeat this step until the evaluation results meet the preset conditions and determine the target text training model.
[0102] In this embodiment, the intermediate text detection model is evaluated through a test set, and the training status of the current intermediate text detection model is evaluated through multiple evaluation results. If the preset conditions are not met, the intermediate text detection model is retrained by adjusting the model parameters or training strategies, thereby improving the generalization ability of the model and the accuracy of text detection.
[0103] The training method, electronic device and storage medium of the text detection model provided in the embodiment of the present application collect text data from multiple different fields and annotate them one by one to generate an annotated text data set. Using these annotated text data, we divide them into a training set for model training, a verification set for verifying model performance, and a test set for testing model accuracy. The initial text detection model is trained with the training set and the verification set to obtain a preliminary intermediate text detection model; the intermediate model is evaluated with the test set to obtain a series of evaluation results. If these evaluation results do not meet the preset standards, we use the training set to train the intermediate model again to generate a new intermediate model, and repeat this evaluation and training process until the evaluation results meet the preset conditions, and finally determine the target text detection model. Through the method of the present application, by obtaining text data from multiple fields, the extensiveness of the text detection model training data is expanded, and at the same time, the text detection model is multiple trained and verified with the training set and the verification set, and the model is evaluated with evaluation indicators in multiple dimensions, thereby improving the accuracy of the text detection model.
[0104] Figure 2Schematic diagram of the text detection model training method provided in this application Figure 2 , this embodiment is in Figure 1 Based on the embodiment, the text detection model training method is described in detail, wherein collecting text data and selecting an initial text detection model can be implemented through steps S201 to S202; training the initial text detection model according to the training set, and obtaining the trained text detection model is implemented through steps S203 to S204; verifying the trained text detection model through the verification set, and obtaining the intermediate text detection model is implemented through steps S205 to S207; evaluating the intermediate text detection model through the test set, and determining the target text detection model is implemented through step S208; Figure 2 As shown, a text detection model training method is described in detail, and the method includes:
[0105] S201, collecting text data from multiple fields, calibrating each text data to obtain calibrated text data, and obtaining a training set, a validation set, and a test set for model training based on the multiple calibrated text data;
[0106] In this embodiment, after calibrating each text data, each text data needs to be preprocessed, and the preprocessing content includes text cleaning, word segmentation processing and word vector conversion; optionally, text cleaning includes the processing of special symbols and blank characters, and the main process of special symbol processing is to build a comprehensive special symbol dictionary, which contains special characters, non-standard punctuation marks and special symbols specific to the same field in various programming languages. In the cleaning process, these special symbols are removed by accurately matching the characters in the text with the special symbol dictionary; the step of blank character processing includes using regular expressions to write complex matching patterns to accurately identify continuous blank areas, including but not limited to any combination of spaces, tabs and line breaks, and replace these continuous blank areas with single spaces, while retaining reasonable blank separations between paragraphs and sentences to avoid the impact of too many or too few blank characters on text representation; for some blank characters in certain formats, special processing is performed according to their format characteristics to ensure that text structure information is not lost.
[0107] Optionally, the word segmentation process includes word segmentation based on a combination of multiple models and processing of unregistered words; wherein, a combination of multiple language models and vocabularies is used, a statistically based language model is used to perform preliminary word segmentation on the text, the text is split into word units based on the frequency of word occurrence and the co-occurrence probability of adjacent words, and the preliminary word segmentation results are further optimized using a neural network language model, especially for some ambiguous words, accurate judgment is made through contextual semantic information, and domain-specific words are accurately identified according to the source field of the text to ensure the accuracy of word segmentation; for unregistered words that are not in the existing vocabulary, they are processed through word vector representation and rule-based methods, and the rule-based methods include but are not limited to recognizing continuous combinations of numbers and letters; for some newly emerging network terms, professional terms and other unregistered words, an attempt is made to give them a temporary vector representation based on their contextual semantic information in the text and combined with the vector representation of similar words, and they are continuously optimized in the subsequent training process.
[0108] Optionally, a pre-trained word vector model that integrates multiple language corpora is selected, and the corpus includes but is not limited to multiple natural languages, programming languages, and symbolic languages; the model makes full use of semantic information, grammatical information, and the distribution information of vocabulary in different texts during the training process. Through this fusion of multimodal information, the word vector can more comprehensively represent the characteristics of words; after the words are converted into vectors, each vector is normalized. The specific method is to calculate the modulus of the vector, and then divide the value of each dimension of the vector by the modulus so that the length of each vector is 1. This normalization process can improve the stability of subsequent model training, avoid the problem of gradient vanishing or explosion caused by excessive differences in vector lengths, and accelerate the convergence of the model. During the normalization process, some special vectors are additionally processed, such as assigning a small random perturbation vector according to the characteristics of the corresponding words.
[0109] S202, performing data analysis on each text data to determine language feature information, text length distribution information, and vocabulary complexity information of each text data, selecting a basic text detection model from multiple basic models based on the language feature information, text length distribution information, and vocabulary complexity information of each text data, and adjusting the hyperparameters of the basic text detection model based on a Bayesian optimization algorithm to obtain an initial text detection model;
[0110] In this embodiment, a comprehensive data analysis is performed on the collected text data, and the analysis content includes language feature information, text length distribution information and vocabulary complexity information; the language feature information includes but is not limited to vocabulary richness, grammatical structure complexity and language style diversity; the text length distribution is analyzed to determine the proportion of short texts, medium-long texts and long texts in the text data, as well as the average length of texts in different fields; the vocabulary complexity information includes but is not limited to the proportion of professional vocabulary and the number of uncommon vocabulary; based on these analysis results, a suitable basic model is selected from a plurality of basic models to select the basic text detection model that best suits the characteristics of the current text data.
[0111] Optionally, a Bayesian optimization algorithm is used to search for the optimal hyperparameter combination. The specific steps include determining the range of hyperparameters to be adjusted, such as the hidden layer dimension, the number of attention heads, and the number of layers; constructing an objective function that comprehensively considers the loss value, accuracy, and F1-score evaluation indicators of the model on a small-scale validation data set; the Bayesian optimization algorithm guides the search process by constructing a probability model of the objective function in the hyperparameter space based on the existing evaluation results, predicting the direction of hyperparameter combinations that may produce better results; during the search process, the probability model is continuously updated to reduce unnecessary hyperparameter combination attempts, thereby effectively reducing the time and computing resource consumption of hyperparameter adjustment; the output layer of the pre-trained model is modified according to the number of text categories to be predicted, determining that the text categories include normal text and multiple different types of abnormal text, and modifying the dimension of the output layer to match the number of these text categories, ensuring that the model can output accurate information on the probability of each text belonging to different categories, and after modifying the hyperparameters, the initial text detection model is determined.
[0112] S203, dividing the training set into a plurality of training groups, training the initial text detection model multiple times according to the plurality of training groups, obtaining a cross entropy loss value of each training, and adjusting the learning rate information of the initial text detection model through an adaptive learning rate adjustment algorithm according to the plurality of cross entropy loss values, and determining an adjusted text detection model;
[0113] In this embodiment, an adaptive learning rate adjustment algorithm is used. During the training process, the learning rate is dynamically adjusted according to the change of the cross entropy loss value of the model on each training batch. In the early stage of training, when the cross entropy loss value decreases rapidly, the learning rate is appropriately increased to speed up the model convergence speed; when the cross entropy loss value tends to be stable or fluctuates, the learning rate is reduced to avoid skipping the optimal solution. In this way, the learning rate can be automatically adjusted to a suitable value according to the training state of the model, so that the model can learn the basic features of the text data, such as the basic semantic representation of vocabulary, common grammatical structures, etc. In a possible implementation method, the preliminary training continues until the cross entropy loss value of the model on the training set changes less than the preset threshold value for consecutive preset value cycles, and it is considered that the preset first convergence condition is reached, and the adjusted text detection model can be determined. For example, the change rate of the loss value of the model on the training set for 3 consecutive cycles is less than 0.01, and the adjusted text detection model can be determined.
[0114] S204, constructing a generator network and a discriminator network, generating a corresponding adversarial sample according to each abnormal text in the training set through the generator network, inputting each abnormal text and the corresponding adversarial sample into the discriminator network, generating corresponding discriminant information, and inputting the multiple discriminant information into the adjusted text detection model to obtain a trained text detection model;
[0115] In this embodiment, in order to improve the learning rate of the model, the present application introduces an adversarial training mechanism, constructs a generator network and a discriminator network, and the generator network is based on the principle of variational autoencoder or generative adversarial network, and generates adversarial samples corresponding to the abnormal texts in the training set by learning the feature distribution of abnormal texts in the training set. The discriminator network is constructed based on a convolutional neural network or a multi-layer perceptron, and is used to distinguish the adversarial samples generated by the abnormal text and the generator. During the training process, the generator network generates corresponding adversarial samples according to each abnormal text in the training set, and each abnormal text and the corresponding adversarial sample are input into the discriminator network. The discriminator generates discriminant information, and the discriminant information is fed back to the adjusted text detection model obtained in step S203, so that the adjusted text detection model can learn more discriminative features, thereby enhancing the ability to discriminate abnormal texts and determining the trained text detection model. During the adversarial training process, by adjusting the training ratio and number of iterations of the generator and the discriminator, the balanced development of the two is ensured to avoid excessive generation of adversarial samples that are difficult to distinguish or the discriminator being too powerful to effectively learn new features.
[0116] S205, verifying the trained text detection model according to the validation set, obtaining a harmonic mean of a first accuracy rate and a recall rate, and a first cross entropy loss value, determining the trained text detection model as a new initial text detection model, training the new initial text detection model according to the training set, and verifying the trained text detection model according to the validation set, obtaining a harmonic mean of a second accuracy rate and a recall rate, and a second cross entropy loss value;
[0117] In this embodiment, the cross entropy loss function is used as the main loss function for model training, and the cross entropy loss function is used to measure the difference between the model prediction result and the true label. At the same time, the harmonic mean F1-score of the accuracy and recall rate is combined as an additional evaluation indicator. The F1-score comprehensively considers the accuracy and recall rate of the model, and can more comprehensively evaluate the performance of the model on an unbalanced data set. The unbalanced data set refers to the situation where the number of abnormal texts is far less than the number of normal texts. By verifying the trained text detection model, a verification result is obtained after verification, and the trained text detection model is further determined as a new initial text detection model. The new initial text detection model is continuously trained according to the training set to obtain a new verification result, that is, after each training set trains the initial text detection model, the trained text detection model is obtained, and the trained text detection model must first be verified by the verification set to obtain a verification result before the next round of training.
[0118] S206, calculating the training cycle difference between the first cross entropy loss value and the second cross entropy loss value, and determining the harmonic mean of the second accuracy and recall rate as the new harmonic mean of the first accuracy and recall rate;
[0119] In this embodiment, the difference between the two cross entropy loss values is taken to obtain the difference in training cycles, and the harmonic mean of the second accuracy and recall rate is determined as the new harmonic mean of the first accuracy and recall rate. In the subsequent judgment of the verification results, only the harmonic mean of the new first accuracy and recall rate obtained for the last time is used as the basis for judgment.
[0120] S207, if there are no consecutive preset number of zeros in the obtained multiple training cycle differences or the harmonic mean of the new first accuracy and recall rate is less than the first preset threshold, repeat steps S204 to S205 until there are consecutive preset number of zeros in the obtained multiple training cycle differences and the harmonic mean of the new first accuracy and recall rate is greater than or equal to the first preset threshold, the training is completed, and the intermediate text detection model is obtained;
[0121] In this embodiment, it is determined whether there are a preset number of consecutive zeros in the obtained multiple training cycle differences and the harmonic mean of the new first accuracy and recall rate is less than the first preset threshold. If not, repeat S204 to S205 to continue to obtain the corresponding training cycle differences and the harmonic mean of the new first accuracy and recall rate. When there are a preset number of consecutive zeros in the obtained multiple training cycle differences and the harmonic mean of the new first accuracy and recall rate is greater than or equal to the first preset threshold, the training is completed and the intermediate text detection model is obtained; for example, the preset number of times is 5 times, and the first preset threshold is 0.9; after repeating steps S204 to S205 for the Nth time, N training cycle differences are obtained, and the next four training cycle differences of the current N training cycle differences have been consecutively 0. After the N+1th training and verification, the obtained training cycle difference is 0, and the harmonic mean of the first accuracy and recall rate obtained this time is greater than 0.9, then the training is completed and the intermediate text detection model is obtained.
[0122] S208. Evaluate the intermediate text detection model according to the test set to obtain multiple evaluation results, and determine whether the multiple evaluation results meet the preset conditions. If not, train the intermediate text detection model again according to the training set to obtain a new intermediate text detection model. Repeat this step until the evaluation results meet the preset conditions and determine the target text training model.
[0123] In this embodiment, the multiple evaluation results include multiple evaluation index results, and the ROC curve and the PR curve determine the multiple evaluation results.
[0124] In a possible implementation, the intermediate text detection model is evaluated based on the test set to obtain evaluation index results for each text data; the evaluation index results include accuracy information, recall information, false positive rate information, the harmonic mean of accuracy and recall, false alarm rate information and false negative rate information; the accuracy rate indicates the proportion of the number of texts correctly predicted by the model to the total number of predicted texts; the recall rate indicates the proportion of the number of abnormal texts correctly predicted by the model to the actual number of abnormal texts; the harmonic mean F1-score of accuracy and recall is the harmonic mean of accuracy and recall, which can balance the relationship between the two; the false alarm rate indicates the proportion of normal texts incorrectly predicted by the model as abnormal texts; the false negative rate indicates the proportion of abnormal texts incorrectly predicted by the model as normal texts.
[0125] One possible implementation method is to determine the ROC curve based on multiple false positive rate information and multiple recall rate information; when drawing the ROC curve, calculate the true positive rate and false positive rate under different thresholds. The true positive rate is the ratio of the number of abnormal texts correctly predicted by the model to the actual number of abnormal texts, and the false positive rate is the ratio of the number of normal texts incorrectly predicted as abnormal texts by the model to the actual number of normal texts. By changing the threshold of the model prediction probability, a series of true positive rate values and false positive rate values are obtained, and these values are plotted as a curve; in order to obtain a more accurate and intuitive curve representation, a smoothing algorithm is used to smooth the curve; the smoothing algorithm can use the moving average method and the spline interpolation method to eliminate the jagged shape on the curve caused by data noise or model fluctuations, making the curve smoother and better reflecting the actual performance trend of the model.
[0126] Optionally, a PR curve is determined based on multiple recall rate information; when drawing the PR curve, the precision at different recall rates is calculated. The precision rate is the ratio of the number of abnormal texts correctly predicted by the model to the number of texts predicted as abnormal. By changing the threshold, the precision values at different recall rate levels are obtained, and the curve is filled with an interpolation algorithm; the interpolation algorithm can choose linear interpolation and polynomial interpolation to better show the change of the precision of the model at different recall rate levels, so that the curve can more continuously and accurately reflect the model performance in the low or high recall rate range.
[0127] By determining multiple evaluation results through multiple evaluation indicator results, ROC curves, and PR curves, the intermediate text detection model can be evaluated comprehensively, multi-dimensionally, and intuitively, thereby determining the target text detection model.
[0128] In a possible implementation, after determining the target text detection model through training, the detection of the text to be detected can be realized. Specifically,
[0129] Figure 3 A flowchart of the text detection model application provided in this application. This embodiment is based on Figure 2 On the basis of the embodiment, after completing the training of the text detection model, how to detect the text to be detected according to the target text detection model is described in detail, wherein the target text detection model outputs the probability of the text to be detected belonging to abnormal or normal text through steps S301 to 302; the client provides the detection result of the text to be detected to the user terminal according to the output result of the target text detection model through steps S303 to S305; Figure 3 As shown, a text detection model training method is described in detail, and the method includes:
[0130] S301, obtaining a text to be detected, preprocessing the text to be detected, and obtaining the preprocessed text to be detected;
[0131] In this embodiment, the text to be detected is preprocessed, the text is cleaned, special symbols and blank characters are removed, and the standard format of the text is maintained; then word segmentation is performed to split the new text into individual word units to ensure the accuracy of word segmentation, especially for newly appeared words or words with special meanings. Finally, the text data after word segmentation is converted into word vectors, and each word is converted into a vector representation of fixed dimension using the same pre-trained word vector model and normalization method in the training process to obtain the pre-processed text to be detected.
[0132] S302, inputting the preprocessed text to be detected into the target text training model to obtain probability information of the preprocessed text to be detected belonging to normal text and probability information of the preprocessed text to be detected belonging to abnormal text;
[0133] In this embodiment, the probability information belonging to the abnormal text includes multiple items, and each item of probability information corresponds to a type of abnormal text.
[0134] S303, determining whether the probability information of belonging to normal text meets the second preset threshold, and if so, determining the text to be detected as normal text, and determining the detection result of determining the text to be detected as normal text as the first detection result;
[0135] In this example, by judging the probability information of whether the text to be detected is normal text, it can be determined whether the text to be detected is normal text.
[0136] S304, if not, determining the text to be detected as abnormal text, and determining whether each probability information in the probability information belonging to the abnormal text satisfies the corresponding third preset threshold; if there is at least one probability information that satisfies the corresponding third preset threshold, determining the text to be detected as abnormal text, and determining the type corresponding to the probability information as the abnormal text type of the text to be detected;
[0137] In this embodiment, if the probability information of the text to be detected belonging to normal text does not meet the second preset threshold, the text to be detected is determined as abnormal text. The corresponding preset threshold of each type of abnormal text is different. The corresponding preset threshold of each type of abnormal text is different and can be determined according to the distribution ratio of the abnormal text in the training set, the weight of false alarm and missed alarm. The principle of determination is that if a certain type of false information text accounts for a small proportion in the training set, but the false alarm can lead to serious consequences, then the threshold of this type of abnormal text should be appropriately increased; if the missed alarm of a certain attack text may cause great harm to the user, then its preset threshold should be appropriately lowered. Determine which abnormal type the text belongs to based on each determined threshold; if there is at least one probability information that satisfies the corresponding third preset threshold, the text to be detected is determined to be abnormal text, and the type corresponding to the probability information is determined as the abnormal text type of the text to be detected; for example, the probability of the output of the text to be detected belonging to normal text is 0.5, the probability of belonging to type A abnormal text is 0.6, the probability of belonging to type B abnormal text is 0.5, and the probability of belonging to type C abnormal text is 0.6. The second preset threshold for normal text is 0.7, the third preset threshold for type A abnormal text is 0.5, the third preset threshold for type B abnormal text is 0.4, and the third preset threshold for type C abnormal text is 0.7. Therefore, the text to be detected is abnormal text, and the possible abnormal types are type A and type B.
[0138] S305: Determine the detection result that the text to be detected is abnormal text as the second detection result, and output the first detection result or the second detection result to the user terminal.
[0139] In this embodiment, the second detection result includes at least one abnormal text type and associated information result of the text to be detected; the associated information result is obtained by performing an association analysis on the text to be detected and multiple associated texts according to an association rule mining algorithm. Optionally, after judging that the text is abnormal, the association rule mining algorithm is further used to analyze the association between the abnormal text and other related texts and user information. For abnormal texts from social media, the historical published content, follow list, fan information, etc. of the user who published the text, as well as the relevant information of other users who interacted with the user, can be analyzed to find out possible abnormal behavior patterns or gang relationships. For texts in other fields, such as abnormal texts in academic papers, text information related to the cited documents, co-authors, etc. can be analyzed to mine clues of possible academic misconduct. Through this association analysis, the background and potential impact of the abnormal text can be more fully understood, providing a basis for further processing and decision-making.
[0140] The text detection model training method provided in the embodiment of the present application collects text data from multiple fields to expand the training samples, and calibrates and preprocesses each text data to improve the accuracy of model training. Furthermore, by performing data analysis on each text data, a basic text detection model is determined according to the analysis results, and the hyperparameters of the model are initially optimized by a Bayesian optimization algorithm. Multiple trainings of the initial detection model are completed through a training set. After each training is completed, a verification result is obtained for the trained model according to a verification set, and an intermediate text detection model is determined until the verification result meets a preset condition. Further, the intermediate text detection model is evaluated through a test set, and the completion of the training of the model is analyzed in multiple dimensions through multiple evaluation indicators and evaluation curves, so as to determine the target text detection model. By inputting the text to be detected into the model, the probability of belonging to normal text and the probability of abnormal text can be obtained. Through the probability information improved by the model, the client determines the text type of the text to be detected if it belongs to abnormal text, and performs association analysis at the same time, and then sends the final detection result to the user end. This method optimizes the processes of data collection, data processing, model training, and multi-dimensional evaluation of the training model, achieving the technical effect of improving the accuracy and generalization ability of the text detection model.
[0141] Figure 4 A structural diagram of the training device for the text detection model provided in this application, such as Figure 4 As shown, the text detection model training device 40 provided in this embodiment includes:
[0142] The collection module 401 is used to collect text data from multiple fields, calibrate each text data, and obtain the calibrated text data; wherein the content of each text data calibration includes the data field, text type and whether it is an abnormal text;
[0143] The first processing module 402 is used to obtain a training set, a validation set and a test set for model training based on the multiple calibrated text data; wherein the training set, the validation set and the test set respectively include multiple normal texts and multiple abnormal texts;
[0144] The second processing module 403 is used to train the initial text detection model according to the training set and the validation set to obtain an intermediate text detection model;
[0145] The third processing module 404 is used to evaluate the intermediate text detection model according to the test set, obtain multiple evaluation results, and determine whether the multiple evaluation results meet the preset conditions. If not, the intermediate text detection model is trained again according to the training set to obtain a new intermediate text detection model. This step is repeated until the evaluation results meet the preset conditions and the target text training model is determined.
[0146] In a possible implementation, the first processing module 402 is further configured to:
[0147] Perform data analysis on each text data to determine the language feature information, text length distribution information and vocabulary complexity information of each text data;
[0148] Selecting a basic text detection model from multiple basic models according to the language feature information, text length distribution information and vocabulary complexity information of each text data;
[0149] The hyperparameters of the basic text detection model are adjusted according to the Bayesian optimization algorithm to obtain the initial text detection model.
[0150] In a possible implementation manner, the second processing module 403 is further configured to:
[0151] Step a: training the initial text detection model according to the training set to obtain a trained text detection model;
[0152] Step b: verifying the trained text detection model according to the verification set to obtain a harmonic mean of the first accuracy and the recall rate, and a first cross entropy loss value;
[0153] Step c, determining the trained text detection model as a new initial text detection model, training the new initial text detection model according to the training set, and verifying the trained text detection model according to the verification set, to obtain a harmonic mean of a second precision and a recall rate, and a second cross entropy loss value;
[0154] Step d, calculating the training cycle difference between the first cross entropy loss value and the second cross entropy loss value, and determining the harmonic mean of the second accuracy and recall rate as the new harmonic mean of the first accuracy and recall rate;
[0155] Step e: If there are no consecutive preset number of zeros in the obtained multiple training cycle differences or the harmonic mean of the new first accuracy and recall rate is less than the first preset threshold, repeat steps a to d until there are consecutive preset number of zeros in the obtained multiple training cycle differences and the harmonic mean of the new first accuracy and recall rate is greater than or equal to the first preset threshold, and the training is completed.
[0156] In a possible implementation manner, the second processing module 403 is further configured to:
[0157] Divide the training set into multiple training groups, train the initial text detection model multiple times according to the multiple training groups, and obtain the cross entropy loss value of each training;
[0158] According to multiple cross entropy loss values, the learning rate information of the initial text detection model is adjusted through an adaptive learning rate adjustment algorithm to determine an adjusted text detection model;
[0159] Build the generator network and the discriminator network;
[0160] Generate corresponding adversarial samples based on each abnormal text in the training set through the generator network;
[0161] Input each abnormal text and the corresponding adversarial sample into the discriminator network to generate the corresponding discriminant information;
[0162] The multiple discriminant information are input into the adjusted text detection model to obtain a trained text detection model.
[0163] In a possible implementation manner, the third processing module 404 is further configured to:
[0164] The intermediate text detection model is evaluated according to the test set to obtain the evaluation index results of each text data; the evaluation index results include accuracy information, recall information, false positive rate information, the harmonic mean of accuracy and recall rate, false positive rate information and false negative rate information;
[0165] Determine the ROC curve based on multiple false positive rate information and multiple recall rate information;
[0166] Determine the PR curve based on multiple recall rate information;
[0167] Multiple evaluation results are determined based on multiple evaluation indicator results, ROC curves and PR curves.
[0168] In a possible implementation manner, the third processing module 404 is further configured to:
[0169] Obtaining a text to be detected, preprocessing the text to be detected, and obtaining the preprocessed text to be detected;
[0170] Input the preprocessed text to be detected into the target text training model to obtain the probability information of the preprocessed text to be detected belonging to normal text and the probability information of the text to be detected belonging to abnormal text; wherein the probability information belonging to the abnormal text includes multiple items, and each probability information corresponds to a type of abnormal text;
[0171] Determine whether the probability information of belonging to normal text meets the second preset threshold value, and if so, determine the text to be detected as normal text, and determine the detection result of determining the text to be detected as normal text as the first detection result;
[0172] If not, the text to be detected is determined as an abnormal text, and it is determined whether each piece of probability information belonging to the abnormal text satisfies the corresponding third preset threshold;
[0173] If there is at least one probability information that satisfies the corresponding third preset threshold, the text to be detected is determined as abnormal text, and the type corresponding to the probability information is determined as the abnormal text type of the text to be detected;
[0174] The detection result that the text to be detected is determined to be an abnormal text is determined as a second detection result; wherein the second detection result includes at least one abnormal text type and associated information result of the text to be detected; the associated information result is obtained by performing an association analysis between the text to be detected and multiple associated texts according to an association rule mining algorithm;
[0175] The first detection result or the second detection result is output to the user end.
[0176] The text detection model training device provided in this embodiment can execute the method provided in the above method embodiment. Its implementation principle and technical effects are similar, and will not be described in detail in this embodiment.
[0177] Figure 5 A hardware diagram of a training device for a text detection model provided in this application. Figure 5 As shown, the electronic device 50 provided in this embodiment includes: at least one processor 501 and a memory 502. Optionally, the device 50 also includes a communication component 503. The processor 501, the memory 502 and the communication component 503 are connected via a bus 505.
[0178] In a specific implementation process, at least one processor 501 executes the computer-executable instructions stored in the memory 502, so that at least one processor 501 executes the above method.
[0179] The specific implementation process of the processor 501 can be found in the above method embodiment, and its implementation principle and technical effect are similar, so this embodiment will not be repeated here.
[0180] In the above embodiments, it should be understood that the processor may be a central processing unit (CPU), or other general-purpose processors, digital signal processors (DSP), application-specific integrated circuits (ASIC), etc. A general-purpose processor may be a microprocessor or any conventional processor. The steps of the method disclosed in the invention may be directly implemented as being executed by a hardware processor, or may be executed by a combination of hardware and software modules in the processor.
[0181] The memory may include a high-speed memory (Random Access Memory, RAM), and may also include a non-volatile memory (Non-volatile Memory, NVM), such as at least one disk memory.
[0182] The bus may be an Industry Standard Architecture (ISA) bus, a Peripheral Component Interconnect (PCI) bus, or an Extended Industry Standard Architecture (EISA) bus, etc. The bus may be divided into an address bus, a data bus, a control bus, etc. For ease of representation, the bus in the drawings of the present application is not limited to only one bus or one type of bus.
[0183] The present application also provides a computer program product, including a computer program, which implements the above method when executed by a processor.
[0184] The present application also provides a computer-readable storage medium, in which computer-executable instructions are stored. When a processor executes the computer-executable instructions, the above method is implemented.
[0185] The above-mentioned readable storage medium can be implemented by any type of volatile or non-volatile storage device or a combination thereof, such as static random access memory (SRAM), electrically erasable programmable read-only memory (EEPROM), erasable programmable read-only memory (EPROM), programmable read-only memory (PROM), read-only memory (ROM), magnetic memory, flash memory, magnetic disk or optical disk. The readable storage medium can be any available medium that can be accessed by a general or special-purpose computer.
[0186] An exemplary readable storage medium is coupled to a processor so that the processor can read information from the readable storage medium and write information to the readable storage medium. Of course, the readable storage medium can also be a component of the processor. The processor and the readable storage medium can be located in an application specific integrated circuit (Application Specific Integrated Circuits, referred to as: ASIC). Of course, the processor and the readable storage medium can also exist in the device as discrete components.
[0187] The division of units is only a logical function division, and there may be other divisions in actual implementation, such as multiple units or components can be combined or integrated into another system, or some features can be ignored or not executed. Another point is that the mutual coupling or direct coupling or communication connection shown or discussed can be an indirect coupling or communication connection through some interface, method or unit, which can be electrical, mechanical or other forms.
[0188] The units described as separate components may or may not be physically separated, and the components shown as units may or may not be physical units, that is, they may be located in one place or distributed on multiple network units. Some or all of the units may be selected according to actual needs to achieve the purpose of the solution of this embodiment.
[0189] In addition, each functional unit in each embodiment of the present invention may be integrated into one processing unit, or each unit may exist physically separately, or two or more units may be integrated into one unit.
[0190] If the function is implemented in the form of a software functional unit and sold or used as an independent product, it can be stored in a computer-readable storage medium. Based on this understanding, the technical solution of the present invention, or the part that contributes to the prior art, or the part of the technical solution, can be embodied in the form of a software product. The computer software product is stored in a storage medium, including several instructions for a computer device (which can be a personal computer, server, or network device, etc.) to perform all or part of the steps of the methods of each embodiment of the present invention. The aforementioned storage medium includes: U disk, mobile hard disk, read-only memory (ROM, Read-Only Memory), random access memory (RAM, Random Access Memory), disk or optical disk, etc. Various media that can store program codes.
[0191] Those skilled in the art can understand that all or part of the steps of implementing the above-mentioned method embodiments can be completed by hardware related to program instructions. The aforementioned program can be stored in a computer-readable storage medium. When the program is executed, the steps of the above-mentioned method embodiments are executed; and the aforementioned storage medium includes: ROM, RAM, disk or optical disk and other media that can store program codes.
[0192] Finally, it should be noted that those skilled in the art will readily conceive of other embodiments of the present invention after considering the specification and practicing the invention disclosed herein. The present invention is intended to cover any variations, uses or adaptations of the present invention, which follow the general principles of the present invention and include common knowledge or customary technical means in the art not disclosed by the present invention, are not limited to the precise structure described above and shown in the drawings, and may be modified and changed in various ways without departing from the scope thereof. The scope of the present invention is limited only by the appended claims.
Claims
1. A training method for a text detection model, characterized in that: include: Collect text data from multiple fields, calibrate each text data, and obtain calibrated text data; wherein the content of each text data calibration includes data field, text type and whether it is abnormal text; According to the multiple calibrated text data, a training set, a validation set and a test set for model training are obtained; wherein the training set, the validation set and the test set respectively include multiple normal texts and multiple abnormal texts; Training the initial text detection model according to the training set and the validation set to obtain an intermediate text detection model; The intermediate text detection model is evaluated according to the test set to obtain multiple evaluation results, and it is determined whether the multiple evaluation results meet the preset conditions. If not, the intermediate text detection model is trained again according to the training set to obtain a new intermediate text detection model. This step is repeated until the evaluation results meet the preset conditions, and the target text training model is determined.
2. The method according to claim 1, characterized in that Before training the initial text detection model according to the training set and the validation set, the method further includes: Perform data analysis on each text data to determine the language feature information, text length distribution information and vocabulary complexity information of each text data; Selecting a basic text detection model from a plurality of basic models according to the language feature information, the text length distribution information and the vocabulary complexity information of each text data; The hyperparameters of the basic text detection model are adjusted according to the Bayesian optimization algorithm to obtain the initial text detection model.
3. The method according to claim 1, characterized in that The training of the initial text detection model according to the training set and the validation set includes: Step a, training the initial text detection model according to the training set to obtain a trained text detection model; Step b: verifying the trained text detection model according to the verification set to obtain a harmonic mean of a first accuracy rate and a recall rate, and a first cross entropy loss value; Step c, determining the trained text detection model as a new initial text detection model, training the new initial text detection model according to the training set, and verifying the trained text detection model according to the verification set, to obtain a harmonic mean of a second precision and a recall rate, and a second cross entropy loss value; Step d, calculating the training cycle difference between the first cross entropy loss value and the second cross entropy loss value, and determining the harmonic mean of the second accuracy and recall rate as the new harmonic mean of the first accuracy and recall rate; Step e: If there are no consecutive preset number of zeros in the obtained multiple training cycle differences or the harmonic mean of the new first accuracy and recall rate is less than the first preset threshold, repeat steps a to d until there are consecutive preset number of zeros in the obtained multiple training cycle differences and the harmonic mean of the new first accuracy and recall rate is greater than or equal to the first preset threshold, and the training is completed.
4. The method according to claim 3, characterized in that The step of training the initial text detection model according to the training set to obtain a trained text detection model includes: Dividing the training set into a plurality of training groups, training the initial text detection model multiple times according to the plurality of training groups, and obtaining a cross entropy loss value for each training; According to the multiple cross entropy loss values, the learning rate information of the initial text detection model is adjusted by an adaptive learning rate adjustment algorithm to determine an adjusted text detection model; Build the generator network and the discriminator network; Generate a corresponding adversarial sample according to each abnormal text in the training set through the generator network; Input each abnormal text and the corresponding adversarial sample into the discriminator network to generate corresponding discriminant information; A plurality of discrimination information is input into the adjusted text detection model to obtain the trained text detection model.
5. The method according to claim 1, characterized in that The intermediate text detection model is evaluated according to the test set to obtain multiple evaluation results, including: The intermediate text detection model is evaluated according to the test set to obtain evaluation index results for each text data; the evaluation index results include accuracy information, recall information, false positive rate information, the harmonic mean of accuracy and recall, false positive rate information and false negative rate information; Determine the ROC curve based on multiple false positive rate information and multiple recall rate information; Determine a PR curve according to the multiple recall rate information; A plurality of evaluation results are determined according to the plurality of evaluation index results, the ROC curve and the PR curve.
6. The method according to any one of claims 1 to 5, characterized in that: The method further comprises: Obtaining a text to be detected, preprocessing the text to be detected, and obtaining the preprocessed text to be detected; Inputting the preprocessed text to be detected into the target text training model to obtain probability information of the preprocessed text to be detected belonging to normal text and probability information of the text to be detected belonging to abnormal text; wherein the probability information of the text to be detected belonging to abnormal text includes multiple items, each of which corresponds to a type of abnormal text; Determine whether the probability information of the normal text satisfies a second preset threshold value, and if so, determine the text to be detected as normal text, and determine the detection result of the text to be detected as normal text as the first detection result; If not, the to-be-detected text is determined as an abnormal text, and it is determined whether each piece of probability information in the probability information belonging to the abnormal text satisfies a corresponding third preset threshold; If there is at least one probability information that satisfies the corresponding third preset threshold, the text to be detected is determined as abnormal text, and the type corresponding to the probability information is determined as the abnormal text type of the text to be detected; The detection result of determining the text to be detected as abnormal text is determined as a second detection result; wherein the second detection result includes at least one abnormal text type and associated information result of the text to be detected; the associated information result is obtained by performing an association analysis on the text to be detected and multiple associated texts according to an association rule mining algorithm; The first detection result or the second detection result is output to a user terminal.
7. A training device for a text detection model, characterized in that: include: The collection module is used to collect text data from multiple fields, calibrate each text data, and obtain the calibrated text data; wherein the content of each text data calibration includes the data field, text type and whether it is an abnormal text; A first processing module is used to obtain a training set, a validation set and a test set for model training according to the multiple calibrated text data; wherein the training set, the validation set and the test set respectively include multiple normal texts and multiple abnormal texts; A second processing module is used to train the initial text detection model according to the training set and the verification set to obtain an intermediate text detection model; The third processing module is used to evaluate the intermediate text detection model according to the test set to obtain multiple evaluation results, and determine whether the multiple evaluation results meet the preset conditions. If not, the intermediate text detection model is trained again according to the training set to obtain a new intermediate text detection model. This step is repeated until the evaluation results meet the preset conditions to determine the target text training model.
8. An electronic device, characterized in that: include: Memory, processor; The memory stores computer-executable instructions; The processor executes the computer-executable instructions stored in the memory, so that the processor performs the method according to any one of claims 1 to 6.
9. A computer-readable storage medium, characterized in that: The computer-readable storage medium stores computer-executable instructions, which are used to implement the method according to any one of claims 1 to 6 when executed by a processor.
10. A computer program product, characterized in that The invention comprises a computer program, which implements the method according to any one of claims 1 to 6 when being executed by a processor.
Citation Information
Cited By
Cross-site scripting attack detection method and device
CN120675826A