Automatic Detection of Generated Text is Easiest when Humans are Fooled (2020)

Abstract: Recent advancements in neural language modelling make it possible to rapidly generate vast amounts of human-sounding text. The capabilities of humans and automatic discriminators to detect machine-generated text have been a large source of research interest, but humans and machines rely on different cues to make their decisions. Here, we perform careful benchmarking and analysis of three popular sampling-based decoding strategies—top-_k_, nucleus sampling, and untruncated random sampling—and show that improvements in decoding methods have primarily optimized for fooling humans. This comes at the expense of introducing statistical abnormalities that make detection easy for automatic systems. We also show that though both human and automatic detector performance improve with longer excerpt length, even multi-sentence excerpts can fool expert human raters over 30% of the time. Our findings reveal the importance of using both human and automatic detectors to assess the humanness of text generation systems.

## introduction state-of-the-art generative language models are now capable of producing multi-paragraph excerpts that at a surface level are virtually indistinguishable from human-written content @xcite @xcite . often, only subtle logical fallacies or idiosyncrasies of language give away the text as machine-generated, errors that require a close reading and/or domain knowledge for humans to detect. deceptive text, whether human-or machinegenerated, has entered the sphere of public concern @xcite . it propogates quickly @xcite , sets political agendas @xcite , influences elections @xcite , and undermines user trust @xcite . @xcite have shown that automatically generated reviews are perceived to be as fluent as human-written ones. as generative technology matures, authors, well-meaning or otherwise, will increasingly employ it to augment and accelerate their own writing. it is more imperative now than ever for both humans and automated systems to be able to detect and identify machinegenerated texts in the wild. however, there has thus been little inquiry into the textual properties that cause humans to give generated text high human-like ratings compared to those that cause automatic systems to rate it highly. to speak of texts produced by language models, we must first consider how these texts are generated. a neural language model encodes a probability distribution over the next word in a sequence given the previous words. 1 a decoding strategy is an algorithm that generates sequences from a language model by determining how words should get selected from this distribution. the field has largely moved toward probabilistic decoding strategies that randomly sample from the output distribution token-by-token. however, when many low-likelihood words cumulatively contain quite a bit of probability mass, choosing one of these words can lead to odd or contradictory phrases and semantic errors. humans are quick to notice these types of errors. for this reason, it has become common to modify the language model's output probability distribution to increase the chance of sampling tokens with high likelihood according to the language model. top-k random sampling, where low-likelihood words are restricted from being generated, is one such method. a language model that is only permitted to produce high-likelihood words is less likely to make a poor choice and create the type of mistakes that are easy for humans to detect. since humans are not proficient at identifying when a model subtly favors some utterances more often than a human author would, they don't notice the over-representation of high-likelihood words in the generated text. in contrast, automatic systems excel at identifying statistical anomalies and struggle to build deeper semantic understanding. top-k in particular creates text that is easy for machines to detect but very hard for humans. thus, we observe the general trend: as the number of unlikely words available to be chosen is increased, humans get better at detecting fakes while automatic systems get worse. in this work, we study three popular random decoding strategies-top-k, nucleus, and temperature sampling-applied to gpt-2 @xcite . we draw a large number of excerpts generated by each strategy and train a family of bertbased @xcite binary classifiers to label text excerpts as human-written or machinegenerated. we find large differences in human rater and classifier accuracy depending on the decoding strategy employed and length of the generated sequences. regardless of strategy, we find human raters achieve significantly lower accuracy than the automatic discriminators. we also show that when a decoding strategy severely modifies the unigram token distribution, as top-k does, humans have trouble detecting the resultant generated text, but automatic classifiers find it the easiest to discriminate. worryingly, we further find that classifiers are brittle; they generalize poorly when trained to discriminate samples from one strategy and then evaluated on samples from another. in summary, our contributions are: ## related work generative language models with a sufficiently large training set and number of trainable parameters, neural language models based on the transformer architecture @xcite are capable of generating convincing, human-like excerpts up to several paragraphs in length. gpt-2 @xcite , grover @xcite , and transformer-dmca @xcite are a few examples of large, publicly available models with this ability. grover, in particular, has been shown to generate fake news that is more trustworthy than human-written fake news according to human raters. ## task definition we frame the detection problem as a binary classification task: given an excerpt of text, label it as either human-written or machine-generated. in particular, we are interested in how variables such as excerpt length and decoding strategy impact performance on this classification task. we thus create several datasets. each is approximately balanced between positive examples of machinegenerated text and negative examples of humanwritten text. while they all share the same humanwritten examples, each dataset contains a different set of machine-generated examples sampled using one particular decoding strategy. we also build additional datasets by truncating all of the examples to a particular sequence length, by training a separate classifier on each dataset, we are able to answer questions about which decoding strategy results in text that is the easiest to automatically disambiguate from human-written text. we are also able to answer questions about how the length of the examples in the training set impacts our ability to automatically classify excerpts of that same length as either human-written or machine-generated. ## dataset methodology all of our generated text samples are drawn from gpt-2, a state-of-the-art transformer-based generative language model that was trained on text from popular web pages @xcite . while we use the gpt-2 large model with 774m parameters, we found that similar trends to those reported here hold in experiments with smaller language models. given an autoregressive language model that defines a probability distribution over the next token given the previous tokens in a sequence, a decoding strategy generates text by deciding how to output a token at each step based on the predicted distributions. perhaps the most straightforward decoding strategy is to randomly choose a token with probability proportional to its likelihood. a challenge with the random sampling approach is that these probability distributions often contain a long tail of vocabulary items that are individually low-probability but cumulatively comprise a substantial amount of probability mass. @xcite observe that choosing tokens from this tail often leads to incoherent generations. top-k sampling, nucleus sampling, and (in the extreme) beam search have all been proposed to heuristically promote samples with higher pertoken likelihoods. top-k and nucleus sampling both do so by setting the likelihood of tokens in the tail of the distribution to zero. top-k restricts the distribution to all but the k most likely tokens, where k is a constant @xcite . nucleus sampling, also called top-p, truncates the distribution at each decoding step t to the k t -most-likely next tokens such that the cumulative likelihood of these tokens is no greater than a constant p (holtzman et al., 2020). we thus consider three different decoding strategy settings: for each decoding method, we construct a training dataset by pairing 250,000 generated samples with 250,000 excerpts of web text. 5,000 additional paired samples are kept aside for validation and test datasets. lastly, we filter out excerpts with fewer than 192 wordpiece tokens @xcite (excerpts might be quite short if the model produces an end-of-text token early on). see appendix 1 for final dataset sizes. a crucial question when generating text with a language model is whether or not to provide a priming sequence which the language model should continue. unconditioned samples, where no priming text is provided, in conjunction with top-k sampling, lead to pathological behavior for discriminators as the first token of the generated text will always be one of k possible options. on the other hand, if long sequences of human text are used as priming, the space of possible generated sequences is larger, but the detection problem shifts from one of "how human-like is the generated text?" to "how well does the generated text follow the priming sequence?". since in this study we are interested in the former simpler question, we create two datasets, one with no priming, and one with the minimum amount of priming possible: a single token of web text. this means that for every excerpt of web text in the training set, there is an excerpt of machinegenerated text that starts with the same token. we find that even with limited priming, the ability of automatic detectors can be strongly impacted. to study the effect of excerpt length, we construct variations of the above datasets by truncating all excerpts to ten possible lengths ranging from 2 to 192 wordpiece tokens @xcite . in total, we obtain sixty dataset variations: one per sampling method, truncation length, and choice of priming or no priming. ## automatic detection method the primary discriminator we employ is a finetuned bert classifier @xcite . we fine-tune one instance of bert per dataset variation described above. for the longest sequence length, @xmath0, we compare bert's performance with several simple baselines that have been proposed in other work. fine-tuned bert we fine-tune bert-large (cased) on the task of labeling a sentence as human-or machine-generated. the models are trained for 15 epochs, with checkpoints saved every 1000 steps, and a batch size of 256. all results are reported on the test set using the checkpoint for which validation accuracy was highest. bag-of-words for each sequence, we compute a bag-of-words embedding where each dimension corresponds to a token in gpt-2's 50,000 token bpe vocabulary @xcite , and we count how many times that token appears in the text sequence. we then train a logistic regression binary classifier to predict human-or machinewritten given this 50,000-dimensional embedding. we experimented with truncating embedding size by removing entries for infrequent vocabulary words, but this did not improve performance. ## human detection method the human evaluation task is framed similarly to the automatic one. we ask the raters to decide whether a passage of text was written by a human or by a computer algorithm. (full instructions are in the appendix.) raters are allowed to choose between four options: "definitely" or "possibly" machine-generated and "definitely" or "possibly" human-written. they are first shown an excerpt of length 16 wordpiece tokens. after they make 1worccond ). note that p1.0 refers to untruncated random sampling, where we sample from 100% of the probability mass. the last column shows human performance on the same task where accuracy with a 50% baseline is computed by randomly pairing samples from each decoding strategy with a human-written sample. a guess, the length of the excerpt is doubled, and they are asked the same question again. this continues until the entire passage of length 192 tokens is shown. passages are equally likely to be humanwritten or machine-generated, with the machinegenerated excerpts being evenly split between the three sampling strategies considered in this paper. initially, amazon mechanical turk (amt) raters were employed for this task, but rater accuracy was poor with over 70% of the "definitely" votes cast for "human" despite the classes being balanced. accuracy, even for the longest sequences, hovered around 50%. the same study was then performed with university students who were first walked through ten examples (see appendix the human evaluation dataset consisted of 150 excerpts of web text and 50 excerpts each from the three decoding strategies. each question was shown to at most three raters, leading to 900 total annotations from the untrained workers and 475 from the expert raters. a more detailed breakdown can be found in the appendix. ## automatic detection results simple baselines logistic regression on bag-of-words is the best of the baselines, beating out the histogram-based methods. while gehrmann et al. (2019 ) report an auc of 0.87 on classifying text as real or generated using logistic regression on the four buckets of the gltr system, we report auc between 0.52 and 0.56 for this task. the discrepancy is likely due to the fact that the human-written text in our discriminator training set comes from the same distribution as the text used to train the language model, while in gltr the human text comes from children's books, scientific abstracts, and newspaper articles. the selection of training data for learned detection systems is crucial. in real-world applications, the choice ought to reflect the genres that builders of text-generation systems are trying to impersonate. fine-tuned bert in figure 1a , we begin by observing discriminator accuracy as a function of excerpt length and sampling method. as can be intuitively expected, as sequence length increases, so too does accuracy. for unconditioned text decoded with nucleus (p0.96) and untruncated (p1.0) random sampling, we find discriminator accuracy increases from 55%, near random, to about 81% for the longest sequences tested. in contrast, discriminators trained and evaluated on top-k achieve over 80% accuracy even on 16-token excerpts. why are top-k's samples so easy to detect? in figure 2b , we see the percentage of probability mass concentrated in the k most common token types for each sampling method. while random sampling and nucleus sampling are very similar to human-written texts, we see top-k concentrating up to 80% of its mass in the first 500 most common tokens. the other sampling methods as well as human-written texts require at least 1,100 token types for the same. it is clear that top-k's distribu- when generating with nucleus or untruncated random sampling, adding a priming token is not as impactful, as these methods are already sampling from a large fraction (or all) of the probability distribution. this is seen in figure 2a where at the very first step of unprimed generation, nucleus sampling selects from 3075 possible vocabulary words, and at later positions selects from on 3 when decoding from the gpt-2 small model with 117m parameters. ## conclusion in this work, we study the behavior of automated discriminators and their ability to identify machine-generated and human-written texts. we train these discriminators on balanced binary classification datasets where all machinegenerated excerpts are drawn from the same generative model but with different decoding strategies. we find that, in general, discriminators transfer poorly between decoding strategies, but that training on a mix of data from methods can help. we also show the rate at which discriminator accuracy increases as excerpts are lengthened. we further study the ability of expert human raters to perform the same task. we find that rater accuracy varies wildly, but has a median of 74%, which is less than the accuracy of our bestperforming discriminator. most interestingly, we find that human raters and discriminators make decisions based on different qualities, with humans more easily noticing semantic errors and discriminators picking up on statistical artifacts. in our experiments, these artifacts are most prominent with top-k sampling. however, any strategy that oversamples high-likelihood words is susceptible. as the p in nucleus sampling is set increasingly lower to achieve more fluent text (some systems are already using p as low as 0.5 @xcite ), the distributional deviations that plague top-k text will surface in nucleus sampling as well. holtzman et al. (2020) explain how a unique attribute of human language is that it dips in and out of low probability zones. this variance in likelihood is what makes human-written text interesting and exciting to read. today's generation systems have not yet solved the problem of mimicking the human cadence without introducing poor word choices that are easy for humans to detect. generation systems often optimize for fooling humans without acknowledging the trade-off that exists between human perception of quality and ease of automatic detection. we therefore suggest three prongs for future research: