SlowGuess/NAACL_2021_OCR huggingface dataset:
Aleem Khan, Elizabeth Fleming, Noah Schofield, Marcus Bishop, and Nicholas Andrews
Human Language Technology Center of Excellence
{akhan141,eflemin9,nschofil,marcus.bishop,noa}@jhu.edu
We consider the task of linking social media accounts that belong to the same author in an automated fashion on the basis of the content and metadata of their corresponding document streams. We focus on learning an embedding that maps variable-sized samples of user activity—ranging from single posts to entire months of activity—to a vector space, where samples by the same author map to nearby points. The approach does not require human-annotated data for training purposes, which allows us to leverage large amounts of social media content. The proposed model outperforms several competitive baselines under a novel evaluation framework modeled after established recognition benchmarks in other domains. Our method achieves high linking accuracy, even with small samples from accounts not seen at training time, a prerequisite for practical applications of the proposed linking framework.
The scale and anonymity of social media pose systematic challenges for manual moderation efforts (Pennycook et al., 2020; Broniatowski et al., 2018). These challenges have motivated the development of automated methods to identify abusive content, such as Davidson et al. (2017), which considers automatically classifying hate speech, or Alvari et al. (2019), which deals with detecting violent extremism, both in the Twitter domain.
However, automatic moderation remains a difficult problem. Indeed, existing methods based on hand-constructed resources such as keyword lists may fail to adapt to novel trends (Corbett-Davies and Goel, 2018) whereas automatic methods based on statistics of large corpora may exhibit harmful biases (Caliskan et al., 2017). Additionally, individual posts may fail to contain sufficient information to reliably identify them as harmful.
This work considers account-level moderation. Specifically, we consider the problem of determining whether two document streams share the same author, based on samples from those streams rather than individual documents. This capability has numerous applications, such as detecting users attempting to circumvent account bans, identifying sockpuppet accounts, and detecting coordinated disinformation campaigns involving multiple authors controlling multiple accounts.
As a motivating application, we consider the enforcement of account bans on anonymous platforms, such as Reddit. Given a new account, the problem is to automatically identify whether it matches any previously banned account, which amounts to making binary decisions about whether pairs of accounts share the same author. Variations of this problem have been studied before. For example, Schwartz et al. (2013) learn a classifier to determine whether the author of a Twitter comment belongs to a small, closed set of authors. In contrast, we are interested in an open-world setting, requiring binary decisions about arbitrary pairs of accounts. This introduces a number of challenges.
First, any individual comment may be too short to serve as the basis for linking accounts. Figure 1a illustrates this empirically using a variation of our model, where embeddings of individual comments from the same account fail to coalesce, making it difficult to assert that an account has the same author as another account. See §4 for further experimental details. Therefore, we focus on aggregating information across contiguous sequences of documents. Figure 1b illustrates the impact of aggregation using our full model, where aggregations of contiguous sequences of documents from the same account exhibit an approximate convergence behavior as the number of documents aggregated increases. In fact, the motivating application above requires linking accounts on the basis of samples of widely varying sizes. Indeed, banned accounts
Proceedings of the 2021 Conference of the North American Chapter of the Association for Computational Linguistics: Human Language Technologies, pages 5275-5287 June 6-11, 2021. ©2021 Association for Computational Linguistics
Figure 1: UMAP projections (McInnes et al., 2020) of embeddings of document streams. Each image shows the same 16 Reddit posts by 9 randomly chosen authors, connected chronologically. Posts by each author are shown in the same color in both figures.
(a) Embeddings of single posts by a model trained on single posts.
(b) Embeddings of samples by a model trained on variable-sized samples. For each author and each  $1 \leq j \leq 16$ , the  $j$ th point shows the embedding of the author's first  $j$  posts.
typically have many documents, all of which we would like to consider, while new accounts generally have few documents, which nevertheless must be linked to banned accounts as quickly as possible to mitigate abusive behavior.
The second challenge is that of spurious associations. For example, over a short period of time, an author may discuss only a single, narrow topic. While a naïve model based on word statistics alone might be sufficient to link such an account to another, this approach would fail to generalize over longer periods of time due to topic drift. Both our training procedure and evaluation framework have been designed to ensure that our model learns the appropriate invariances to identify same-authorship, rather than being correct for the wrong reasons (McCoy et al., 2019). Namely, samples from an account are drawn from different time periods in each training iteration (see §2.3), while the evaluation data consists of posts by accounts not seen at training time and is future to all the training data (see §4.2).
Finally, the numbers of banned and new accounts may be quite large, requiring a still larger number of pairwise comparisons. For this reason, our proposed approach to account linking consists of embedding variable-sized samples from document streams into a metric space whereby samples likely to have been composed by the same author map to nearby points. Under this embedding, comparisons between document streams amount to pairwise distance calculations, so our approach is highly scalable and amenable to various optimizations, such as approximate nearest neighbor methods.
Our primary contributions are the following:
- We provide a simple but effective data augmentation strategy which enables embedding variable-sized samples. In addition, we successfully train such an embedding on a large-scale dataset consisting of more than 300 million comments from 1 million distinct accounts using scalable losses.
- We propose a novel framework to assess account linking performance focused on challenging conditions and minimizing the impact of incidental authorship features, such as topic. In particular, we propose benchmark datasets as well as verification metrics tailored to our application.
Our code, data splits, and scripts to reproduce our experiments are available at http:// github.com/noa/naacl2021.
2 Learning embeddings of document streams
We treat a document stream as a sequence of times-tamped actions  $a_1, a_2, \ldots, a_L$  where each  $a_i$  is a structure containing the data comprising an action. The possible contents of  $a_i$  are specific to the document stream, but include at least a timestamp  $t_i$  such that  $t_1 < t_2 < \dots < t_L$ .
In this work we focus on textual content published on social media platforms, although the approach would easily extend to allow  $a_1, a_2, \ldots, a_L$  to contain other modalities such as images or video, which would be handled similarly. In addition, we
Figure 2: Illustration of the proposed model architecture. Each action  $a_i$  consists of text content  $x_i \in \mathbb{Z}^\ell$ , a subreddit feature  $r_i \in \mathbb{Z}$ , and is published at time  $t_i \in \{0,1,\dots,23\}$ . These elements are combined as shown using various embedding lookups  $E$ , one-dimensional convolutions  $C$ , and linear projections  $P$ , along with an attention mechanism  $A$  and a max pooling layer  $M$ .
also avail of certain categorical features contained in  $a_1, a_2, \ldots, a_L$  such as hashtags or the subreddit to which a comment was posted.
A sample from a document stream is a contiguous subsequence of its actions. We introduce an embedding  $f_{\theta}$  in §2.1 mapping a variable-sized sample to a point in a vector space, such that the Euclidean distance between the embeddings of two samples quantifies the likelihood that they belong to the same author.
We define an embedding  $f_{\theta}$  as follows. This embedding is illustrated in Figure 2. Consider a sample  $a = (a_1, a_2, \ldots, a_M)$  where each action  $a_i$  consists of a subreddit feature  $r_i$ , a timestamp  $t_i$ , and text content  $x_i$ .<sup>1</sup> We encode  $t_i$  as the corresponding hour of the day and  $r_i$  by lookup in the list of 2048 most common subreddits, resulting in  $t_i \in \{0, 1, \ldots, 23\}$  and  $r_i \in \{0, 1, \ldots, 2048\}$ , where  $r_i = 2048$  when the subreddit is not among the top 2048. We encode the text feature using the SentencePiece unigram subword model (Kudo, 2018), resulting in  $x_i \in \mathbb{Z}^\ell$ , where the parameter  $\ell$  is defined in §2.2. Note that the chosen vocabulary size impacts the amount of content that can be encoded with  $\ell$  integers. Further details on the choice of text encoding are provided in Appendix C.
We replace each token of  $x_{i}$  with a correspond-
ing learned embedding in  $\mathbb{R}^N$  for all  $1\leq i\leq M$  resulting in  $M$  matrices in  $\mathbb{R}^{\ell \times N}$ . We apply one-dimensional convolutions of widths 2, 3, and 4 along the first axis of each, concatenate the convolved matrices along their second axes, max-pool along the first axis, and concatenate the results with learned embeddings of the corresponding subreddit features and one-hot encodings of the corresponding time features, resulting in  $M$  vectors, which we aggregate using dot-product attention. The resulting sequence of vectors is projected to a single vector through max-pooling followed by two fully-connected layers with bias, resulting in the encoding  $f_{\theta}(a)\in \mathbb{R}^{D}$  of the sample  $a$ .
2.2 Text Sampling
The variance in the lengths of documents poses computational challenges when aggregating large samples. Therefore we resort to truncating each document to a fixed number  $\ell$  of tokens, padding any documents containing fewer than  $\ell$  tokens. We take  $\ell = 32$  after observing that Reddit posts have an average length of approximately 43 tokens (see Appendix D).
We also experimented with a more complicated text sampling strategy, namely sampling contiguous segments of  $\ell$  tokens from each post uniformly at random during training. While this approach leverages all available textual information by affording slightly different samples of each post in each iteration of training, we found it to yield similar results and also complicates the comparison to our primary baseline model, which uses the prefix
<sup>1</sup>In addition to  $r_i, t_i, x_i$  platforms like Reddit contain further metadata, such as the thread title and the submission and parent comments, all of which might help distinguish users because users read them and chose to respond. Incorporating these features would be interesting to explore in future work.
Figure 3: In contrast with choosing sample sizes uniformly at random, sampling according to a left skewed Beta distribution results in more samples of sizes closer to the specified maximum.
method described above.
2.3 Sample selection
During training we randomly select document stream samples of sizes varying between  $R = 1$  and  $S = 16$ , which we regard as hyperparameters of the model. To select a sample from the stream  $a_1, a_2, \ldots, a_L$  we first choose its length  $M = R + \lceil x(S - R) \rceil$  where  $x \sim \mathrm{Beta}(3,1)$  and take the sample  $a_i, a_{i+1}, \ldots, a_{i+M-1}$  where  $1 \leq i \leq L - M + 1$  is chosen uniformly at random. Selecting  $M$  according to Beta (3,1) provides an expected sample size closer to  $S$  than to  $R$ , a tradeoff that allows the model to quickly learn features of a document stream by exposing it to larger samples most of the time, while still maintaining the flexibility to handle samples of varying sizes. Indeed, the latter is critical in the evaluation described in §4.3, which requires linking large samples to small samples. The density function of Beta (3,1) is shown in Figure 3 together with that of the uniform distribution Unif (0,1) for comparison. We explore the benefits of Beta (3,1) and other related distributions in §4.5.
2.4 Scalable deep metric learning losses
Deep metric learning methods aim to embed observations into a low-dimensional space such that instances from the same class map to nearby points under a chosen metric, such as Euclidean distance. In our setting, we take the instances to be document stream samples and the classes to be the corresponding accounts, which serve as proxies for latent authorship. Therefore, training the mapping  $f_{\theta}$  defined in §2.1 using metric learning affords an embedding under which samples by the same author map to nearby points.
Recent work in deep metric learning has introduced a number of training objectives with state of the art performance on computer vision tasks (Kim et al., 2020; Wang et al., 2019). Unfortunately, many of these objectives scale linearly with the number  $K$  of classes considered due to a costly linear projection onto  $\mathbb{R}^K$ . Note that because account names in effect provide labels for the corresponding document streams, we may use raw social media content to fit our model directly, availing of a virtually unlimited source of data. We stipulate that the ability to exploit larger amounts of data may be more important than per-example efficiency, and therefore consider the classical triplet loss (Schroff et al., 2015) in our experiments, whose complexity does not depend on  $K$ . In particular, we use semi-hard negative mining with a fixed margin penalty. We also consider the top-  $k$  loss recently proposed by Lu et al. (2019), which optimizes precision-at-  $k$  as follows. Given targets ranked by similarity to a query, top-  $k$  arranges for as many matches as possible to be among the top  $k$  ranked targets. It accomplishes this by penalizing only those targets that would need to move the smallest amount in order to maximize the number of matching targets among the top  $k$ . Like triplet loss, top-  $k$  also uses an additive margin penalty to separate classes. See Appendix A for further experimental details on both loss functions.
The separate but related problem of closed-world author attribution has received considerable attention. For example, the PAN 2019 challenge (Daelemans et al., 2019) employed a closed-world setting with a small number of authors that are the same at training and test time. That task also considered longer documents, obviating the need for aggregating evidence of authorship across multiple documents.
Generic text embedding methods such as the universal sentence encoder (Cer et al., 2018) and BERT (Devlin et al., 2019) are fit using auxiliary tasks, such as conditional language modeling. In the case of BERT, this is usually followed by supervised fine-tuning for a downstream task of interest. In this work, we are interested in learning representations that are immediately useful for our account linking task. However, because a large corpus of task-specific training data may be collected without human supervision, the benefits of generative pre
training are diminished in our setting. Indeed, the parameters of the text encoding are learned from a random initialization in all our experiments. Our approach is further distinguished from generic embedding methods by featuring a multi-document embedding, mapping a sequence of documents to a single vector, where each document may consist of both text and metadata.
The most closely related prior work is the Invariant User Representation (IUR) proposed by Andrews and Bishop (2019), whose approach is broadly similar to ours, but only considers samples of a fixed size. Our approach may be viewed as a generalization of that work in support of the account linking task. In addition we use a simpler dot product attention mechanism and introduce the use of scalable metric learning losses in §2.4, which enable us to train our model on an order of magnitude more data than previously considered. We validate these improvements in §4.2 using the ranking task proposed by Andrews and Bishop (2019). We also adapt IUR to serve as a baseline in our primary linking task in §4.3.
We believe that our treatment of account linking as a pairwise recognition task between document stream samples and our proposed general-purpose evaluation protocols are both novel. However, in prior work, there have been several platform-specific approaches to account linking. For example Silvestri et al. (2015) explore a heuristic approach to linking accounts across social media platforms. Separately, on platforms with rich social network information, graph-matching methods have been explored (Fan, 2012). Our focus is on content-based account linking, which is more general than prior methods we are aware of. Some other related but distinct problems include detecting deceptive accounts (Van Der Walt and Eloff, 2018) and authorship classification of short messages (Ishihara, 2011).
We conduct evaluations on the two primary tasks illustrated in Figure 4. First, our ranking evaluation described in §4.2 is motivated by information retrieval needs. Although ranking is not the focus of this paper, it provides an assessment of the quality of the learned embedding in terms of similarity judgements and facilitates comparison with the baseline model IUR. In addition, we use the ranking evaluation to monitor training using de
Model	Features	Loss	MRR	R@4	R@8
Prop	TPS	Top-k	0.637	0.709	0.765
Prop	TPS	Triplet	0.634	0.702	0.762
Prop	TP	Top-k	0.450	0.522	0.595
Prop	TP	Triplet	0.452	0.520	0.591
Prop	T	Triplet	0.372	0.439	0.512
IUR	TPS	Arcface	0.520	0.590	0.650
IUR	T	Arcface	0.200	0.240	0.290
Table 1: Ranking results for the proposed model (Prop) and the baseline (IUR), both trained and evaluated using various combinations of text content (T), publication time (P), and subreddit (S). IUR results are reported from Andrews and Bishop (2019).
velopment data disjoint from the test data used for the final evaluation. Second, we introduce an account linking evaluation framework in §4.3 inspired by similar evaluations used for speaker recognition (Doddington et al., 2000; Van Leeuwen and Brümmer, 2007). Both evaluations involve setting up two sets of samples as described below, the queries and the targets. For each query, there is exactly one target drawn from the same document stream. Roughly speaking, both evaluations involve matching targets with their corresponding queries.
4.1 MUD: a Web-scale training dataset
Reddit is currently one of the most popular social media platforms, where anonymous users interact primarily by posting comments to discussion threads. Together with its text content, each comment is labeled by its publication time and the subreddit to which it was posted, a categorical feature roughly indicating its topic.
We construct a dataset consisting of 300 million Reddit posts from 1 million users published over an entire year to be used to train our proposed model. This Million User Dataset (MUD) consists of all posts by authors who published at least 100 and at most 1000 posts between July 2015 and June 2016, where the lower bound ensures a sufficiently long history from which to sample, and the upper bound is intended to reduce the impact of bot and spam accounts. We obtained the data by drawing from the existing Pushshift Reddit corpus (Baumgartner et al., 2020). Some further statistics of MUD are shown in Table 8.
(a) Ranking evaluation: for each query, the targets are ranked by similarity to the query.
(b) Linking evaluation: for each target, the queries are determined to match each query or not.
Figure 4: Illustrations of our two primary evaluation frameworks. Document stream samples are shown as stacks of documents of sizes reflecting the corresponding sample sizes.
4.2 Ranking evaluation
As shown in Figure 4a, the ranking experiment consists of ranking the targets by similarity to each query. For compatibility, we mimic the experimental setup from Andrews and Bishop (2019), which proposes separate sets of queries and targets to be used for training and testing. We adopt the training split for validation and the testing split for evaluation, although we train our model on MUD (see §4.1). We select hyperparameters based on dev split performance (see Appendix A). The test split consists of samples, each of size exactly 16, although we train the proposed model using samples from MUD of varying sizes as described in §2.3. Note that the posts comprising MUD precede those of both IUR splits in publication time, ensuring that our training data is disjoint from IUR's test data. Of the 111,396 authors contributing to the test split, 69,275 or  $62\%$  contribute to the IUR training split. In contrast, MUD has only 39,529 users in common with the test split, a significantly smaller overlap than IUR. In principle, the increase in novel users at test time puts the proposed model at a disadvantage because it places more importance on generalization to novel users.
We report recall-at-  $k$ $(\mathbf{R}@\boldsymbol{k})$  and mean reciprocal rank (MRR),calculated exactly as in Andrews and Bishop (2019). MRR is the expected value of the reciprocal of the position of the correct target in the ranked list.  $\mathbf{R}@\boldsymbol{k}$  is the probability that the unique target composed by the same author as a given query appears in the top  $k$  ranked results. We
limit ourselves to R@4 and R@8 as proxies for the "first page" of search results returned to a user issuing a query.
The results of this evaluation calculated with the test split are shown in Table 1. Note that the full version of the proposed model significantly outperforms the previously published state-of-the-art.2 We conclude that although the angular margin loss used by Andrews and Bishop (2019) is considered state-of-the-art, the simpler triplet loss outperforms it, most likely because it admits the use of a considerably larger dataset. We remark that the models trained with top-  $k$  performed only slightly better than those trained with triplet loss, an observation consistent with recent findings that when matching experimental conditions, the choice of ranking loss is less important than previously believed (Musgrave et al., 2020).
In addition, Figure 5 shows the results of the evaluation performed after every hour of training. Note that after only six hours of training the full model outperforms the baseline. Figure 5 also shows the learning curve for an ablation of our model that eliminates the subreddit feature. We observe that this ablated model performs almost as well as the full-featured baseline, which suggests that the proposed approach may be effective in domains where only text and timestamps are
$^2$ A paired sign test of the differences in ranking between IUR and the proposed model is significant at the  $p < 10^{-15}$  level.
3 Although we generated Figure 5 post-hoc using test data, we did not use test data for model or hyperparameter selection.
available.
Figure 5: Test results after every hour of training for the proposed model using combinations of text (T), publication time (P), and subreddit (S) features as shown. The baseline result 0.65 shown as a dashed line is reported from Andrews and Bishop (2019) and corresponds with a model availing of all three features.
4.3 A new framework for account linking