RiteeshGrandhi/sciclaimeval-shared-task huggingface dataset:
Generated Text Detection
The burgeoning progress in the generation capabilities of large language models has led to a corresponding increase in research and development efforts in the field of detection. Several recent efforts look at methods, varying from simple feature-based classifiers to fine-tuned language model-based detectors, in order to classify whether a piece of input text is human-written or AI-generated Ippolito et al. ( 2019 ); Gehrmann et al. ( 2019 ); Mitchell et al. ( 2023 ) , along with methods that specifically focus on AI-generated news Zellers et al. ( 2019 ); Bogaert et al. ( 2022 ); Bhattacharjee and Liu ( 2023 ); Kumarage et al. ( 2023 ) . A related direction of work is that of authorship attribution (AA). While older AA methods focused on human authors, more recent efforts Uchendu et al. ( 2020 ); Munir et al. ( 2021 ) build models to identify the generator for a particular input text. Recent work also shows how AI-generated text can deceive state-of-the-art AA models Jones et al. ( 2022 ) , thus making the task of detecting such text even more important.
Contrastive Learning for Text Classification
Following the success of contrastive representation learning in the computer vision domain, several recent works in natural language have used contrastive learning for text classification, often for benefits such as robustness Zhang et al. ( 2022 ); Ghosh and Lan ( 2021 ); Pan et al. ( 2022 ) , generalizability Tan et al. ( 2020 ); Kim et al. ( 2022 ) and also in few-shot scenarios Jian et al. ( 2022 ); Zhang et al. ( 2021 ); Chen et al. ( 2022a ) . Authors in Qian et al. ( 2022 ); Chen et al. ( 2022b ) also use ideas from contrastive learning to leverage label information to learn better representations for the classification task.
Domain Adaptation for Text Classification
Domain adaptation (DA) is a paradigm that aims to tackle the distribution shift between training and testing distributions, by learning a discriminative classifier, that is invariant to domain-specific features Sener et al. ( 2016 ) . Along with labeled source data, DA methods may use either unlabeled target data (unsupervised DA) or a few labeled target samples (semi-supervised DA). In our work, we consider the unsupervised DA setting Ganin et al. ( 2016 ) . In the domain of language, unsupervised domain adaptation has been used in a variety of tasks Ramponi and Plank ( 2020 ) , such as sentiment classification Glorot et al. ( 2011 ); Trung et al. ( 2022 ) , question answering Yue et al. ( 2021 ) , event detection Trung et al. ( 2022 ) , sequence tagging or labeling Han and Eisenstein ( 2019 ) , etc.

In this work, we frame the problem of detecting AI-generated news text from multiple generators as an unsupervised domain adaptation task, where the different generators are the different data domains. Our proposed framework combines the representational power of self-supervised contrastive learning and a principled method for unsupervised domain adaptation to solve the AI-generated text detection problem. To the best of our knowledge, we are the first to propose this kind of a formulation for AI-generated text detection, along with a novel framework for this task. In the following section, we describe our framework in detail, along with our training objective.
Model
In this work, we consider a setting where we have labeled data from the source generator and only unlabeled samples from the target generator 2 2 2 We use the terms ‘LLM’ and ‘generator’ interchangeably. . More formally, the source domain dataset is denoted by \mathbf{S}=\{(x^{S}_{i},y^{S}_{i})\}_{i=1}^{N^{S}} where y^{S}_{i}\in\{0,1\} corresponding to ‘human-written’ or ‘AI-generated’ labels, and N^{S} is the number of source domain samples. The target domain is denoted by \mathbf{T}=\{(x^{T}_{i})\}_{i=1}^{N^{T}} , where N^{T} is the number of target domain samples. Note that all domains share the same label space.
ConDA Framework
We show our framework in Figure 2 . For the detector, we use a pre-trained RoBERTa model ( roberta-base ) from Huggingface 3 3 3 https://huggingface.co/roberta-base , with a classifier head on top of it. As the input, we have two articles: x^{S}_{i} from the source and x^{T}_{i} from the target. We perform a text transformation \tau on this text whereby we get the transformed samples x^{S}_{j} and x^{T}_{j} . In order to input both the original and the transformed (also referred to as ‘perturbed’ throughout this paper), we use a Siamese network Bromley et al. ( 1993 ); Neculoiu et al. ( 2016 ); Reimers and Gurevych ( 2019 ) where the RoBERTa model weights are shared across the two branches. For the two input texts, we take the hidden layer representation of the [CLS] token: h_{i[CLS]}^{S} and h_{j[CLS]}^{S} . Following the methodology in Chen et al. ( 2020 ) , we pass these embeddings through a projection layer that consists of a multi-layer perceptron (MLP) with one hidden layer and compute a contrastive loss in the lower dimensional projection space. The MLP can be represented as a function g(\cdot):\mathbbm{R}^{d_{h}}\mapsto\mathbbm{R}^{d_{p}} , where d_{h} is the size of the hidden layer embedding: 768 for roberta-base , and we set d_{p} as 300 , following Pan et al. ( 2022 ) . For the source domain, we also compute the cross-entropy losses for binary classification of both the original and transformed text. Furthermore, we have a domain discrepancy component between the projected representations of the source and target text. We elaborate on the losses and related design choices in the following section.
Source Classification Loss:
We leverage the availability of the source labels and compute the binary cross-entropy (CE) losses for the original and the perturbed text:

