Man-machine mixed text detection method based on context extension

By introducing sliding window and context information into AI text detection, combined with coherence characteristics and confidence verification, the problem of insufficient accuracy and robustness of traditional methods in human-computer hybrid text detection is solved, and a more efficient detection effect is achieved.

CN120409492APending Publication Date: 2025-08-01HUNAN UNIV
View PDF 0 Cites 2 Cited by

Patent Information

Application Number
CN202510508917.0
Authority / Receiving Office
CN · China
Patent Type
Applications(China)
Current Assignee / Owner
Filing Date
2025-04-22
Publication Date
2025-08-01

AI Technical Summary

Technical Problem

Traditional AI text detection methods are difficult to effectively distinguish between human-computer mixed text, especially in short text, semantic features are sparse, resulting in insufficient detection accuracy and robustness.

Method used

The sliding window mechanism is used to expand the detection range to the context of the sentence, combined with coherence characteristics and confidence verification, semantic features are extracted through the pre-trained RoBERTA model, and a noise suppression method is designed to enhance detection accuracy.

Benefits of technology

By introducing context information and noise suppression technology, the accuracy and robustness of human-computer hybrid text detection are improved, the limitations of single-sentence detection are overcome, and the detection accuracy and generalization ability are improved.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN120409492A_ABST
    Figure CN120409492A_ABST
Patent Text Reader

Abstract

The invention relates to a man-machine mixed text detection method based on context expansion, which expands the detection range from a single target sentence to the context of the sentence by introducing a sliding window mechanism, and designs a method for weakening context noise interference to improve the accuracy and generalization of model prediction. The method comprises the following steps: firstly, collecting texts with the window length as a training set and a verification set, and extracting semantic features and coherence features for training to obtain a trained detection model; a sliding window mechanism is applied to a test set to detect all window texts, and a small sliding window step length is set, so that sentences in the window texts can obtain a plurality of prediction probabilities under different context conditions. And adopting a detection mechanism based on confidence to perform confidence weighting on the plurality of prediction probabilities to obtain a final probability that the sentence is the AI text.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] The present invention relates to a method for detecting human-machine hybrid text based on context expansion, belonging to the field of natural language processing. Background Art

[0002] The emergence of large language models (LLMs) has had an important impact on aspects such as the diversity and fluency of machine-generated text. The text generated by them is highly similar to human-created text in terms of language style, grammatical structure, and expression manner, even to the extent that it is difficult to distinguish with the naked eye. The progress of this technology has greatly improved people's production and living efficiency and demonstrated extensive application potential in fields such as information retrieval and automated writing. However, the abuse of this technology has also brought severe challenges. There are more and more reports of LLMs being used to write homework and papers, and the problems of machine water army posting and false news flooding have become common. Therefore, developing efficient and reliable AI-generated text detection technology has become a key issue that needs to be solved urgently.

[0003] Traditional AI text detection methods mainly simplify the problem into a binary classification task, that is, detecting the whole text as human text or AI text. However, this coarse-grained classification method is difficult to handle more complex scenarios in reality, especially when dealing with human-machine hybrid text, there are obvious limitations. To overcome this problem, one solution is to detect the text sentence by sentence and locate the sentence fragments generated by AI. However, due to the sentence length limitation, the available language features and semantic clues for short texts are relatively scarce, and this feature sparsity significantly increases the difficulty of sentence-level AI text detection.

[0004] The sliding window method is a classic algorithm strategy, and its core idea is to maintain a window with a fixed or variable size and efficiently traverse the data by dynamically adjusting the left and right boundaries of the window. When dealing with scenarios that require dynamically maintaining local features such as continuous subsequences or continuous subintervals, using the sliding window algorithm can efficiently solve such problems.

[0005] In the present invention, we designed a method for detecting human-machine hybrid text based on context expansion. We introduced a sliding window mechanism to expand the detection scope from a single target sentence to the context of the sentence. By additionally introducing context auxiliary information, we can more accurately extract the semantic features of the target sentence. Considering that when introducing context, noise text that interferes with sentence judgment will also be introduced, we designed the following methods to weaken the interference of noise text: (1) additionally extract the coherence features of the text for detection. If there is noise text in the window, its coherence with the context will decrease; (2) design a confidence-based detection and verification mechanism to enhance the weight of high-confidence prediction results, so that the model preferentially adopts "confident" judgments and reduces noise interference. Summary of the Invention

