Training method of machine-generated text detection model based on machine style optimization, machine-generated text detection method and device

Through the training method based on machine style optimization, the probability distribution of the detection model is adjusted to make it closer to the distribution of advanced generative models, which solves the problem of misalignment between the source model and the detection model in the existing technology, and significantly improves the accuracy of machine-generated text detection technology.

CN119272749BActive Publication Date: 2025-04-08武汉模态跃迁科技有限公司
View PDF 0 Cites 0 Cited by

Patent Information

Application Number
CN202411293516.X
Authority / Receiving Office
CN · China
Patent Type
Patents(China)
Current Assignee / Owner
Filing Date
2024-09-14
Publication Date
2025-04-08
Estimated Expiration
2044-09-14

AI Technical Summary

Technical Problem

When facing complex language models, the alignment between the source model and the detection model is reduced, resulting in poor accuracy of machine-generated text detection technology.

Method used

Through a training method based on machine style optimization, the probability distribution of the detection model is adjusted to make it closer to the distribution of advanced generative models. The method includes loading a pre-trained model, a word participle loading module, a sampling deviation analysis module and an output module, through which model training and detection is performed to improve the accuracy of the detection model.

Benefits of technology

It significantly improves the accuracy of machine-generated text detection technology, solves the problem of misalignment between the source model and the detection model, and improves the detection model's recognition ability of complex language models.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN119272749B_ABST
    Figure CN119272749B_ABST
Patent Text Reader

Abstract

The training method of the machine-generated text detection model disclosed in the present invention includes: using a model loading module to load a first pre-trained model, and using the loaded first pre-trained model as a first reference model and a first scoring model; using a word segmenter loading module to load the word segmenter of the first pre-trained model; using a sampling deviation analysis module to obtain the difference between the output of the first reference model and the output of the first scoring model, and then obtain a prediction result; and based on the original text, the real label initialized as None, and the degree of difference between the current prediction result of the model and the real label, the machine-generated text detection model is trained. The present invention solves the misalignment problem between the source model and the detection model in the existing zero-sample method, so that the alignment rate between the probability distribution of the source model and the detection model is improved, thereby significantly improving the accuracy of the machine-generated text detection technology.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] The present invention relates to the field of artificial intelligence technology, and in particular to a training method for a machine-generated text detection model based on machine style optimization, and a machine-generated text detection method and device. Background Art

[0002] With the rapid development of artificial intelligence technology, machine-generated texts are becoming more and more realistic and difficult to distinguish. While this technological advancement brings the convenience of automated writing and content generation, it also comes with the risk of spreading false information. Malicious actors can use generated texts to create fake news and forged social media posts, thereby influencing public opinion and social stability. Without effective detection methods, it will be difficult to meet these challenges and ensure the authenticity and reliability of information. Therefore, it is particularly important to explore and develop machine-generated text detection technology to protect the health and security of the information environment.

[0003] In the field of machine-generated text detection, zero-shot methods have shown excellent performance. This method uses a pre-trained language model to analyze the probability distribution of each token in the text. By comparing the log-probability difference between the original text and the perturbed version, the zero-shot method can effectively distinguish between human-generated and machine-generated text without annotating training data. Since the probability distribution of the detection model is highly similar to that of the source model, the zero-shot method has shown significant results in detection tasks.

[0004] However, existing zero-shot methods have some drawbacks that cannot be ignored:

[0005] The effectiveness of zero-shot methods is challenged when faced with more complex language models. Although early generative models rely on a small number of initial tokens to generate text, their detection models can accurately reflect the probability distribution of the source model, ensuring the effectiveness of zero-shot methods. However, modern language models usually go through an additional training phase so that the generated text not only conforms to human preferences, but also has a unique style. This uniqueness of style leads to a decrease in the alignment between the source model and the detection model, and differences in probability estimates, which ultimately weakens the effectiveness of zero-shot detection techniques. Summary of the invention

[0006] In response to the above defects or improvement needs of the prior art, the present invention provides a training method for a machine-generated text detection model based on machine style optimization, a machine-generated text detection method and a device, which aims to solve the misalignment problem between the source model and the detection model, which leads to the problem of poor accuracy of the existing machine-generated text detection technology.

[0007] To achieve the above object, according to one aspect of the present invention, a training method for a machine-generated text detection model based on machine style optimization is provided, wherein the machine-generated text detection model includes a model loading module, a word segmentation loading module, a sampling deviation analysis module and an output module, and the method includes:

[0008] Using a model loading module to load a first pre-trained model, and using the loaded first pre-trained model as a first reference model and a first scoring model;

[0009] Load the word segmenter of the first pre-trained model using the word segmenter loading module;

[0010] Using a sampling deviation analysis module to obtain a difference between the output of the first reference model and the output of the first scoring model based on the output of the first reference model, the output of the first scoring model, and the true label, wherein the output of the first reference model is an unnormalized original score of each possible output output by the first reference model based on the input original text, and the output of the first scoring model is an unnormalized original score of each possible output output by the first scoring model based on the input original text;

[0011] Input the output obtained by the sampling deviation analysis module into the output module to obtain the prediction result; and

[0012] The machine-generated text detection model is trained based on the original text, the real label initialized to None, and the degree of difference between the current prediction result of the model and the real label.

[0013] In one embodiment, using a model loading module to load a pre-trained model includes:

[0014] The model loading module uses an adaptive causal language model to obtain the first pre-trained model loaded into the specified device based on the input model name, device, and cache directory.

[0015] In one embodiment, using a word segmenter loading module to record a word segmenter of a pre-training module includes:

[0016] The word segmenter loading module uses an adaptive word segmenter model to obtain the word segmenter loaded into the specified device based on the input model name, data set, and cache directory.

[0017] In one embodiment, obtaining a difference between an output of the first reference model and an output of the first scoring model based on an output of the first reference model, an output of the first scoring model, and a true label using a sampling deviation analysis module includes:

[0018] The sampling bias analysis module adjusts the size of the output logits of the first scoring model and the first reference model to match them, wherein the output logits of the first scoring model is the original score of each possible output output by the first scoring model without normalization, and the output logits of the first reference model is the original score of each possible output output by the first reference model without normalization;

[0019] By performing logarithmic normalization processing on the output logits of the first scoring model, the logarithmic normalized probability of the first scoring model is obtained, and by performing normalization processing on the first reference model, the normalized probability of the first reference model is obtained;

[0020] Using the log-normalized probability of the first scoring model, remove the redundant dimensions to obtain the log-normalized probability of the first scoring model selected according to the true label; using the normalized probability of the reference model, calculate the weighted average and variance of the log-normalized probability of the first scoring model;

[0021] The mask ratio is set to 0, the second dimension data of the logarithmic probability selected by the first scoring model according to the true label is used as the length, and the product of the mask ratio and the length is calculated as the cut point 1 and the cut point 2;