\begin{split}\mathcal{L}_{CE}^{S}&=-\frac{1}{b}\sum_{i=1}^{b}[y_{i}\log p(y_{i}|h^{S}_{i[CLS]})+\ &(1-y_{i})\log(1-p(y_{i}|h^{S}_{i[CLS]}))]\end{split} (1)

\mathcal{L}_{CE}^{S} denotes the CE loss for the original text, b denotes the batch size. Similarly, we compute \mathcal{L}_{CE}^{S^{{}^{\prime}}} for the perturbed text, and we skip the equation for brevity. Inspired by the training objective in Pan et al. ( 2022 ) , we use CE losses for both the original and perturbed samples in the final training objective. The transformation performed on the original text (i.e. synonym replacement in our experiments) preserves the semantics of the text and hence is label-preserving. In such a case we would want a classifier to be able to detect text with such minor, semantic-preserving perturbations as well. Not only is this supposed to improve the robustness of the classifier, but in turn also the generalizability of the detector Xu and Mannor ( 2012 ) , which is essential for our use-case.
Contrastive Loss:
To learn a better representation of the input text, we use contrastive losses, for both the source and target texts (Figure 2 ). We use a loss similar to the one in Chen et al. ( 2020 ) : the only difference is that, instead of computing the loss between two transformed views of the text, we use the transformed text and the original anchor text. For our transformation, we use synonym replacement (more details regarding implementation are in the Appendix). The contrastive loss for the source is denoted by:

\mathcal{L}^{S}_{ctr}=-\sum_{(i,j)\in b}\log\frac{exp(sim(z^{S}_{i},z^{S}_{j})/t)}{\sum_{k=1}^{2|b|}\mathbbm{1}_{[k eq i]}exp(sim(z^{S}_{i},z^{S}_{k})/t)} (2)

\mathcal{L}^{S}_{ctr}=-\sum_{(i,j)\in b}\log\frac{exp(sim(z^{S}_{i},z^{S}_{j})/t)}{\sum_{k=1}^{2|b|}\mathbbm{1}_{[k\neq i]}exp(sim(z^{S}_{i},z^{S}_{k})/t)}

z^{S}_{i} and z^{S}_{j} denote the projection layer embeddings for the original (anchor) and the transformed text, t is the temperature, b is the current mini-batch, sim(\cdot,\cdot) is a similarity metric which is cosine similarity in our case. Similar to Chen et al. ( 2020 ) , we do not sample or mine negatives explicitly, we simply consider the remaining 2(|b|-1) samples in the mini-batch b as negatives. We have a similar contrastive loss for the target domain, denoted by \mathcal{L}^{T}_{ctr} , and we skip the equation here for brevity. The objective of these contrastive losses is to bring the positive pairs, i.e. anchor and the transformed sample, closer in the representation space, and well separated from the negative samples.