[0006] The present invention designs a human - machine hybrid text detection method based on context extension, which enhances the reliability of short - text detection by introducing context information, overcomes the limitation of insufficient detection features of a single sentence, and at the same time designs a noise suppression method to reduce the noise interference brought by introducing context and improve the accuracy of hybrid text detection. Compared with the traditional sentence - level AI text detection method, this method enhances the semantic accuracy of the target sentence by considering context text features, improves the detection accuracy, and introduces coherence features and confidence judgment to enhance the robustness and generalization of the method.

[0007] A human - machine hybrid text detection method based on context extension includes the following steps:

[0008] Step S101: Dataset preparation, which specifically includes the following steps:

[0009] Step S1011: Determine the window length of the sliding window;

[0010] Step S1012: Extract a sentence set of the window - length size. For each article sample in the original training set and validation set, randomly extract a consecutive sentence set of the window - length size from it to form a new window text, thereby constructing a new training set and validation set;

[0011] Step S102: Extract semantic features of the window text. Input the window text into a pre - trained language model to obtain the semantic feature vector of the text;

[0012] Step S103: Extract coherence features of the window text, which specifically includes the following steps:

[0013] Step S1031: Construct a token - level cross - entropy loss sequence. Use a large - language model to obtain the token - level cross - entropy loss sequences of the window text and the target sentence in the window text respectively;

[0014] Step S1032: Construct a byte - level cross - entropy loss sequence. Map the two token - level cross - entropy loss sequences obtained in the previous step to byte - level cross - entropy loss sequences;

[0015] Step S1033: Calculate the word - level perplexity sequence. Calculate the word - level perplexity sequences through the two byte - level cross - entropy loss sequences obtained in the previous step.

[0016] Step S1034: Coherence feature extraction. When the target sentence is connected to the context and input into the language model separately, the obtained perplexities are different. By measuring the difference in perplexities in these two cases, the influence degree of the context on the target sentence is measured, which is then used as the coherence feature representation of the window text;

[0017] Step S104: Build a classification network model and train the feature classifier;

[0018] Step S105: Test set detection, and the specific steps are as follows:

[0019] Step S1051: Obtain prediction results. Use the sliding window method on the test set to test the text within the window;

[0020] Step S1052: Confidence weighted detection. For the sentences in the test text, when the sliding window step size is small, multiple prediction probabilities will be obtained. Use the confidence to weight the prediction probabilities to calculate the final prediction result of the sentence.

[0021] Further improvement, the specific steps of 1011 are as follows:

[0022] The selected window length cannot be too small, otherwise insufficient context information cannot be obtained; nor can it be too large, otherwise too much noisy text will be introduced. This step determines the optimal window length len window (2 ≤ len window ≤ len text , where len text represents the number of sentences included in the article), and this window length reflects the number of sentences included in the window.

[0023] Further improvement, the specific steps of 1012 are as follows:

[0024] Traverse all articles in the original training set and the original validation set. During the traversal, randomly select consecutive sentences in the article to form a new window text. That is, set a random number s, where s represents the position of the first selected sentence, and it is required that 0 < s < (len text -len window ), so as to ensure that the selected window text always contains len window sentences. Repeat this process until all the original training set and the original validation set are traversed to form a new window text training set and a window text validation set.

[0025] Further improvement, the specific steps of 102 are as follows:

[0026] The semantic features of the text are not limited to the surface form of the words, but express the information of the text through the interaction of vocabulary, grammatical structure and context, and can better reflect the internal attributes of the text. In the pre-trained language model, the input text is represented as a sequence, and the [CLS] token is fixed at the beginning of the sequence. During the training process, the model encodes the semantic information of the entire text sequence into the hidden state corresponding to the [CLS] token.

[0027] In this method, the pre-trained RoBERTA model is used to extract the semantic features of the window text. When the window text T is input into the RoBERTA model, the RoBERTA model will convert the text T into a series of vectors {x1, x2, …, x n}, where n is the sequence length, and the vectors are processed through a multi-layer Transformer architecture. Assume that the output of each layer of the RoBERTA model is H l , where l represents the layer number. Each layer of the Transformer will update the hidden state of the [CLS] token, making it gradually cover more information of the text sequence. Therefore, through multi-layer encoding, the final hidden state h CLS of the [CLS] token will contain the semantic information of the entire text sequence:

[0028] h CLS = H L [0, :] (1)

[0029] where L is the total number of layers of the RoBERTA model, H L is the output of the last layer of the model, and its dimension is [n, d], where d is the dimension of the hidden layer. The obtained hidden state h CLS is the semantic feature f sem of the window text T.