[0022] Starting from trimming point 1, the mean of the logarithmic probability selected by the first scoring model according to the true label is calculated, and at the same time, the weighted mean and mean of the variance of the log-normalized probability of the scoring model are calculated for trimming point 2. The difference between the mean of the logarithmic probability selected by the first scoring model according to the true label and the weighted mean of the log-normalized probability of the scoring model is divided by the square root of the mean of the variance of the log-normalized probability of the first scoring model to obtain the sampling deviation value, which is the difference between the output of the first reference model and the output of the first scoring model.

[0023] In one embodiment, the machine-generated text detection model is trained based on the original text, the real label initialized to None, and the degree of difference between the current prediction result of the model and the real label, including:

[0024] Use the inverse mapping model tokenizer to tokenize the original text, return the input ID in tensor form, and transfer it to the specified device after padding and truncating. Convert the decoder input embedding to the specified device and repeat according to the shape of the inverse mapping input ID obtained after tokenizing the original text. Pass the obtained input ID and decoder input embedding into the inverse mapping model for forward propagation.

[0025] Get the last hidden state of the reverse prompt, adapt the last hidden state of the reverse prompt using the reverse prompt adapter, generate the reverse prompt embedding, and get the length of the reverse prompt embedding;

[0026] Use the first scoring model tokenizer to tokenize the model's output text, return it in tensor form, and fill it. Do not return the token type ID, and convert it to the specified device. Remove the first element of the input ID after the tokenization as the label to obtain the label.

[0027] Get the input embedding of the first scoring model;

[0028] Concatenate the generated reverse hint embedding with the input embedding of the first scoring model, construct the attention mask, and concatenate the tensor with all 1s with the marked attention mask;

[0029] Get the logits of the first scoring model, cut off the static prompt length plus the part after the reverse prompt is embedded, and set the logits of the first reference model as the logits of the first scoring model;

[0030] Determine whether the input ID after marking is consistent with the obtained label after removing the first element. If not, report an error.

[0031] Use the first reference model for forward propagation, obtain the logits of the reference model, and remove the last element;

[0032] The sampling bias analysis module is used to calculate the original loss value from the output logits and labels of the first reference model and the first scoring model;

[0033] Get the logits of the last token of the first scoring model, use the classifier to predict the logits of the last token, and get the predicted value;

[0034] Construct an output dictionary containing the original loss values ​​obtained using the sampling bias analysis module and the predicted values ​​obtained by the classifier;

[0035] Calculate the cross entropy loss using the original loss value obtained by the sampling bias analysis module and the passed label, and return the original loss value obtained by the sampling bias analysis module and the calculated cross entropy loss.

[0036] Based on the same inventive concept, the second aspect of the present invention provides a method for detecting machine-generated text, wherein the machine-generated text detection model includes a model loading module, a word segmentation loading module, a sampling deviation analysis module and an output module, and the method includes:

[0037] Using the model loading module to load the second pre-trained model, and using the loaded second pre-trained model as the second reference model and the second scoring model;

[0038] Load the word segmenter of the second pre-trained model using the word segmenter loading module;

[0039] Using the sampling deviation analysis module to obtain the difference between the output of the second reference model and the output of the second scoring model based on the output of the second reference model, the output of the second scoring model and the true label, wherein the output of the second reference model is the original score of each possible output of the second reference model based on the input text to be tested, and the output of the second scoring model is the original score of each possible output of the second scoring ...;

[0040] The output obtained by the sampling deviation analysis module is input into the output module to obtain the prediction result;

[0041] The machine-generated text detection model is a model obtained by using the training method for the machine-generated text detection model described in any one of claims 1 to 5.

[0042] Based on the same inventive concept, the third aspect of the present invention provides a training device for a machine-generated text detection model based on machine style optimization, wherein the machine-generated text detection model includes a model loading module, a word segmenter loading module, a sampling deviation analysis module and an output module, and the device includes:

[0043] A first pre-trained model loading module, used to load the first pre-trained model using the model loading module, and use the loaded first pre-trained model as a first reference model and a first scoring model;

[0044] A word segmenter loading module of the first pre-trained model, used to load the word segmenter of the first pre-trained model using the word segmenter loading module;

[0045] A first difference output module, used to obtain the difference between the output of the first reference model and the output of the first scoring model based on the output of the first reference model, the output of the first scoring model and the true label by using the sampling deviation analysis module, wherein the output of the first reference model is the original score of each possible output output by the first reference model based on the input original text without normalization, and the output of the first scoring model is the original score of each possible output output by the first scoring model based on the input original text without normalization;

[0046] A first prediction module, used to input the output obtained by the sampling deviation analysis module into the output module to obtain a prediction result; and

[0047] The forward propagation module is used to train the machine-generated text detection model based on the original text, the real label initialized as None, and the degree of difference between the current prediction result of the model and the real label.

[0048] Based on the same inventive concept, the fourth aspect of the present invention provides a machine-generated text detection device, wherein the machine-generated text detection model includes a model loading module, a word segmentation loading module, a sampling deviation analysis module and an output module, and the device includes:

[0049] A second pre-trained model loading module, used to load the second pre-trained model using the model loading module, and use the loaded second pre-trained model as a second reference model and a second scoring model;

[0050] A word segmenter loading module of the second pre-trained model, used to load the word segmenter of the second pre-trained model using the word segmenter loading module;

[0051] A second difference output module, used for obtaining the difference between the output of the second reference model and the output of the second scoring model based on the output of the second reference model, the output of the second scoring model and the true label by using the sampling deviation analysis module, wherein the output of the second reference model is the original score of each possible output output by the second reference model based on the input text to be tested without normalization, and the output of the second scoring model is the original score of each possible output output by the second scoring model based on the input text to be tested without normalization;

[0052] A second prediction module, used for inputting the output obtained by the sampling deviation analysis module into the output module to obtain a second prediction result of the text to be tested;

[0053] Wherein, the machine-generated text detection model is a model obtained by using the training device of the machine-generated text detection model described in claim 7.

[0054] Based on the same inventive concept, the fifth aspect of the present invention provides a computer-readable storage medium on which a computer program is stored. When the program is executed by a processor, it implements the training method of the machine-generated text detection model described in the first aspect or the machine-generated text detection method described in the second aspect.

[0055] Based on the same inventive concept, the sixth aspect of the present invention provides a computer device, including a memory, a processor, and a computer program stored in the memory and executable on the processor, wherein when the processor executes the program, the training method for the machine-generated text detection model described in the first aspect or the machine-generated text detection method described in the second aspect is implemented.

[0056] Compared with the prior art, the advantages and beneficial technical effects of the present invention are as follows:

[0057] Due to the proposed machine-style-based optimization of the machine-generated text detection model, it allows the probability distribution of the detection model to be adjusted to be closer to the distribution of advanced generation models. This method gradually adjusts the preferences of the detection model to the style choices commonly made by complex large language models, while maintaining sufficient versatility to be applicable to various text generation scenarios. Therefore, the present invention solves the misalignment problem between the source model and the detection model that occurs in the existing zero-shot method, so that the alignment rate between the probability distribution of the source model and the detection model is improved, thereby significantly improving the accuracy of machine-generated text detection technology. BRIEF DESCRIPTION OF THE DRAWINGS