Since the performance of contrastive learning depends significantly on the transformation used to generate the positive sample Tian et al. ( 2020 ) , we take a principled approach to choosing a transformation out of several possible ones Bhattacharjee et al. ( 2022 ) . To choose one transformation for the main experiments, we evaluate a simple detection model (only one domain) over different choices of transformations and choose the one that gives the best performance, and therefore, is the most discriminative. In the input space, we use random swap, random crop, and synonym replacement as the choices. In the latent space, we have paraphrasing and summarization as the choices. Based on detection performance, we finally choose synonym replacement as the transformation that we use throughout the remainder of the paper.
Maximum Mean Discrepancy(MMD):
Maximum Mean Discrepancy (MMD) Gretton et al. ( 2012 ) is a metric to measure the distance between two distributions, which in our case refers to two different generators. Formally, let S=\{x^{S}_{1},x^{S}_{2},...,x^{S}_{N^{S}}\} and T=\{y^{T}_{1},y^{T}_{2},...,y^{T}_{N^{T}}\} be two sets of samples drawn from distribution \mathcal{S} and \mathcal{T} , respectively. The MMD distance between the distributions \mathcal{S} and \mathcal{T} is defined as the distance between means of two samples mapped to the Reproducing Kernel Hilbert Space (RKHS) Steinwart ( 2001 ) . Following past work Pan et al. ( 2010 ); Long et al. ( 2015 ) , we compute the MMD between text embeddings in a lower dimensional space, i.e. between z^{S}_{i} and z^{T}_{i} . Formally,

\scalebox{0.85}{$MMD(\mathcal{S},\mathcal{T})=\|\frac{1}{N^{S}}\sum_{i=1}^{N^{S}}\phi(z^{S}_{i})-\frac{1}{N^{T}}\sum_{i=1}^{N^{T}}\phi(z^{T}_{i})\|_{\mathcal{H}}$}, (3)

where \phi\colon\mathcal{S}\mapsto\mathcal{H} and \mathcal{H} represents the RKHS space.

The final training objective for our main framework is:

\begin{split}\mathcal{L}=&\frac{(1-\lambda_{1})}{2}[L^{S}_{CE}+L^{S^{{}^{\prime}}}_{CE}]+\ &\frac{\lambda_{1}}{2}[L^{S}_{ctr}+L^{T}_{ctr}]+\lambda_{2}MMD(S,T)\end{split} (4)

where \lambda_{1} and \lambda_{2} are hyper-parameters.
Experimental Settings
In this section we describe the datasets, baselines and the training details we use for our experiments.
Dataset
Since our task requires news text from multiple generators, we use the publicly available TuringBench 4 4 4 https://turingbench.ist.psu.edu/ dataset Uchendu et al. ( 2021 ) , which contains human-written and machine-generated news articles from 19 generators, spanning over 10 different language model architectures (including different sizes for some of the generators). For a full list of labels, check Appendix B.1 .

Out of the 10 different architectures available in the dataset, we sample a representative set of 6 different generators, in order to evaluate our model (Table 1 ). For most of the architectures, if there were multiple parameter sizes available, we choose the largest one, to make the detection task more challenging for our model. We briefly go over the architectural details of each of the generators used:

CTRL Keskar et al. ( 2019 ) is a transformer-based language model, that is developed for controllable generation of text based on control codes for style, content, and task-specific generation. The model is pre-trained on a variety of text types, including web-text, news, question-answering datasets, etc. FAIR_wmt19 Ng et al. ( 2019 ) is FAIR’s model that was developed for the WMT19 news translation task. Texts in TuringBench are from the English version of the FAIR_wmt19 language model. GPT2-XL Radford et al. ( 2019 ) is the 1.5B size version of GPT-2, which is also a transformer-based language model built upon the architecture of the original GPT model Radford et al. ( 2018 ) , with further modifications. GPT-3 Brown et al. ( 2020 ) is the successor of the GPT-2 model, and is the largest model we use in our evaluation, with a size of 175B parameters. GROVER_mega Zellers et al. ( 2019 ) is the largest version of the GROVER model, which is a transformer-based model, similar in architecture to GPT-2, but trained to conditionally generate news articles. XLM Lample and Conneau ( 2019 ) is also a transformer-based language model designed for cross-lingual tasks.