[0030] For further improvement, the specific steps of 1031 are as follows:

[0031] For the window text T, select one of the sentences as the target sentence T target , and input T and T target into the large language model GPT2 for perplexity calculation. Taking the window text T as an example, after inputting T into the GPT2 model, the model uses the byte-level BPE (Byte-Pair Encoding) tokenizer to encode the input text into the corresponding token digital identification sequence S = {s1, s2, …, s m}, where m is the length of the token sequence. Let the logits matrix output by the model be V is the size of the vocabulary. Since the language model predicts the probability distribution of the next word at each position in an autoregressive manner, and the label at each time step is the next word in the input sequence, it is necessary to align the logits prediction with the numerical identifier:

[0032] L shift = L[1:m - 1] (2)

[0033] S shift = S[2:m] (3) Next, calculate the token-level cross-entropy loss according to the output:

[0034]

[0035] Among them, is the cross-entropy loss of the (i + 1)-th token. Construct the token-level cross-entropy loss sequence of the window text T Target sentence T target Perform the same steps to construct its token-level cross-entropy loss sequence where m ′ is the length of the token sequence of T target .

[0036] For further improvement, the specific steps of 1032 are as follows:

[0037] To construct the byte-level loss sequence, it is necessary to map the token-level loss sequence. Taking the window text T as an example, for each numerical identifier s in the numerical identifier sequence S i (i = 1, …, m), restore it to the token subword t by reverse querying the BBPE tokenizer vocabulary i , and further decode the obtained token subword t i into the byte sequence B i :

[0038]

[0039] Among them, E byte is the byte encoding mapping table, is the constructed byte decoding mapping table. Next, construct the byte-level loss sequence according to the obtained byte sequence. Since the first token has no previous context, the byte-level loss corresponding to this token is 0, and the losses of the byte sequences B i corresponding to the remaining position token subwords t i are all Thus, the byte-level loss sequence can be constructed

[0040] Target sentence T targetExecute the same steps to construct its byte-level cross-entropy loss sequence

[0041] For further improvement, the specific steps of 1033 are as follows:

[0042] To construct the word-level perplexity sequence, the byte-level loss sequence needs to be mapped. Taking the window text T as an example, based on the byte-to-word mapping table I map and the byte-level loss sequence For each word w in the window text T i , first extract all the byte position index sets D i that belong to w i :

[0043] D i ={d|I map [d]=w i}(7)

[0044] Calculate the average cross-entropy loss of each word w i through the index, which is the perplexity:

[0045]

[0046] Thus, the word-level perplexity sequence PPL of the window text T can be obtained word_T . For the target sentence T target Execute the same steps to construct its word-level perplexity sequence PPL word_target .

[0047] For further improvement, the specific steps of 1034 are as follows:

[0048] In a large language model, the perplexity of each token reflects the uncertainty of the model in predicting that token under the given context. Therefore, the perplexity of each word is affected by the context. In this method, by measuring the difference in perplexity of a single sentence when concatenating the context and inputting it into the language model alone, the influence degree of the context on the sentence is mapped, thus reflecting the coherence of the text.

[0049] In the previous step, the word-level perplexity sequence PPL of the window text T word_T and the word-level perplexity sequence PPL target of the target sentence T word_target are obtained. According to the position of the target sentence in the window, the perplexity sequence of the window text is intercepted to obtain the perplexity sequence PPL' of the target sentence in the context word . Next, quantify the perplexity difference and define the influence intensity ΔPPL of the context on the target sentence wordis the relative difference in perplexity between the two cases:

[0050]

[0051] The obtained influence strength ΔPPL word is the coherence feature f of the window text coh .

[0052] The specific steps of the further improvement belonging to 104 are as follows:

[0053] Construct a classification network model and train a feature classifier. This classification network learns the complex non-linear relationship between input features through two fully connected layers and converts the features into class probabilities. In the first fully connected layer, the window text semantic feature f sem and the coherence feature f coh obtained previously are transformed into hidden layer representations through a weight matrix transformation:

[0054] h = σ1(W1·cat(f sem , f coh ) + b1) (10)

[0055] where W1 is the weight matrix, b1 is the bias vector, and σ1 is the activation function. In the second fully connected layer, the hidden layer features are mapped to the class space:

[0056] o = σ2(W2·h + b2) (11)