[0058] In order to more clearly illustrate the embodiments of the present invention or the technical solutions in the prior art, the drawings required for use in the embodiments or the description of the prior art will be briefly introduced below. Obviously, the drawings described below are some embodiments of the present invention. For ordinary technicians in this field, other drawings can be obtained based on these drawings without paying creative work.

[0059] Figure 1 A flowchart of a training method for a machine-generated text detection model in an embodiment of the present invention;

[0060] Figure 2 A flowchart of a machine-generated text detection method in an embodiment of the present invention;

[0061] Figure 3 A structural block diagram of a training device for a machine-generated text detection model in an embodiment of the present invention;

[0062] Figure 4 It is a structural block diagram of a machine-generated text detection device in an embodiment of the present invention.

[0063] Figure 5 A framework diagram of a machine-generated text detection model in an embodiment of the present invention;

[0064] Figure 6 It is a detailed flow chart of the training method of the machine-generated text detection model in an embodiment of the present invention. DETAILED DESCRIPTION

[0065] The present invention provides a machine-generated text detection model based on machine style optimization and a training method thereof, which first obtains a GPT-J model, initializes a scoring model and a reference model and respective word segmenters based on the model to obtain a set of preprocessing models, then obtains a data set, divides the data set into a training set and a validation set, and uses the preprocessing model, the validation set, and the data set to fine-tune and evaluate the preprocessing model. The present invention can solve the problem of misalignment between the source model and the detection model in the machine-generated text detection technology based on zero-sample technology, thereby causing the problem of poor accuracy of the existing machine-generated text detection technology.

[0066] In order to make the purpose, technical solution and advantages of the embodiments of the present invention clearer, the technical solution in the embodiments of the present invention will be clearly and completely described below in conjunction with the drawings in the embodiments of the present invention. Obviously, the described embodiments are 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 ordinary technicians in this field without creative work are within the scope of protection of the present invention.

[0067] Embodiment 1

[0068] The present invention discloses a training method for a machine-generated text detection model based on machine style optimization, wherein the machine-generated text detection model includes a model loading module, a word segmentation loading module, a sampling deviation analysis module and an output module, see Figure 1 , the method comprising:

[0069] S110: Using a model loading module to load a first pre-trained model, and using the loaded first pre-trained model as a first reference model and a first scoring model;

[0070] S120: Load the word segmenter of the first pre-trained model using a word segmenter loading module;

[0071] S130: using the sampling deviation analysis module to obtain the difference between the output of the first reference model and the output of the first scoring model based on the output of the first reference model, the output of the first scoring model, and the true label, wherein the output of the first reference model is the original score of each possible output output by the first reference model based on the input original text without normalization, and the output of the first scoring model is the original score of each possible output output by the first scoring model based on the input original text without normalization;

[0072] S140: inputting the output obtained by the sampling deviation analysis module into the output module to obtain a prediction result; and

[0073] The machine-generated text detection model is trained based on the original text, the real label initialized to None, and the degree of difference between the current prediction result of the model and the real label.

[0074] in, Figure 5 A framework diagram of a machine-generated text detection model in an embodiment of the present invention.

[0075] In one embodiment, the model loading module specifically uses an adaptive causal language model to load the first pre-trained model. The input of the model loading module is the model name, device, and cache directory, and the output is the pre-trained model loaded into the specified device.

[0076] The word segmenter loading module specifically adopts an adaptive word segmenter model to load the word segmenter of the first pre-trained model. The input of the word segmenter loading module is the model name, data set, and cache directory, and the output is the word segmenter loaded into the specified device.

[0077] The sampling deviation analysis module is a module used to compare the differences between the outputs of the reference model and the scoring model. The inputs of the sampling deviation analysis module include the unnormalized raw scores of each possible output output by the reference model, the unnormalized raw scores of each possible output output by the scoring model, and the true label of the text. More specifically, the true label content is "machine-generated text" or "human text", which is used to describe the true category of the input text. The output of the sampling deviation analysis module is a sampling deviation value used to quantify the output difference between the reference model and the scoring model and the log-likelihood sum calculated by the scoring model based on the true label of the text. More specifically, the log-likelihood sum represents the model's predictive ability for a given label, and a higher log-likelihood value indicates that the model is more confident in predicting the correct label.

[0078] The forward propagation module is used to perform the forward propagation process. The input is the text and the real label initialized to None, and the output is the model prediction value and cross entropy loss value obtained after the unnormalized probability output is processed by the softmax function.

[0079] In one embodiment, the sampling deviation analysis module first adjusts the size of the logits output by the first scoring model and the first reference model to match as needed. Then, by log-normalizing the output logits of the first scoring model, the log-normalized probability of the first scoring model is obtained, and by normalizing the first reference model, the normalized probability of the first reference model is obtained. Then, using the log-normalized probability of the first scoring model, redundant dimensions are removed to obtain the logarithmic probability selected by the first scoring model according to the true label. Subsequently, using the normalized probability of the first reference model, the weighted average and variance of the log-normalized probability of the first scoring model are calculated. Next, the mask ratio is set to 0, the second dimension data of the logarithmic probability selected by the first scoring model according to the true label is used as the length, and the product of the mask ratio and the length is calculated as the cut point 1 and the cut point 2. Finally, starting from trimming point 1, the mean of the logarithmic probability selected by the first scoring model according to the true label is calculated, and the weighted mean and mean of the variance of the log-normalized probability of the scoring model are calculated for trimming point 2. The difference between the mean of the logarithmic probability selected by the first scoring model according to the true label and the weighted mean of the log-normalized probability of the scoring model is divided by the square root of the mean of the variance of the log-normalized probability of the scoring model to obtain the sampling deviation value.

[0080] Based on the original text, the real label initialized as None, and the difference between the current prediction result of the model and the real label, the machine-generated text detection model is trained, including:

[0081] (S1) Use the inverse mapping model tokenizer to tokenize the text, return the input ID in the form of a tensor, and pad and truncate it to a maximum length of 20, and transfer it to the specified device.

[0082] (S2) Convert the decoder input embedding to the specified device and repeat according to the shape of the inverse mapping input ID obtained in step (S1).

[0083] (S3) The input ID obtained in step (S1) and the decoder input obtained in step (S2) are embedded into the inverse mapping model for forward propagation.

[0084] (S4) Get the last hidden state of the reverse hint and convert it into floating point 32 format.

[0085] (S5) Adapt the last hidden state of the reverse prompt obtained in step (S4) using the reverse prompt adapter, retain the key information in the last hidden state and convert it into a suitable embedding representation to generate a reverse prompt embedding.

[0086] (S6) Obtain the length of the reverse hint embedding.

[0087] (S7) Use the scoring model tokenizer to tokenize the output text of the model, return it in tensor form, and fill it in. Do not return the token type ID and convert it to the specified device.

[0088] (S8) The first element of the input ID after the mark is removed as a label. Specifically, the label is a label of the target object related to the input ID after the mark, which is used for subsequent calculation of the loss function.

[0089] (S9) Obtain input embedding for the scoring model.

[0090] (S10) Concatenate the reverse prompt embedding generated in step (S5) and the input embedding of the scoring model obtained in step (S9), maintaining the data type of the input embedding.

[0091] (S11) Construct an attention mask and concatenate the tensor with all 1s and the marked attention mask.

[0092] Preferably, step (S11) comprises the following sub-steps:

[0093] (S11-1) Determine the actual length of the input sequence based on the length of the reverse hint embedding obtained in step (S6) or the length of the input ID after being labeled in step (S8).

[0094] (S11-2) Initialize the mask and create a tensor with all 1s and the same size as the maximum length of the input sequence.

[0095] (S11-3) According to the actual input length, the position corresponding to the padding part in the mask is set to 0.

[0096] (S11-4) Concatenate the tensor with all 1s obtained in step (S11-2) with the marked attention mask obtained in step (S11-3) to form the final attention mask.

[0097] (S12) Obtain the logits of the scoring model, and cut off the static prompt length plus the part after the reverse prompt embedding.

[0098] (S13) The logits of the reference model are set as the logits of the scoring model.

[0099] (S14) Determine whether the input ID after marking obtained in step (S7) minus the first element is consistent with the label obtained in step (S8). If not, report an error.

[0100] (S15) Perform forward propagation using the reference model, obtain logits, and remove the last element.

[0101] (S16) The sampling bias analysis module is used to calculate the logits and labels of the reference model and the scoring model to obtain the original loss value.

[0102] (S17) Get the logits of the last token of the scoring model.

[0103] (S18) Use the classifier to predict the logits of the last token and obtain the predicted value.

[0104] (S19) Construct an output dictionary containing the original loss value obtained in step (S16) and the predicted value obtained in (S18).

[0105] (S20) Using the original loss value obtained in step (S16) and the input label, the cross entropy loss is calculated.

[0106] (S21) Return the original loss value obtained in step (S16) and the predicted value obtained in step (S20).

[0107] The method of the present invention is described below by means of specific examples.

[0108] The embodiment of the present invention provides a method for training a machine-generated text detection model based on machine style optimization, see Figure 6 , including the following steps:

[0109] (1) Obtain the GPT-J model and download the model file to a local directory.

[0110] (2) Use the pre-trained model obtained in step (1) as the scoring model and reference model, initialize its word segmenter and model respectively, and define the loss function and forward propagation function to obtain a complete model ready for training and verification.

[0111] (3) Obtain a data set, divide 2686 data items in the data set into a training set, and divide 672 data items in the data set into a validation set.

[0112] (4) Using the training set obtained in step (3), randomly select 1,000 data points to obtain a training subset.

[0113] (5) Using the preprocessing model obtained in step (2), the validation set obtained in step (3), and the training subset obtained in step (4), fine-tune and evaluate the preprocessing model to obtain evaluation data.

[0114] It should be noted that the forward propagation function is a broader term that refers to the process by which the model calculates the output after receiving the input through various layers and modules (forward propagation process). It involves the extraction, fusion and final generation of prediction results of features. The main task of the forward propagation function is to pass the input data through the network structure of the model to obtain the output of the model.

[0115] The loss function is a specific term that refers to a part of the forward propagation process used to calculate the difference (loss) between the model output and the true label. In this invention, it refers to the cross entropy loss function, whose main task is to evaluate the error between the model's prediction results and the true label so as to perform backpropagation and parameter update during the training process.

[0116] Therefore, although both involve the forward propagation process of the model, the "forward propagation function" is a broader concept, while the "forward loss function" focuses on the specific implementation of calculating the loss.

[0117] Preferably, step (2) comprises the following sub-steps:

[0118] (2-1) The model obtained in step (1) is used as a scoring model and loaded into a model loading module to obtain a pre-trained scoring model loaded into a specified device.

[0119] (2-2) The model obtained in step (1) is used as a reference model and loaded into the model loading module to obtain a pre-trained reference model loaded into the specified device.

[0120] (2-3) A configuration dictionary is created as an attribute that maps integer labels to string labels.

[0121] (2-4) Obtain the T5 model and word segmenter, and load them into the model loading module and the word segmenter loading module respectively to obtain an inverse mapping model and its word segmenter loaded into the specified device.

[0122] (2-5) Create an InverseTokenAdapter object as a reverse token adapter to convert the input feature vector from dimension 512 to dimension 2560.

[0123] (2-6) Set the maximum reverse prompt length to 20.

[0124] (2-7) Set the static prompt length to 0.

[0125] (2-8) Use torch.randn to generate a random tensor with a shape of (20,512), where 20 is the maximum reverse prompt length obtained in step (2-6). The elements in this tensor are randomly drawn from the standard normal distribution. Next, use nn.Parameter to convert the tensor into a trainable parameter so that it can be optimized during model training and used as the decoder input embedding of the model.

[0126] (2-9) Use the model obtained in step (1) as the scoring model, set the data set to 'xsum', and load the tokenizer loading module to obtain a scoring model tokenizer loaded into the specified device.

[0127] (2-10) Use the model obtained in step (1) as the reference model, set the data set to 'xsum', and load the tokenizer loading module to obtain a reference model tokenizer loaded into the specified device.

[0128] (2-11) Initialize the sampling deviation analysis module.

[0129] (2-12) creates a linear layer as a classifier with an input dimension of 50257 and an output dimension of 2, and loads it to the specified device.

[0130] (2-13) The inverse mapping model obtained in step (2-4) is set to not require gradient calculation.

[0131] Preferably, step (5) comprises the following sub-steps:

[0132] (5-1) This step is the model evaluation module, which uses the validation set obtained in step (3) to evaluate the preprocessing model obtained in step (2).

[0133] (5-2) Combine the training subset obtained in step (4) and the validation set obtained in step (3) into a data list.

[0134] (5-3) Get the initialized recorder, data loader, total number of epochs, Adam optimizer, cosine annealing learning rate scheduler, and gradient scaler.

[0135] (5-4) Move the model obtained in step (2) to the specified device.

[0136] (5-5) Set the cumulative value of gradient steps. The default value is 1.

[0137] (5-6) Initialize the epoch loss value list to store the loss value of each epoch.

[0138] (5-7) Initialize iteration counter i to 0.

[0139] (5-8) Initialize the loss tensor and move it to the specified device.

[0140] (5-9) Initialize two empty lists to store the original text deviation values ​​and the generated text deviation values.

[0141] (5-10) Initialize the epoch counter e to 0.

[0142] (5-11) Clear the gradient of the Adam optimizer obtained in step (5-6).

[0143] (5-12) Using the data loader obtained in step (5-4), obtain text data in batches.

[0144] (5-13) Update the learning rate scheduler obtained in step (5-7).

[0145] (5-14) Start automatic mixed precision training, use the text data obtained in step (5-12) to forward propagate through the model to obtain the output of the model, then add the original bias value in the model output to the original text bias value list obtained in step (5-9), add the sampled bias value in the model output to the generated text bias value list obtained in step (5-9), and finally divide the loss value of the current batch by the cumulative value of the gradient steps obtained in step (5-5), and add it to the loss tensor obtained in step (5-8).

[0146] (5-15) Determine whether the iteration counter i+1 has reached the cumulative value of the gradient steps in step (5-5). If so, proceed to step (5-16); if not, proceed to step (5-17).

[0147] (5-16) Perform the gradient descent step.

[0148] (5-17) Add the updated loss tensor to the epoch loss value list

[0149] (5-18) Increase the iteration counter obtained in step (5-7) by 1.

[0150] (5-19) Determine whether all text data in the text loader updated in step (5-12) has been loaded. If so, proceed to step (5-20); if not, return to step (5-12).

[0151] (5-20) Using the area calculation module under the ROC curve of step (5-1-8), the original text deviation value list and the generated text deviation value list updated in step (5-14) are input to obtain the area under the ROC curve (ROCAUC) of the current model.

[0152] (5-21) Using the area calculation module under the precision-recall curve of step (5-1-9), input the original text deviation value list and the generated text deviation value list updated in step (5-14) to obtain the area under the precision-recall curve (PR AUC) of the current model.

[0153] (5-22) Use the epoch loss value list updated in step (5-17) to obtain the average loss value of the current epoch.

[0154] (5-23) Using the recorder obtained in step (5-3), write the epoch average loss value obtained in the current step (5-22), the ROC AUC obtained in step (5-20), the PR AUC obtained in step (5-21), the average value of the original text deviation value list obtained in step (5-14), the standard deviation of the original text deviation value list obtained in step (5-14), the average value of the generated text deviation value list obtained in step (5-14), and the standard deviation of the generated text deviation value list obtained in step (5-14) to TensorBoard.

[0155] (5-24) Reset the original text training cycle sampling deviation value list and the training text training cycle sampling deviation value list obtained in step (5-14).

[0156] (5-25) Determine whether the epoch counter e+1 has reached the number of epochs required to verify and save the model. If so, proceed to step (5-26). If not, proceed to step (5-27).

[0157] (5-26) Call the evaluation module (5-1) of the training model to obtain the evaluation results of the current model's performance on the verification data set.

[0158] (5-27) Using the recorder obtained in step (5-3) and the evaluation result obtained in step (5-26), write the evaluation result of the current epoch to TensorBoard.

[0159] (5-28) Save the fine-tuned model to a directory.

[0160] (5-29) Increase the epoch counter e obtained in step (5-15) by 1, and then determine whether e reaches the total number of training epochs obtained in step (5-3). If so, proceed to step (5-30); if not, return to step (5-10).

[0161] (5-30) Close the recorder in step (5-3).

[0162] (5-31) Returns the fine-tuned model.

[0163] (5-32) Call the evaluation module (5-1) of model training to obtain the evaluation results of the current model's performance on the verification data set.

[0164] Preferably, step (5-1) is a model evaluation module, which includes the following sub-steps:

[0165] (5-1-1) Move the preprocessed model obtained in step (2) to the specified device and set the model to evaluation mode.

[0166] (5-1-2) Initialize the loss value to 0.

[0167] (5-1-3) Create a data loader to load the validation set data obtained in step (3) in batches.

[0168] (5-1-4) Initialize two empty lists to store the original text deviation values ​​and the generated text deviation values.

[0169] (5-1-5) Use a context manager so that gradients are not calculated within the context.

[0170] (5-1-6) The data loader obtained in step (5-1-3) obtains text data batch by batch, and passes the data to the model for prediction, then accumulates the loss value of each batch to the total loss value obtained in step (5-1-2), and adds the original text deviation value and generated text deviation value of each batch to the original text deviation value list and generated text deviation value list obtained in step (5-1-4), respectively.

[0171] (5-1-7) The total loss value updated in step (5-1-6) is divided by the length of the data loader to obtain the average loss value.

[0172] (5-1-8) This step is the area calculation module under the ROC curve. The input is the original text deviation value list and the generated text deviation value list, and the output is the area under the ROC curve. Get the original text deviation value list (Co) and the generated text deviation value list (Cs) updated in step (5-1-6). First, create a list of length Co, in which all elements are 0, representing the label of the real data, and at the same time create a list of length Cs, in which all elements are 1, representing the label of the generated data, and then connect the two lists to obtain a real label list. Then use the roc_curve function that draws the ROC curve, input the real label list and its length, and get the true positive rate and false positive rate. Finally, use the auc function, input the true positive rate and false positive rate to get the area under the ROC curve (ROC AUC).

[0173] (5-1-9) This step is the area calculation module under the precision-recall curve. The input is the original text deviation value list and the generated text deviation value list, and the output is the area under the precision-recall curve. Get the original text deviation value list (Co) and the generated text deviation value list (Cs) updated in step (5-1-6). First, create a list of length Co, in which all elements are 0, representing the label of the real data, and at the same time create a list of length Cs, in which all elements are 1, representing the label of the generated data, and then connect the two lists to obtain a real label list. Then use the precision_recall_curve function for calculating the precision-recall curve, input the real label list and its length, and obtain the precision and recall. Finally, use the auc function, input the precision and recall, to obtain the area under the precision-recall curve (PR AUC).

[0174] Preferably, step (5-3) comprises the following sub-steps:

[0175] (5-3-1) Get the current time and format it into a string.

[0176] (5-3-2) Initialize a TensorBoard logger object and set the log path according to the time string obtained in step (5-3-1).

[0177] (5-3-3) Create a data loader, set the batch size to 1, use the training subset obtained in step (4) to load a batch of data, and perform a random shuffle operation.

[0178] (5-3-4) Set the total number of training epochs.

[0179] (5-3-5) Initialize the Adam optimizer to update the model parameters and set the learning rate. The default value is 5e-5.

[0180] (5-3-6) Initialize the cosine annealing learning rate scheduler, which is used to dynamically adjust the learning rate. The period is set to the product of the length of the data loader obtained in step (5-3-3) and the total number of epochs obtained in step (5-3-4).

[0181] (5-3-7) Initialize the GradScaler gradient scaler for automatic gradient scaling.

[0182] Preferably, step (5-16) comprises the following sub-steps:

[0183] (5-16-1) Use the gradient scaler in step (5-3) and the loss tensor updated in step (5-14), calculate the gradient of the loss and perform backpropagation.

[0184] (5-16-2) Use the gradient scaler in step (5-3) and the Adam optimizer in step (5-3) to update the parameters of the model and execute the optimizer steps.

[0185] (5-16-3) Clear the gradient of the Adam optimizer in step (5-3).

[0186] (5-16-4) Update the scaling factor of the gradient scaler in step (5-3).

[0187] (5-16-5) Use the recorder in step (5-3) to write the loss updated in step (5-14) to TensorBoard for visualizing the loss during training.

[0188] (5-16-6) Add the loss tensor updated in step (5-14) to the epoch loss value list in step (5-6).

[0189] (5-16-7) Reset the loss tensor and move it to the specified device.

[0190] In general, the above technical solutions conceived by the present invention can achieve the following beneficial effects compared with the prior art:

[0191] (1) Since the present invention is based on a machine style optimization detection model, it allows the probability distribution of the detection model to be adjusted to be closer to the distribution of advanced generative models. This method gradually adjusts the preferences of the detection model to the style choices commonly made by complex large language models, while maintaining sufficient versatility to be applicable to various text generation scenarios. Therefore, the present invention solves the misalignment problem between the source model and the detection model that occurs in existing zero-shot methods, thereby improving the alignment rate between the probability distributions of the source model and the detection model, thereby significantly improving the accuracy of machine-generated text detection technology.

[0192] (2) In model training, the pre-trained GPT-J model and T5 model are used for initialization at the beginning of training, and fine-tuned to adapt to specific tasks. This method can usually improve the performance of the model on specific tasks because the pre-trained model has learned rich language features. In addition, the training process adopts automatic mixed precision training (Automatic Mixed Precision), which mixes FP16 and FP32 precision for floating-point calculations during training to reduce computational and memory overhead, thereby accelerating the training process and reducing video memory usage. In the text detection model, it is necessary to define the Gradscaler gradient scaler and use the context manager to control mixed precision training before model training. The gradient scaler prevents the gradient underflow problem caused by insufficient precision when performing low-precision calculations, thereby effectively improving the stability and accuracy of training, while retaining the speed and memory advantages of low-precision calculations. The context manager is responsible for automatically selecting the most suitable calculation precision during training, ensuring the accuracy of the calculation while reducing memory usage and calculation time. In addition, by setting the gradient step accumulation and using the cosine annealing learning rate scheduler, the model can adjust the learning rate more effectively during training, thereby improving the convergence speed and stability.

[0193] (3) This method comprehensively evaluates model performance by defining specific loss functions and evaluation indicators, rather than relying solely on simple loss values. The calculation of the loss function is divided into two parts. First, the sampling bias analysis module calculates the sampling difference and obtains the original loss value through the logits and labels of the reference model and the scoring model. This module uses the log_softmax and softmax functions to calculate the log probability and probability value of the predicted distribution and the reference distribution, respectively. Subsequently, the difference between the two distributions is measured by calculating the log likelihood, the mean and variance of the reference distribution, thereby obtaining the original loss value of the evaluation model on a specific sample. Secondly, the cross entropy loss is calculated during the forward propagation of the model, and the cross entropy between the predicted probability distribution and the true label is measured to evaluate the difference between the model's predicted probability distribution and the true label.

[0194] Evaluation metrics include ROC-AUC, PR-AUC, and average loss. ROC-AUC is used to measure the ability of the model to distinguish between positive and negative samples. The closer its value is to 1, the better the model's ability to distinguish. This metric is calculated by the roc_auc_score function based on the true labels of all batches and the predicted positive class probabilities. PR-AUC measures the trade-off between precision and recall. First, the precision and recall curves are calculated, and then the PR-AUC value is calculated by the AUC function. Average loss is the average of the loss function values. It is used to measure the deviation between the prediction and the true label. It is calculated by accumulating the loss values ​​of each batch and taking the average. The entire evaluation process ensures that the data loader is initialized correctly, the batch data format matches the model output, the model and data are calculated on the same device, and the model output and metric calculation are handled correctly. This meticulous evaluation method can more comprehensively reflect the performance of the model in real application scenarios.

[0195] The application of these loss functions and evaluation metrics in model training is significantly different from traditional methods. Traditional loss functions, such as mean squared error (MSE), usually only focus on the direct difference between the model output and the actual label. The sampling bias analysis module introduced in this method calculates the difference between the predicted distribution and the reference distribution, taking into account the log probability and variance of the distribution, so as to capture the subtle differences in the model on the sample. In terms of evaluation metrics, traditional evaluation methods often only focus on a single metric such as accuracy or error rate. In contrast, ROC-AUC and PR-AUC provide a comprehensive evaluation of the model's ability to distinguish between positive and negative samples and the trade-off between precision and recall, which can more comprehensively reflect the performance of the model in different scenarios. ROC-AUC measures the classification ability of the model, while PR-AUC focuses on the performance of the classifier when dealing with imbalanced data sets. These metrics can more comprehensively reflect the stability and consistency of the model during training.

[0196] Embodiment 2

[0197] Based on the same inventive concept, this embodiment discloses a machine-generated text detection method, wherein the machine-generated text detection model includes a model loading module, a word segmentation loading module, a sampling deviation analysis module and an output module, see Figure 2 , the method comprising:

[0198] S210: Loading a second pre-trained model using a model loading module, and using the loaded second pre-trained model as a second reference model and a second scoring model;

[0199] S220: Load the word segmenter of the second pre-trained model using a word segmenter loading module;

[0200] S230: using the sampling deviation analysis module to obtain the difference between the output of the second reference model and the output of the second scoring model based on the output of the second reference model, the output of the second scoring model and the true label, wherein the output of the second reference model is the original score of each possible output output by the second reference model based on the input text to be tested without normalization, and the output of the second scoring model is the original score of each possible output output by the second scoring model based on the input text to be tested without normalization;

[0201] S240: inputting the output obtained by the sampling deviation analysis module into the output module to obtain a prediction result;

[0202] The machine-generated text detection model is a model obtained by using the training method of the machine-generated text detection model described in Example 1.

[0203] Since the method introduced in the second embodiment of the present invention is a method implemented by the model obtained by the training method of the machine-generated text detection model in the first embodiment of the present invention, those skilled in the art can understand the specific implementation and application of the method based on the method introduced in the first embodiment of the present invention, so it is not repeated here. All implementations and applications based on the model obtained by the method in the first embodiment of the present invention belong to the scope of protection of the present invention.

[0204] Embodiment 3

[0205] Based on the same inventive concept, the present invention provides a training device for a machine-generated text detection model based on machine style optimization, wherein the machine-generated text detection model includes a model loading module, a word segmentation loading module, a sampling deviation analysis module and an output module, see Figure 3 , the device comprises:

[0206] A first pre-trained model loading module 301 is used to load a first pre-trained model using a model loading module, and use the loaded first pre-trained model as a first reference model and a first scoring model;

[0207] A word segmenter loading module 302 of the first pre-trained model, used to load the word segmenter of the first pre-trained model using the word segmenter loading module;

[0208] A first difference output module 303, used to obtain the difference between the output of the first reference model and the output of the first scoring model based on the output of the first reference model, the output of the first scoring model and the true label by using the sampling deviation analysis module, wherein the output of the first reference model is the original score of each possible output output by the first reference model based on the input original text without normalization, and the output of the first scoring model is the original score of each possible output output by the first scoring model based on the input original text without normalization;

[0209] A first prediction module 304, configured to input the output obtained by the sampling deviation analysis module into an output module to obtain a prediction result; and

[0210] The forward propagation module 305 is used to train the machine-generated text detection model based on the original text, the real label initialized to None, and the degree of difference between the current prediction result of the model and the real label.

[0211] Since the device introduced in the third embodiment of the present invention is a device used to implement the training method of the machine-generated text detection model in the first embodiment of the present invention, based on the method introduced in the first embodiment of the present invention, the person skilled in the art can understand the specific structure and deformation of the device, so it is not repeated here. All devices used in the method in the first embodiment of the present invention belong to the scope of protection of the present invention.

[0212] Embodiment 4

[0213] Based on the same inventive concept, the present invention provides a machine-generated text detection device, wherein the machine-generated text detection model includes a model loading module, a word segmentation loading module, a sampling deviation analysis module and an output module, see Figure 4 , the device comprises:

[0214] A second pre-trained model loading module 401 is used to load the second pre-trained model using the model loading module, and use the loaded second pre-trained model as the second reference model and the second scoring model;

[0215] A word segmenter loading module 402 of the second pre-trained model, used to load the word segmenter of the second pre-trained model using the word segmenter loading module;

[0216] A second difference output module 403, used to obtain the difference between the output of the second reference model and the output of the second scoring model based on the output of the second reference model, the output of the second scoring model and the true label by using the sampling deviation analysis module, wherein the output of the second reference model is the original score of each possible output output by the second reference model based on the input test text without normalization, and the output of the second scoring model is the original score of each possible output output by the second scoring model based on the input test text without normalization;

[0217] The second prediction module 404 is used to input the output obtained by the sampling deviation analysis module into the output module to obtain a second prediction result of the text to be tested;

[0218] The machine-generated text detection model is a model obtained by the training device of the machine-generated text detection model in the second embodiment.

[0219] Since the device introduced in the fourth embodiment of the present invention is a device used to implement the machine-generated text detection method in the second embodiment of the present invention, based on the method introduced in the first embodiment of the present invention, the person skilled in the art can understand the specific structure and deformation of the device, so it is not repeated here. All devices used in the method in the second embodiment of the present invention belong to the scope of protection of the present invention.

[0220] Embodiment 5

[0221] Based on the same inventive concept, the present invention further provides a computer-readable storage medium on which a computer program is stored. When the program is executed by a processor, the method described in the first embodiment is implemented.

[0222] Since the computer-readable storage medium introduced in the fifth embodiment of the present invention is a computer-readable storage medium used to implement the training method of the machine-generated text detection model in the first embodiment of the present invention or the machine-generated text detection method in the second embodiment, based on the method introduced in the first embodiment of the present invention, those skilled in the art can understand the specific structure and deformation of the computer-readable storage medium, so it is not repeated here. All computer-readable storage media used in the methods of the first or second embodiments of the present invention belong to the scope of protection of the present invention.

[0223] Embodiment 6

[0224] The present invention also provides a computer device, including a memory, a processor, and a computer program stored in the memory and executable on the processor, wherein the processor implements the method described in Embodiment 1 when executing the program.

[0225] Since the computer device introduced in the fourth embodiment of the present invention is a computer device used to implement the training method of the machine-generated text detection model in the first embodiment of the present invention or the machine-generated text detection method in the second embodiment, based on the method introduced in the first embodiment of the present invention, the person skilled in the art can understand the specific structure and deformation of the computer device, so it is not repeated here. All computer devices used in the methods of the first or second embodiments of the present invention belong to the scope of protection of the present invention.

[0226] Those skilled in the art will appreciate that embodiments of the present invention may be provided as methods, systems, or computer program products. Therefore, the present invention may take the form of a complete hardware embodiment, a complete software embodiment, or an embodiment combining software and hardware. Moreover, the present invention may take the form of a computer program product implemented on one or more computer-usable storage media (including but not limited to disk storage, CD-ROM, optical storage, etc.) containing computer-usable program code.

[0227] The present invention is described with reference to flowcharts and / or block diagrams of methods, devices (systems), and computer program products according to embodiments of the present invention. It should be understood that each process and / or block in the flowchart and / or block diagram, as well as the combination of processes and / or blocks in the flowchart and / or block diagram, can be implemented by computer program instructions. These computer program instructions can be provided to a processor of a general-purpose computer, a special-purpose computer, an embedded processor, or other programmable data processing device to produce a machine, so that the instructions executed by the processor of the computer or other programmable data processing device generate instructions for implementing the processes in the flowchart and / or block diagram. Figure 1 A process or multiple processes and / or boxes Figure 1 A device that provides the functions specified in a block or multiple blocks.

[0228] Although preferred embodiments of the present invention have been described, additional changes and modifications may be made to these embodiments by those skilled in the art once the basic creative concepts are known. Therefore, the appended claims are intended to be interpreted as including the preferred embodiments and all changes and modifications that fall within the scope of the present invention. Obviously, those skilled in the art may make various changes and modifications to the embodiments of the present invention without departing from the spirit and scope of the embodiments of the present invention. Thus, if these modifications and variations of the embodiments of the present invention fall within the scope of the claims of the present invention and their equivalents, the present invention is also intended to include these modifications and variations.

Claims

1. A training method for a machine-generated text detection model based on machine style optimization, characterized in that: in, The machine-generated text detection model includes a model loading module, a word segmenter loading module, a sampling deviation analysis module and an output module, and the method includes: Using a model loading module to load a first pre-trained model, and using the loaded first pre-trained model as a first reference model and a first scoring model; Load the word segmenter of the first pre-trained model using the word segmenter loading module; Using a sampling deviation analysis module to obtain a difference between the output of the first reference model and the output of the first scoring model based on the output of the first reference model, the output of the first scoring model, and the true label, wherein the output of the first reference model is an unnormalized original score of each possible output output by the first reference model based on the input original text, and the output of the first scoring model is an unnormalized original score of each possible output output by the first scoring model based on the input original text; Input the output obtained by the sampling deviation analysis module into the output module to obtain the prediction result; and The machine-generated text detection model is trained based on the original text, the real label initialized to None, and the degree of difference between the current prediction result of the model and the real label.

2. The method for training a machine-generated text detection model as claimed in claim 1, characterized in that: Use the model loading module to load the pre-trained model, including: The model loading module uses an adaptive causal language model to obtain the first pre-trained model loaded into the specified device based on the input model name, device, and cache directory.

3. The training method of a machine-generated text detection model as claimed in claim 1, characterized in that: Use the word segmenter loading module to record the word segmenter of the pre-training module, including: The word segmenter loading module uses an adaptive word segmenter model to obtain the word segmenter loaded into the specified device based on the input model name, data set, and cache directory.

4. The method for training a machine-generated text detection model as claimed in claim 1, wherein: The sampling deviation analysis module is used to obtain the difference between the output of the first reference model and the output of the first scoring model based on the output of the first reference model, the output of the first scoring model, and the true label, including: The sampling bias analysis module adjusts the size of the output logits of the first scoring model and the first reference model to match them, wherein the output logits of the first scoring model is the original score of each possible output output by the first scoring model without normalization, and the output logits of the first reference model is the original score of each possible output output by the first reference model without normalization; By performing logarithmic normalization processing on the output logits of the first scoring model, the logarithmic normalized probability of the first scoring model is obtained, and by performing normalization processing on the first reference model, the normalized probability of the first reference model is obtained; Using the log-normalized probability of the first scoring model, remove the redundant dimensions to obtain the log-normalized probability of the first scoring model selected according to the true label; using the normalized probability of the reference model, calculate the weighted average and variance of the log-normalized probability of the first scoring model; The mask ratio is set to 0, the second dimension data of the logarithmic probability selected by the first scoring model according to the true label is used as the length, and the product of the mask ratio and the length is calculated as the cut point 1 and the cut point 2; Starting from trimming point 1, the mean of the logarithmic probability selected by the first scoring model according to the true label is calculated, and at the same time, the weighted mean and mean of the variance of the log-normalized probability of the scoring model are calculated for trimming point 2. The difference between the mean of the logarithmic probability selected by the first scoring model according to the true label and the weighted mean of the log-normalized probability of the scoring model is divided by the square root of the mean of the variance of the log-normalized probability of the first scoring model to obtain the sampling deviation value, which is the difference between the output of the first reference model and the output of the first scoring model.

5. The method for training a machine-generated text detection model as claimed in claim 1, wherein: Based on the original text, the real label initialized as None, and the difference between the current prediction result of the model and the real label, the machine-generated text detection model is trained, including: Use the inverse mapping model tokenizer to tokenize the original text, return the input ID in tensor form, and transfer it to the specified device after padding and truncating. Convert the decoder input embedding to the specified device and repeat according to the shape of the inverse mapping input ID obtained after tokenizing the original text. Pass the obtained input ID and decoder input embedding into the inverse mapping model for forward propagation. Get the last hidden state of the reverse prompt, adapt the last hidden state of the reverse prompt using the reverse prompt adapter, generate the reverse prompt embedding, and get the length of the reverse prompt embedding; Use the first scoring model tokenizer to tokenize the model's output text, return it in tensor form, and fill it. Do not return the token type ID, and convert it to the specified device. Remove the first element of the input ID after the tokenization as the label to obtain the label. Get the input embedding of the first scoring model; Concatenate the generated reverse hint embedding with the input embedding of the first scoring model, construct the attention mask, and concatenate the tensor with all 1s with the marked attention mask; Get the logits of the first scoring model, cut off the static prompt length plus the part after the reverse prompt is embedded, and set the logits of the first reference model as the logits of the first scoring model; Determine whether the input ID after marking is consistent with the obtained label after removing the first element. If not, report an error. Use the first reference model for forward propagation, obtain the logits of the reference model, and remove the last element; The sampling bias analysis module is used to calculate the original loss value from the output logits and labels of the first reference model and the first scoring model; Get the logits of the last token of the first scoring model, use the classifier to predict the logits of the last token, and get the predicted value; Construct an output dictionary containing the original loss values ​​obtained using the sampling bias analysis module and the predicted values ​​obtained by the classifier; Calculate the cross entropy loss using the original loss value obtained by the sampling bias analysis module and the passed label, and return the original loss value obtained by the sampling bias analysis module and the calculated cross entropy loss.

6. A method for detecting machine-generated text, characterized in that: The machine-generated text detection model includes a model loading module, a word segmenter loading module, a sampling deviation analysis module and an output module, and the method includes: Using the model loading module to load the second pre-trained model, and using the loaded second pre-trained model as the second reference model and the second scoring model; Load the word segmenter of the second pre-trained model using the word segmenter loading module; Using the sampling deviation analysis module to obtain the difference between the output of the second reference model and the output of the second scoring model based on the output of the second reference model, the output of the second scoring model and the true label, wherein the output of the second reference model is the original score of each possible output of the second reference model based on the input text to be tested, and the output of the second scoring model is the original score of each possible output of the second scoring ...; The output obtained by the sampling deviation analysis module is input into the output module to obtain the prediction result; The machine-generated text detection model is a model obtained by using the training method for the machine-generated text detection model described in any one of claims 1 to 5.

7. A training device for a machine-generated text detection model based on machine style optimization, characterized in that: in, The machine-generated text detection model includes a model loading module, a word segmentation loading module, a sampling deviation analysis module and an output module, and the device includes: A first pre-trained model loading module, used to load the first pre-trained model using the model loading module, and use the loaded first pre-trained model as a first reference model and a first scoring model; A word segmenter loading module of the first pre-trained model, used to load the word segmenter of the first pre-trained model using the word segmenter loading module; A first difference output module, used to obtain the difference between the output of the first reference model and the output of the first scoring model based on the output of the first reference model, the output of the first scoring model and the true label by using the sampling deviation analysis module, wherein the output of the first reference model is the original score of each possible output output by the first reference model based on the input original text without normalization, and the output of the first scoring model is the original score of each possible output output by the first scoring model based on the input original text without normalization; A first prediction module, used to input the output obtained by the sampling deviation analysis module into the output module to obtain a prediction result; and The forward propagation module is used to train the machine-generated text detection model based on the original text, the real label initialized as None, and the degree of difference between the current prediction result of the model and the real label.

8. A machine-generated text detection device, characterized in that: The machine-generated text detection model includes a model loading module, a word segmentation loading module, a sampling deviation analysis module and an output module, and the device includes: A second pre-trained model loading module, used to load the second pre-trained model using the model loading module, and use the loaded second pre-trained model as a second reference model and a second scoring model; A word segmenter loading module of the second pre-trained model, used to load the word segmenter of the second pre-trained model using the word segmenter loading module; A second difference output module, used for obtaining the difference between the output of the second reference model and the output of the second scoring model based on the output of the second reference model, the output of the second scoring model and the true label by using the sampling deviation analysis module, wherein the output of the second reference model is the original score of each possible output output by the second reference model based on the input text to be tested without normalization, and the output of the second scoring model is the original score of each possible output output by the second scoring model based on the input text to be tested without normalization; A second prediction module, used for inputting the output obtained by the sampling deviation analysis module into the output module to obtain a second prediction result of the text to be tested; Wherein, the machine-generated text detection model is a model obtained by using the training device of the machine-generated text detection model described in claim 7.

9. A computer-readable storage medium having a computer program stored thereon, characterized in that: When the program is executed by a processor, it implements the training method of the machine-generated text detection model as described in any one of claims 1 to 5 or the machine-generated text detection method as described in claim 6.

10. A computer 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 program, it implements the training method of the machine-generated text detection model as described in any one of claims 1 to 5 or the machine-generated text detection method as described in claim 6.