Furthermore, given the challenge of detecting text from the more recent conversational language models, we augment the TuringBench dataset with ChatGPT news articles. Following a similar data generation procedure as in Uchendu et al. ( 2021 ) , we use a subset of around 9,000 news articles from The Washington Post and CNN (more details in Appendix B.2 ), and use the headlines to generate articles using ChatGPT. For this paper, we used the OpenAI API with the gpt-3.5-turbo model (version as on March 14, 2023). After experimenting with a few different prompt types, we finally used the following prompt for each news headline : “Generate a news article with the headline ‘< headline >’." Finally, we have a balanced dataset of approximately 9k human-written articles, and 9k articles generated using ChatGPT (after accounting for null values and API request errors). For simplicity, we name this dataset ChatGPT News and we use this dataset for a case study on ChatGPT generated news articles, in Section 6 .
Baselines
For a fair comparison, we compare our method with baselines that do not require labeled data. We use two open-source AI-generated text detectors, namely GLTR Gehrmann et al. ( 2019 ) and the more recent DetectGPT Mitchell et al. ( 2023 ) , as our unsupervised baseline models.

GLTR utilizes a proxy language model to calculate the token-wise log probability of the input text. It employs four statistical tests: (i) log probabilities (\log p(x)) , (ii) average token rank (Rank), (iii) token log-rank (LogRank), and (iv) predictive entropy (Entropy). The first test assumes that a higher average log probability in the input text indicates AI generation. The second and third tests follow a similar assumption, where input texts with lower average rank are more likely to be generated by AI. The last test is based on the hypothesis that AI-generated texts tend to exhibit less diversity and surprises, resulting in low entropy.

DetectGPT also utilizes a proxy language model to calculate the token-wise log probability. However, its decision function is based on comparing the log probability of the original input text with the log probability of a set of n perturbed versions of the input text. These perturbations are generated using the mask-filling language model T5(T5-base) Raffel et al. ( 2020 ) . The decision function assumes that if the log probability difference between the input text and the perturbed text is positive with high probability, then the input text is likely to be AI-generated.

In addition to these zero-shot baselines, we include the off-the-shelf OpenAI-GPT2 detector as one of the baselines in our study. The OpenAI-GPT2 detector is a RoBERTa model fine-tuned specifically for detecting GPT2-generated text. It was trained on a GPT-2-output dataset 5 5 5 https://github.com/openai/gpt-2-output-dataset comprising 250k documents from the WebText test set Radford et al. ( 2019 ) as human-written text. Then as the AI text, this dataset contains 250k GPT-2 generated text with a temperature of 1 with no truncation and another 250k samples generated with top-k 40 truncation. Note that for our evaluation, this model may be considered unsupervised for all target domains except GPT-2_xl.
Results
To understand and investigate the effectiveness of our model, we try to answer the following research questions:

- RQ1: Does ConDA perform well on unknown target domains in comparison to a source-only model (Table 2 ) and a supervised model fine-tuned on the target (Table 3 )?

- RQ2: How well does ConDA perform in comparison to unsupervised-baselines (Table 4 )?

- RQ3: Are each of the loss components beneficial in training (Table 5 )?

All results are reported as an average over 3 training runs with 3 different random seeds.
Performance of ConDA on unlabeled target data
To evaluate the performance of ConDA on each of the target domains, i.e. generators, we first look at how our model improves over a source-only model. Table 2 shows the results for this experiment, grouped by target domain. We report F1 scores for the ConDA framework and a source-only model, along with scores averaged over sources, for each target. The source-only model is a pre-trained RoBERTa (roberta-base) fine-tuned only on the source domain S. The source-only scores provide an estimate of how well a model trained just on the source transfers to the target domain.
Although a few of the source-only models have satisfactory performance on the target, using our ConDA framework, we achieve performance gains over the source-only model in almost all tasks (rows with positive \Delta F1 values). Particularly interesting are the cases where we use a smaller generator as the source, a larger one as the target, and still get high performance gains: 58 F1 points for FAIR_wmt19 (656M) \rightarrow GROVER_mega (1.5B), and 41 F1 points for FAIR_wmt19 (656M) \rightarrow GPT-3 (175B). This may suggest that, with our ConDA framework, even having unlabeled data from newer and possibly larger generators can improve performance if we use a suitable generator as the source.

Next, we compare the performance of our model with a fully-supervised detector trained on the target domain in Table 3 .
For ConDA, we show the test performance for all target-source pairs. For the supervised model, we use a pre-trained RoBERTa (roberta-base) fine-tuned on the target data. We then evaluate the model on the test set of the same target domain, and essentially this is our upper bound performance. ConDA achieves test performance comparable to fully-supervised models. In particular, for targets CTRL and XLM, ConDA (with GROVER_mega as source) achieves upper bound performance. For targets GROVER_mega and GPT-2_xl, ConDA performs within 3 and 6 F1 points of the fully-supervised model.