[0057] where W2 is the weight matrix, b2 is the bias vector, and σ2 is the activation function. The dimension of the output o is len window ×1, and the elements in o represent the probability that the corresponding sentence in the window text is an AI text.

[0058] The specific steps of the further improvement belonging to 1051 are as follows:

[0059] Each sample in the test set is a complete text containing multiple sentences. Apply the sliding window strategy to each text in the test set, with the window length being len window , and the sliding step size being 1. Whenever the window slides once, use the trained model to classify and predict the text within the window. Therefore, in the entire text, except for the first and the last sentences, each sentence will be included in different contexts for multiple predictions, obtaining a prediction sequence belonging to that sentence:

[0060] P = {p i |i = 1, …, k} (12)

[0061] where k is the total number of times the sentence is predicted.

[0062] For further improvement, the specific steps of the 1052 are as follows:

[0063] For each sentence in the text, after obtaining the prediction sequence P of the sentence, for each prediction probability value in P, use the confidence weight to strengthen the contribution of high-confidence values and weaken the interference of uncertain values, so that the model preferentially adopts "confident" judgments and reduces noise interference. Specifically, calculate the prediction probability p i The absolute distance from the neutral reference value of 0.5, and linearly scale it to the interval [0,1] to generate a list of confidence weights. If the sum of all weights is 0 (i.e., all probabilities are at the neutral value), then evenly distribute the weights; otherwise, normalize each weight by dividing it by the total weight. Then, perform a weighted sum on the original probability list based on the normalized weights to obtain the final prediction result.

[0064] Compared with other methods, the present invention has the following remarkable advantages:

[0065] The present invention designs a human-machine hybrid text detection method based on context expansion, enhances the reliability of short text detection by introducing context information, overcomes the limitation of insufficient single-sentence detection features, and at the same time designs a noise suppression method to reduce the noise interference introduced by the context, improving the accuracy and robustness of human-machine hybrid text detection. BRIEF DESCRIPTION OF THE DRAWINGS

[0066] Figure 1 Shows the overall flowchart of the "human-machine hybrid text detection method based on context expansion" of the present invention. DETAILED DESCRIPTION OF THE EMBODIMENTS

[0067] To more clearly show the features and advantages of this patent, the following provides a detailed description of the embodiments. It should be clear that the following detailed description is only an example and is intended to provide further explanation of the present application. Unless otherwise specified, all technical and scientific terms used in this specification have the same meaning as commonly understood by those of ordinary skill in the technical field to which the present application belongs. Figure 1 Discloses a human-machine hybrid text detection method based on context expansion provided by an embodiment of the present application. The method includes the following steps:

[0068] Step 1: Dataset preparation step

[0069] We use the GoodNews dataset as the original human text. At the same time, we use the GPT2 (1.5B) model to rewrite the human text to generate AI text. The generated AI text is mixed with the original human text to construct the GoodNews-GPT2 mixed text dataset for subsequent experiments. In this dataset, 10,000, 1,000, and 1,000 texts are randomly selected as the original training set, original validation set, and test set respectively. Additionally, four language models, GPTNeo (2.7B), GPTJ (6B), OPT (2.7B), and GPTNeoX (20B), are used to generate AI text, and the corresponding mixed text test sets are constructed respectively to verify the robustness and generalization of the model under different generator conditions.

[0070] During the construction of the test set, three different levels, level-1, level-2, and level-3, are set to represent the proportion of AI text in the test set text. Among them, the proportion of AI text in level-1 is the least, and the proportion of AI text in level-3 is the most.

[0071] In the subsequent experiments, considering the number of sentences in the text, the window length of the sliding window is set to 3, that is, each window contains 3 sentences. Traverse each article sample in the original training set and the original validation set. During the traversal, randomly extract 3 consecutive sentences to form a new window text. Specifically, when traversing each text, set a random number s (0 < s < (len text - 3)), representing the position of the first sentence selected. Repeat this process until all the original training set and the original validation set are traversed to form a new window text training set and a window text validation set.

[0072] Step 2: Semantic feature extraction step

[0073] The semantic features of the window text are mainly extracted by using the pre-trained RoBERTA model. In the RoBERTA model, the input text is represented as a sequence, and the [CLS] token is fixed at the beginning of the sequence. During the training process of the model, the semantic information of the entire text sequence is encoded into the hidden state corresponding to the [CLS] token.

