C o C o: Coherence-Enhanced Machine-Generated Text Detection Under Low Resource With Contrastive Learning (2023)

Abstract: Machine-Generated Text (MGT) detection, a task that discriminates MGT from Human-Written Text (HWT), plays a crucial role in preventing misuse of text generative models, which excel in mimicking human writing style recently. Latest proposed detectors usually take coarse text sequences as input and fine-tune pretrained models with standard cross-entropy loss. However, these methods fail to consider the linguistic structure of texts. Moreover, they lack the ability to handle the low-resource problem which could often happen in practice considering the enormous amount of textual data online. In this paper, we present a coherence-based contrastive learning model named CoCo to detect the possible MGT under low-resource scenario. To exploit the linguistic feature, we encode coherence information in form of graph into text representation. To tackle the challenges of low data resource, we employ a contrastive learning framework and propose an improved contrastive loss for preventing performance degradation brought by simple samples. The experiment results on two public datasets and two self-constructed datasets prove our approach outperforms the state-of-art methods significantly. Also, we surprisingly find that MGTs originated from up-to-date language models could be easier to detect than these from previous models, in our experiments. And we propose some preliminary explanations for this counter-intuitive phenomena. All the codes and datasets are open-sourced.

## introduction thriving progress in the field of text generative models (tgms) (yang et al., 2019; kenton and toutanova, 2019; liu et al., 2019; keskar et al., 2019; lewis et al., 2020; brown et al., 2020; gao 1 codes are available at https://github.com/yichenzw/cohmgt-detection and datasets are at https://huggingface.co/datasets/zachw/mgtdetect_coco . figure 1 : illustration of sentence-level structure difference between hwt and mgt, the mgt is generated by grover @xcite . hwt is more coherent than mgt as the sentences share more same entities with each other. @xcite @xcite @xcite , e.g., chatgpt foot_0 and gpt-4 (openai, 2023), enables everyone to produce mgts massively and rapidly. however, the accessibility to high-quality tgms is prone to cause misuses, such as fake news generation @xcite @xcite , product review forging (adelani et al., 2020), and spamming @xcite , etc. mgts are hard to distinguish by an untrained human for their human-like writing style @xcite ) and the excessive amount @xcite , which calls for the study of reliable automatic mgt detectors. previous works on mgts detection mainly concentrate on sequence feature representation and classification @xcite @xcite @xcite . recent studies have shown the good performance of automated detectors in a fine-tuning fashion @xcite . although these finetuning-based detectors have demonstrated their effectiveness, they still suffer from two issues that limit their conversion to practical use: (1) existing detectors treat input documents as flat sequences of tokens and use neural encoders or statistical features (e.g., tf-idf, perplexity) to represent text as the dense vector for classification. these finetuning-based methods rely much on the token-level distribution difference of texts in each class, which ignores high-level linguistic representation of text structure. (2) compared with the enormous number of online texts, the annotated dataset for training mgt detectors is rather low-resource. constrained by the amount of available annotated data, traditional detectors sustain frustrating accuracy and even collapse during the test stage. the defect in the coherence of lms in generating long text has been revealed by previous works. @xcite mentions that long-range semantic coherence remains challenging in language generation. @xcite also provides examples of incoherent mgts. as shown in fig. 1 , mgts and hwts exhibit differences in terms of coherence traced by entity consistency. accordingly, we propose that coherence could be an entry point for mgt detection via the perspective of high-level linguistic structure representation, where mgts could be less interactive than hwts. specifically, we propose an entity coherence graph to model the sentence-level structure of texts based on the thoughts of centering theory @xcite , which evaluates text coherence by entity consistency. the entity coherence graph treats entities as nodes and builds edges between entities in the same sentences and the same entities among different sentences to reveal the text structure. instead of treating text as a flat sequence, coherence modeling helps to introduce distinguishable linguistic features at the input stage and provides explainable differences between mgts and hwts. to alleviate the low-resource problem in the second issue, inspired by the resurgence of contrastive learning @xcite , we utilize the proper design of sample pair and contrastive process to learn fine-grained instance-level features under low resource. however, it has been proven that the easiest negative samples are unnecessary and insufficient for model training in contrastive learning @xcite . to circumvent the performance degradation brought by the easy samples, we propose a novel contrastive loss with the capability to reweight the effect of negative samples by difficulty score to help the model concentrate more on hard samples and ignore the easy samples. extensive experiments on multiple datasets (grover, gpt-2, gpt-3.5) demonstrate the effectiveness and robustness of our proposed method. surpirsingly, we find that the gpt-3.5 datasets are easier for all the detectors compared with datasets of smaller and older models (gpt-2 and grover) under our setting. we take a small step to exploring why the gpt-3.5 dataset is overly simple by probing statistical cues, including perspective from token spans and individual tokens. in summary, our contributions are summarized as follows: coherence modeling. for generative models, coherence is the critical requirement and vital target @xcite . previous works mainly discuss two types of coherence, local coherence @xcite and global coherence @xcite . local coherence focus on sentence-to-sentence transitions @xcite , while global coherence tries to capture comprehensive structure @xcite . our method strives to represent both local and global coherence with inner-and inter-sentence relations between entity nodes. contrastive learning. contrastive learning in nlp demonstrates superb performance in learning token-level embeddings @xcite and sentence-level embeddings @xcite for natural language understanding. with an in-depth study of the mechanism of contrastive learning, the hardness of samples is proved to be crucial in the training stage. @xcite define the dot product between the queries and the negatives in normalized embedding space as hardness and figured out the easiest 95% negatives are insufficient and unnecessary. @xcite propose a difficulty measure function based on the distance between classes and apply curriculum learning to the sampling stage. differently, our method pays more attention to hard negative samples for improving the detection accuracy of challenging samples. ## methodology the workflow of coco mainly contains coherence graph construction and supervised contrastive learning discriminator. fig. 2 illustrates its overall architecture. the pseudocode of the training process is shown in algorithm 1. ## conclusion in this paper, we propose coco, a coherenceenhanced contrastive learning model for mgt detection. we construct a novel coherence graph from the document and implement a moco-based contrastive learning framework to improve model performance in low-resource settings. an innovative encoder composed of relation-aware gcn and attention lstm is designed to learn the coherence representation from the coherence graph, which is further incorporated with the sequence representation of the document. to alleviate the effect of unnecessary easy samples, we propose an improved contrastive learning loss to force the model to pay more attention to hard negative samples. coco outperforms all detection tasks generated by grover, gpt-2, and gpt-3.5, respectively, in both low-resource and high-resource settings. we also find the outputs from the advanced gpt-3.5 are more detectable and explore the rationale behind the phenomena through the perspective of spans of tokens and individual tokens.