Interestingly, for target generator GPT-3, all the ConDA models perform better than the fully-supervised performance, with the best F1 (from ConDA with source FAIR_wmt19) being 27 points higher than the supervised performance. Furthermore, when GPT-3 is used as the source domain, we get mediocre performance for all target domains. We suspect that this might be due to the following reason: The GPT-3 data in TuringBench might be noisy and therefore lack good quality, discriminative signals that can guide the detector. The performance improvement that occurs when ConDA is evaluated on GPT-3 as target, with any other domain as source, is possibly due to the effective transfer of discriminative signals from the labeled source data, hence improving the performance on GPT-3 data even in the absence of labels.
Performance compared to unsupervised baselines
We compare our ConDA framework with relevant unsupervised baselines and report results in Table 4 .
Out of the four GLTR measures ( \log p(x) , Rank, Log Rank, and Entropy), the first three fare quite well for detecting CTRL-generated text, but performance on other generators is quite poor. DetectGPT, which is the most recent method we evaluate, performs poorly on almost all generators, with some satisfactory performance on CTRL and XLM.
Surprisingly, the OpenAI GPT-2 Detector performs poorly on the GPT-2_xl data from TuringBench, although it can be considered supervised for this particular target. Finally, we see ConDA outperforms all the baselines in terms of maximum AUROC, and all but one in terms of average AUROC.

Interestingly, we see that ConDA models trained with GROVER_mega as the source perform very well for several target domains. This might be because GROVER Zellers et al. ( 2019 ) was designed and trained in order to generate news articles. Since our task here is to specifically detect human vs. AI written news articles, training models on data generated using GROVER_mega is useful and this data possibly has good discriminative signals.
Ablation: Effectiveness of loss components
We evaluate variants of the ConDA model, by removing one component at a time and compare these in Table 5 . ConDA \CEs removes the two cross-entropy losses, i.e. no supervision even for the source. ConDA \contrast removes the contrastive loss components for both source and target. ConDA \MMD removes the MMD loss between source and target. Hence the only component that makes use of the unlabeled target domain data is the target contrastive loss. Finally, ConDA is the full model. We see that the full model outperforms all the variants, implying that all three types of components are essential for detection performance in this problem setting. Combined with source supervision, the contrastive losses and the MMD objective effectively tie the power of self-supervised learning and unsupervised domain adaptation resulting in superior performance across target domains.
A Case Study on ChatGPT
Given recent concerns surrounding OpenAI’s ChatGPT and GPT-4 OpenAI ( 2023 ) , it is important to create detectors for text generated by these conversational language models. With the incredible fluency and writing quality these language models possess, not only can such text easily fool humans Else ( 2023 ) but can also be extremely difficult for detectors to identify. Even OpenAI’s detector struggles to detect AI-generated text reliably 6 6 6 https://openai.com/blog/new-ai-classifier-for-indicating-ai-written-text . Hence in this case study, we are interested in evaluating our ConDA framework on ChatGPT-generated news articles, in an unsupervised manner. Since there is no existing dataset of ChatGPT-generated vs. human-written text or news, we create our own dataset as explained in Section 4.1 . We assign ChatGPT as the unlabeled target domain and assume that we have labeled data from the 6 other generators (Table 1 ). Therefore we emulate a real-world scenario where labeled data from older generators may be available, but it might be hard to find labeled samples for newer LLMs. We sample 4k articles from our ChatGPT News dataset and evaluate the same 3 unsupervised models as in Section 4.2 (upper row block in Table 6 ), and our ConDA framework over 6 source generators (lower row block in Table 6 ) on this data. For GLTR, we report the average over the 4 statistical measures. Although we see satisfactory performance across most methods, our ConDA framework with source as FAIR_wmt19 and GPT2_xl has the best and the second best performance, respectively. However, we would like the reader to note that such good performance on our ChatGPT News dataset does not imply similar performance on any other type of text generated by ChatGPT (see Section 8 ). For text embedding visualizations from our ConDA model for this ChatGPT case study, check Appendix C .