[0074] When the window text T is input into the RoBERTA model, the RoBERTA model will convert the text T into a series of vectors {x1, x2, … x n}, where n is the sequence length, and the vectors are processed through a multi-layer Transformer architecture. Assume that the output of each layer of the RoBERTA model is H l, where l represents the number of layers. Each layer of the Transformer updates the hidden state of the [CLS] token, gradually covering more information of the text sequence. Therefore, through multi-layer encoding, the final hidden state h of the [CLS] token CLS will contain the semantic information of the entire text sequence:

[0075] h CLS = H L [0, :] (13)

[0076] where L is the total number of layers of the RoBERTA model, and H L is the output of the last layer of the model, with a dimension of [n, d], where d is the dimension of the hidden layer. The obtained hidden state h CLS is the semantic feature f of the window text T sem .

[0077] Step 3: Coherence feature extraction step

[0078] The coherence feature of the window text is mainly obtained by measuring the difference in word perplexity. In large language models, the perplexity of each token reflects the uncertainty of the model in predicting that token under the given context. Therefore, the perplexity of each word is affected by the context. When the same sentence is input into the large language model alone and in the form of a joint context, the obtained perplexity is different. Therefore, by measuring the difference in perplexity in these two cases, the influence degree of the context on the target sentence can be measured, and then used as the coherence feature representation of the window text.

[0079] In large language models, a word may be split into multiple tokens, and different tokenization strategies (such as different numbers of merges) may lead to different splitting methods for the same word. At the same time, some tokens may span multiple words during tokenization (such as subwords after spaces or punctuation). Therefore, when measuring the perplexity difference, if the perplexity difference at the token level is directly calculated, it will lead to misattribution during mapping. And as the smallest storage unit of text, no matter how the tokenization strategy is adjusted, the byte-level loss allocation can always be accurately traced back to the original word. Therefore, in this method, the token-level cross-entropy loss sequence is first obtained, mapped to the byte-level cross-entropy loss sequence, and then the word-level perplexity sequence is calculated.

[0080] First, for the window text T, select one of the sentences as the target sentence T target , and combine T with T targetInput into the large language model GPT2 for perplexity calculation. Taking the window text T as an example, after inputting T into the GPT2 model, the model uses a byte-level BPE (Byte-Pair Encoding) tokenizer to encode the input text into a corresponding sequence of token digital identifiers S = {s1, s2, …, s m}, where m is the length of the token sequence. Let the logits matrix output by the model be V is the size of the vocabulary. Since the language model predicts the probability distribution of the next word at each position in an autoregressive manner, and the label at each time step is the next word in the input sequence, it is necessary to align the logits prediction with the digital identifier:

[0081] L shift = L[1:m - 1] (14)

[0082] S shift = S[2:m] (15)

[0083] Next, calculate the token-level cross-entropy loss according to the output:

[0084]

[0085] Among them, is the cross-entropy loss of the (i + 1)-th token. Thus, construct the token-level cross-entropy loss sequence of the window text T For each digital identifier s i (i = 1, …, m) in the digital identifier sequence S, restore it to the token subword t i by reverse querying the BBPE tokenizer vocabulary, and further decode the obtained token subword t i into a byte sequence B i :

[0086]

[0087] Among them, E byte is the byte encoding mapping table, is the constructed byte decoding mapping table. According to the obtained byte sequence, construct the byte-level loss sequence. Since the first token has no previous context, the byte-level loss corresponding to this token is 0, and the byte-level loss of the token subword t i at the remaining positions is Thus, the byte-level loss sequence can be constructed

[0088] Based on the byte-to-word mapping table I map and the byte-level loss sequence For each word w in the window text T i , first extract the set D of all byte position indices belonging to w i : i D

[0089] = {d | I i [d] = w map} (19) i

[0090] Calculate the average cross - entropy loss for each word w i , which is the perplexity:

[0091]

[0092] Thus, the word - level perplexity sequence PPL of the window text T can be obtained word_T .

[0093] For the target sentence T target , perform the same steps to construct its word - level perplexity sequence PPL word_target . According to the position of the target sentence in the window, intercept the perplexity sequence of the window text to obtain the perplexity sequence PPL′ of the target sentence in the context word . Next, quantify the perplexity difference and define the influence strength ΔPPL of the context on the target sentence word as the relative difference in perplexity between the two modes:

[0094]

[0095] The obtained influence strength ΔPPL word is the coherence feature f of this window text coh .

[0096] Step Four: Training Steps of the Classification Network Model

[0097] This classification network includes two fully - connected layers, which learn the complex non - linear relationship between input features and convert the features into class probabilities. In the first fully - connected layer, the previously obtained window text semantic feature f sem and coherence feature f coh are transformed into a hidden - layer representation through a weight matrix:

[0098] h = tanh(W1·cat(f semantic , f coherence ) + b1) (22)

[0099] where W1 is the weight matrix, b1 is the bias vector, and tanh is the activation function. In the second fully - connected layer, the hidden - layer features are mapped to the class space: ​

[0100] o = Sigmoid(W2·h + b2) (23)

[0101] Among them, W2 is the weight matrix, b2 is the bias vector, and Sigmoid is the activation function, which is responsible for converting the output into a probability. The dimension of the output o is 3×1, and the elements therein represent the probabilities that the corresponding sentences in the window text are AI texts.

[0102] Step Five: Sliding Window Testing Step

[0103] Each sample in the test set is a complete text containing multiple sentences. Apply the sliding window strategy to each text in the test set, with the window length being 3 and the sliding step being 1. Whenever the window slides once, use the trained model to classify and predict the text within the window. Therefore, in the entire text, except for the first and the last sentences, each sentence will be included in different contexts for multiple predictions, obtaining a prediction sequence belonging to that sentence:

[0104] P = {p i | i = 1, …, k} (24)

[0105] Among them, k is the number of times the sentence is predicted. For each sentence in the text, after obtaining the prediction sequence P of that sentence, for each prediction probability value in P, use the confidence weight to strengthen the contribution of high-confidence values and weaken the interference of uncertain values, so that the model preferentially adopts "certain" judgments and reduces noise interference. Specifically, calculate the absolute distance between the prediction probability p i and the neutral benchmark value of 0.5, and linearly amplify it to the [0, 1] interval to generate a list of confidence weights. If the sum of all weights is 0 (i.e., all probabilities are at the neutral value), then evenly distribute the weights; otherwise, normalize each weight by dividing it by the total weight. Then, perform a weighted sum on the original probability list based on the normalized weights to obtain the final prediction result.

[0106] In the specific experimental process, we use the constructed GoodNews-GPT2 mixed text dataset for experimental verification and choose to compare with the advanced method Adaloc in the field of mixed text detection. In terms of evaluation metrics, we use two metrics, accuracy and average precision, to evaluate the method proposed in the present invention. The experimental results are shown in Table 1:

[0107] Table 1 Experimental Results on the GoodNews-GPT2 Mixed Text Dataset

[0108]

[0109] To better evaluate the generalization and robustness of the detection model, we use the GoodNews-GPT2 mixed text dataset as the training set and validation set, and use four language models, GPTNeo(2.7B), GPTJ(6B), OPT(2.7B), and GPTNeoX(20B), to construct corresponding mixed text test sets for cross-model detection experiments. The experimental results are shown in Tables 2 - 5:

[0110] Table 2 Cross-model detection experiment results on the GoodNews-GPTNeo mixed text dataset

[0111]

[0112] Table 3 Cross-model detection experiment results on the GoodNews-GPTJ mixed text dataset

[0113]

[0114]

[0115] Table 4 Cross-model detection experiment results on the GoodNews-OPT mixed text dataset

[0116]

[0117] Table 5 Cross-model detection experiment results on the GoodNews-GPTNeoX mixed text dataset

[0118]

[0119] Finally, it should be noted that the above embodiments are only used to illustrate the technical solutions of the present invention, rather than to limit it; although the present invention has been described in detail with reference to the foregoing embodiments, those of ordinary skill in the art should understand that they can still modify the technical solutions described in the foregoing embodiments, or perform equivalent replacements on some or all of the technical features; and these modifications or replacements do not make the essence of the corresponding technical solutions deviate from the scope of the technical solutions of the embodiments of the present invention.

Claims

1. A human-machine hybrid text detection method based on context extension, characterized in that, It includes the following steps: Step S101: Dataset preparation, which specifically includes the following steps: Step S1011: Determine the window length of the sliding window; Step S1012: Extract a sentence set of the window length. For each article sample in the original training set and validation set, randomly extract a continuous sentence set of the window length from it to form a new window text, thereby constructing a new training set and validation set; Step S102: Extract semantic features of the window text. Input the window text into a pre-trained language model to obtain the semantic feature vector of the text; Step S103: Extract coherence features of the window text, which specifically includes the following steps: Step S1031: Construct a token-level cross-entropy loss sequence. Use a large language model to obtain the token-level cross-entropy loss sequences of the window text and the target sentence in the window text respectively; Step S1032: Construct a byte-level cross-entropy loss sequence. Map the two token-level cross-entropy loss sequences obtained in the previous step to a byte-level cross-entropy loss sequence; Step S1033: Calculate the word-level perplexity sequence. Calculate the word-level perplexity sequence respectively through the two byte-level cross-entropy loss sequences obtained in the previous step; Step S1034: Extract coherence features. When the target sentence is connected to the context and input into the language model alone, the perplexities obtained are different. By measuring the difference in perplexities in the two cases, measure the influence degree of the context on the target sentence, and then use it as the coherence feature representation of the window text; Step S104: Construct a classification network model and train a feature classifier; Step S105: Detection on the test set. The specific steps are as follows: Step S1051: Obtain the prediction result. Use the sliding window method on the test set to test the text within the window; Step S1052: Confidence-weighted detection. For the sentences in the test text, when the sliding window step size is small, multiple prediction probabilities will be obtained. Use the confidence to weight the prediction probabilities to calculate the final prediction result of the sentence.

2. The method for detecting a human-machine hybrid text based on context expansion according to claim 1, wherein, The specific steps of the said Step S101 are as follows: The selection of the window length cannot be too small, as it will not be able to obtain sufficient context information; nor can it be too large, as it will introduce too much noisy text. This step determines the optimal window length len of the sliding window. window (2 ≤ len window ≤ len text , where len text represents the number of sentences contained in the article). This window length reflects the number of sentences contained in the window. Then, traverse all the articles in the original training set and the original validation set. During the traversal process, randomly select consecutive sentences in the article to form a new window text. That is, set a random number s, where s represents the position of the first sentence selected, and it is required that 0 < s < (len text - len window ), so as to ensure that the selected window text always contains len window sentences. Repeat this process until all the original training set and the original validation set are traversed to form a new window text training set and a window text validation set.

3. A method for detecting a human-machine hybrid text based on context expansion according to claim 1, characterized in that The specific steps of the said Step S102 are as follows: The semantic features of the text are not limited to the surface form of the words, but express the information of the text through the interaction of vocabulary, grammatical structure and context, and can better reflect the internal attributes of the text. In the pre-trained language model, the input text is represented as a sequence, and the [CLS] token is fixed at the beginning of the sequence. During the training process, the model encodes the semantic information of the entire text sequence into the hidden state corresponding to the [CLS] token. When the window text T is input into the RoBERTA model, the RoBERTA model will convert the text T into a series of vectors {x1, x2, … x n}, where n is the sequence length, and processes the vectors through a multi-layer Transformer architecture. Assume that the output of each layer of the RoBERTA model is H l , where l represents the layer number, and each layer of the Transformer updates the hidden state of the [CLS] token, making it gradually cover more information of the text sequence. Therefore, through multi-layer encoding, the final hidden state h CLS of the [CLS] token will contain the semantic information of the entire text sequence: h CLS = H L [0,:] (1) Among them, L is the total number of layers of the RoBERTA model, and H L is the output of the last layer of the model, whose dimension is [n, d], where d is the dimension of the hidden layer, and the obtained hidden state h CLS is the semantic feature f of the window text T sem .

4. A method for detecting a human-machine hybrid text based on context extension according to claim 1, characterized in that, The specific steps of the said Step S103 are as follows: For the window text T, select one of the sentences as the target sentence T target , and input T and T target into the large language model GPT2 for perplexity calculation. Taking the window text T as an example, after inputting T into the GPT2 model, the model uses a byte-level BPE (Byte-Pair Encoding) tokenizer to encode the input text into a corresponding sequence of token digital identifiers S = {s1, s2, …, s m}, where m is the length of the token sequence. Let the logits matrix output by the model be V is the vocabulary size. Since the language model predicts the probability distribution of the next word at each position in an autoregressive manner, and the label at each time step is the next word in the input sequence, it is necessary to align the logits prediction with the digital identifier: L shift = L[1:m-1] (2) S shift = S[2:m] (3) Next, calculate the token-level cross-entropy loss according to the output: Among them, is the cross-entropy loss of the (i + 1)-th token, and a token-level cross-entropy loss sequence of the window text T is constructed Target sentence T target Perform the same steps to construct its token-level cross-entropy loss sequence where m ′ is target the length of the token sequence of T. Next, in order to construct a byte-level loss sequence, it is necessary to map the token-level loss sequence. Taking the window text T as an example, for each digital identifier s i (i = 1, …, m) in the digital identifier sequence S, it is restored to the token sub-word t by reverse querying the BBPE tokenizer vocabulary i , and the obtained token sub-word t i is further decoded into a byte sequence B i : Among them, E byte is the byte encoding mapping table, and is the constructed byte decoding mapping table. Next, according to the obtained byte sequence, a byte-level loss sequence is constructed. Since the first token has no previous context, the byte-level loss corresponding to this token is 0. For the tokens at the remaining positions, the sub-word t i corresponding byte sequence B i has a loss of Thus, a byte-level loss sequence for the target sentence T target can be constructed. Perform the same steps to construct its byte-level cross-entropy loss sequence, denoted as Next, in order to construct the word-level perplexity sequence, the byte-level loss sequence needs to be mapped. Taking the window text T as an example, based on the byte-to-word mapping table I map and the byte-level loss sequence For each word w i in the window text T i , first extract the set D i of all byte position indices belonging to w D i = {d | I map [d] = w i} (7) Calculate the average cross-entropy loss for each word w through indexing i The average cross-entropy loss is the perplexity The word-level perplexity sequence PPL of the window text T can be obtained accordingly word_T , for the target sentence T target Perform the same steps to construct its word-level perplexity sequence PPL word_target , in a large language model, the perplexity of each token reflects the uncertainty of the model in predicting that token under the given context. Therefore, the perplexity of each word is affected by the context. In this method, by measuring the difference in perplexity of a single sentence when concatenating the context and inputting it into the language model alone, the degree of influence of the context on the sentence is mapped, thereby reflecting the coherence of the text. In the previous step, the word-level perplexity sequence PPL of the window text T was obtained word_T and the target sentence T target 's word-level perplexity sequence, denoted as PPL word_target , according to the position of the target sentence in the window, intercept the perplexity sequence of the window text to obtain the perplexity sequence PPL′ of the target sentence in the context word , next, quantify the perplexity difference and define the influence strength ΔPPL of the context on the target sentence word as the relative difference in perplexity between the two cases: The obtained influence intensity ΔPPL word is the coherence feature f of the window text coh .

5. A method for detecting a human-machine hybrid text based on context extension according to claim 1, wherein, The specific steps of the said Step S104 are as follows: Build a classification network model and train a feature classifier. This classification network learns the complex non-linear relationships between input features through two fully connected layers and converts the features into class probabilities. In the first fully connected layer, the window text semantic feature f sem and the coherence feature f coh are transformed into hidden layer representations through a weight matrix transformation: h = σ1(W1·cat(f sem , f coh ) + b1) (10) Among them, W1 is the weight matrix, b1 is the bias vector, and σ1 is the activation function. In the second fully connected layer, map the hidden layer features to the category space: o = σ2(W2·h + b2) (11) where W2 is the weight matrix, b2 is the bias vector, σ2 is the activation function, and the dimension of the output o is len window ×1, and the elements in o represent the probability that the corresponding sentence in the window text is an AI text.

6. A method for detecting a human-machine hybrid text based on context extension according to claim 1, characterized in that, The specific steps of the said Step S105 are as follows: Each sample in the test set is a complete text containing multiple sentences. Apply the sliding window strategy to each text in the test set, with the window length being len window , and the sliding step size being 1. Whenever the window slides once, use the trained model to perform classification prediction on the text within the window. Therefore, in the entire text, except for the first and the last sentences, each sentence will be included in different contexts for multiple predictions, obtaining a prediction sequence belonging to that sentence: P = {p i | i = 1, …, k} (12) Among them, k is the total number of times the sentence is predicted. For each sentence in the text, after obtaining the prediction sequence P of the sentence, for each predicted probability value in P, the confidence weight is used to strengthen the contribution of the high-confidence value and weaken the interference of the uncertainty value, so that the model preferentially adopts the "certain" judgment and reduces the noise interference. Specifically, calculate the predicted probability p i The absolute distance from the neutral reference value of 0.5, and linearly magnify it to the interval [0,1] to generate a list of confidence weights. If the sum of all weights is 0 (that is, all probabilities are at the neutral value), the weights are evenly distributed; otherwise, each weight is divided by the total weight to achieve normalization, and then the original probability list is weighted and summed based on the normalized weights to obtain the final prediction result.

Citation Information

Cited By

  • Method and system for detecting AI generation text and medium

    CN120849593A

  • AI generation text detection method based on sentence length distribution and text predictability characteristics

    CN122433705A