SlowGuess/NAACL_2021_OCR huggingface dataset:
Wilson Fearn
Brigham Young University
wilson.fearn@gmail.com
Orion Weller
Brigham Young University oweller@byu.edu
Kevin Seppi
Brigham Young University  
kseppi@byu.edu
Text classification is a significant branch of natural language processing, and has many applications including document classification and sentiment analysis. Unsurprisingly, those who do text classification are concerned with the run-time of their algorithms, many of which depend on the size of the corpus' vocabulary due to their bag-of-words representation. Although many studies have examined the effect of preprocessing techniques on vocabulary size and accuracy, none have examined how these methods affect a model's run-time. To fill this gap, we provide a comprehensive study that examines how preprocessing techniques affect the vocabulary size, model performance, and model run-time, evaluating ten techniques over four models and two datasets. We show that some individual methods can reduce run-time with no loss of accuracy, while some combinations of methods can trade  $2 - 5\%$  of the accuracy for up to a  $65\%$  reduction of run-time. Furthermore, some combinations of preprocessing techniques can even provide a  $15\%$  reduction in run-time while simultaneously improving model accuracy. $^{1}$
With the increasing amount of text data available, text analysis has become a significant part of machine learning (ML). Many problems in text analysis use ML methods to perform their task, ranging from classical problems like text classification and topic modeling, to more complex tasks like question answering. Although neural networks have become increasingly common in the research field, many industry NLP problems can be well served by less complex but more efficient and explainable models, such as Support Vector Machines (SVMs) or K-Nearest Neighbors (K-NN).
We focus on the text classification problem, where the dominant approach to using these nonneural models is to first calculate the number of unique terms in the dataset (the vocabulary, size  $V$ ) and encode each instance of the dataset into a bag-of-words (BoW) representation (Joachims, 1998; Zhang et al., 2010). This results in a high-dimensional vector of size  $V$  that indicates whether each given word of the vocabulary was used in this instance.
However, the vanilla approach to the BoW representation can lead to sub-par performance, as shown by numerous studies that have examined how preprocessing techniques affect the BoW w.r.t. performance and vocabulary size. These studies have examined this representation in fields such as information retrieval (Chaudhari et al., 2015; Patil and Atique, 2013; Beil et al., 2002; Senuma, 2011), text classification (Yang and Pedersen, 1997; Caragea et al., 2012; Uysal and Gunal, 2014; Vijayarani et al., 2015; Kumar and Harish, 2018; HaCohen-Kerner et al., 2020; Symeonidis et al., 2018) and topic modeling (Schofield and Mimno, 2016; Blei et al., 2003). They suggest a myriad of preprocessing techniques that could improve performance, ranging from choosing features that have high mutual information, low frequency, or simply remove punctuation.
Another related problem of the BoW representation is that this sparse high-dimensional vector does not scale well to datasets with large vocabularies. As preprocessing techniques help contribute to a reduced vocabulary, they should also help alleviate this scaling problem, at least according to folklore. However, to the best of our knowledge, no previous study of preprocessing techniques have examined how they contribute to reduced run-time costs, leading to uncertainty about what these techniques do to mitigate the computational complexity in practice.
To remedy this, we analyze how these prepro
1Our code and results are publicly available at https: //github.com/wfearn/preprocessing-paper
Proceedings of the 2021 Conference of the North American Chapter of the Association for Computational Linguistics: Human Language Technologies, pages 3069-3082 June 6-11, 2021. ©2021 Association for Computational Linguistics
Figure 1: Comparing vocabulary size (in millions) vs the total number of words (in 10s of millions) for the AP News and Amazon corpora. Note that the vocabulary size of AP News w.r.t. the number of documents plateaus much faster than the noisier Amazon corpus.
cessing methods affect not only vocabulary size and performance, but also how they affect training and inference time. To do this, we contribute a comprehensive analysis of 10 different preprocessing methods applied to four machine learning models, evaluated on two datasets with widely varying vocabularies (Figure 1).
Our results show that the individual preprocessing methods provide widely different effects on run-time, with some methods (i.e. rare word filtering and stopwords removal) providing significant run-time reductions without losing any performance. We also show that some combinations of preprocessing methods both improve performance and reduce run-time.
Datasets To see how preprocessing affects runtime, we examine two datasets (in English): the Amazon (He and McAuley, 2016) $^2$  and AP News corpora (MacIntyre, 1998). These datasets were chosen because of the wide disparity between their vocabularies. The Amazon corpus comes from user product reviews and contains a much higher vocabulary relative to the number of documents, due to its noisy text. The AP News corpus contains professionally-edited news articles and its vocabulary plateaus much faster than the Amazon corpus (Figure 1). We perform sentiment analysis on Amazon and year classification on AP News and report scores with the accuracy metric. We note
that we also computed the F1 score alongside accuracy and found our results to be similar; thus we report accuracy since it is easier to understand.
To test the effect of document size on preprocessing, we sampled various-sized<sup>3</sup> datasets from the original corpus and ran our analysis on each, sampling 5 different times with differing random seeds.<sup>4</sup> However, we found that our results were nearly identical across the differing corpus sizes and thus, only report numbers for the 100k size.
Preprocessing Methods We analyze 10 different methods (with their shortened names in parenthesis): lowercasing (lower), rare word filtering (rare), hashing (hash), punctuation removal (nopunct), stopwords removal (stop), number removal (nrem), word stemming (stem), lemmatization (lemma), spelling correction (spell), and word segmentation (seg). We choose these methods because of their prevalence in previous work (Symeonidis et al., 2018; Kumar and Harish, 2018; HaCohen-Kerner et al., 2020) and their use in industry (Li et al., 2013; Sanchez-Pi et al., 2014).
Due to the exponential number of possible preprocessing combinations, we run all individual methods but restrict the search space of combinations of these methods. For rare word filtering and word hashing, we first conduct experiments for 9 different levels of filtering individually, using only the best level in future combinations with other methods. Results for all levels of filtering and hashing are in Appendices A and B. We then conduct experiments for all 24 combinations of spelling correction, word segmentation, number removal, and stopwords removal, using the best outcome (the pipeline of all four) to combine with other methods. We note that while this is not an exhaustive search of all combinations, our analysis includes the standard preprocessing pipelines as well as many more.
Models We use Scikit-Learn (Pedregosa et al., 2011) for three of the base algorithms, including K-NN (Altman, 1992), Naive Bayes (Rish et al., 2001), and the Support Vector Machine (SVM, (Suykens and Vandewalle, 1999)). We also employ Vowpal Wabbit (Langford et al., 2007; Karampatziakis and Langford, 2010), due to its strong performance and frequent use in industry.
35k, 10k, 20k, 30k, 40k, 50k, and 100k instances
4 Although the Amazon corpus contains many more documents, we keep our sampling consistent with the AP News corpus, as AP News has only 600k instances.
<sup>2</sup>http://jmcauley.ucsd.edu/data/amazon/
Group	Method	Vocab Size ↓	Train Time ↓	Test Time ↓	Accuracy ↑
Individual Methods	stop	99.8 ± 0.2	69.5 ± 1.4	79.0 ± 3.5	97.4 ± 2.2
rare	1.0 ± 0.0	80.6 ± 3.0	70.3 ± 3.2	99.3 ± 2.8
seg	24.6 ± 0.2	93.7 ± 2.4	80.3 ± 2.5	100.6 ± 1.6
spell	57.8 ± 0.2	95.1 ± 2.6	89.7 ± 2.6	99.4 ± 2.3
hash	10.1 ± 0.0	97.1 ± 4.0	75.7 ± 4.0	99.2 ± 1.1
nopunct	61.9 ± 0.2	97.5 ± 2.2	89.5 ± 2.0	100.7 ± 1.6
stem	81.7 ± 0.4	97.8 ± 2.0	95.0 ± 2.6	99.8 ± 1.0
lower	88.7 ± 0.3	101.7 ± 7.5	100.1 ± 6.6	99.1 ± 3.0
nrem	96.2 ± 0.7	101.7 ± 4.0	100.7 ± 5.3	99.7 ± 1.2
lemma	98.1 ± 0.5	102.2 ± 5.3	101.5 ± 5.1	100.3 ± 1.1
Lowest Train/Test Time	spell+seg+nrem+stop+rare	0.8 ± 0.0	44.6 ± 1.0	56.8 ± 1.1	95.4 ± 2.0
stop+rare	0.9 ± 0.0	46.5 ± 3.5	44.5 ± 2.0	99.8 ± 0.8
spell+seg+nrem+stop+hash	7.6 ± 0.0	53.9 ± 2.0	39.6 ± 1.4	97.7 ± 2.6
spell+seg+nrem+stop	14.1 ± 0.0	54.2 ± 1.6	50.9 ± 2.3	97.6 ± 2.2
spell+seg+nrem+stop+lemma	11.9 ± 0.0	55.1 ± 0.9	50.1 ± 1.7	97.6 ± 1.3
Highest Accuracy	nopunct+rare	0.9 ± 0.0	82.6 ± 1.9	70.2 ± 1.7	101.0 ± 1.8
lower+nopunct+nrem+rare	0.9 ± 0.0	87.1 ± 5.5	88.8 ± 5.1	101.1 ± 0.3
lower+nopunct+rare	0.9 ± 0.0	86.1 ± 2.7	86.7 ± 2.2	101.3 ± 0.6
seg+rare	0.9 ± 0.0	86.3 ± 5.8	73.3 ± 3.9	101.4 ± 1.5
spell+seg+rare	0.9 ± 0.0	89.6 ± 5.6	88.4 ± 5.3	101.8 ± 0.5
Table 1: Effect of preprocessing techniques on Amazon. Scores are the relative performance of each method over the no preprocessing baseline (e.g. stopwords removal takes only  $69.5\%$  of the baseline's training time). Results are the average (and std) relative performance of the four models, across the five dataset seeds. Bold indicates statistical similarity to the best score, from a two-sample t-test with  $\alpha = 0.05$ . For brevity, this table only includes individual methods and those with the highest accuracy or lowest train/test time. All results are in Appendix C.
All models use default hyperparameters and our document representations use the BoW representation, consisting of a sparse vector format. These four models provide a wide range of algorithms that might be used, allowing us to show how preprocessing methods generalize across models.
Compute All experiments were performed using 14-core Intel Broadwell processors running at  $2.4\mathrm{GHz}$  with 128GB of DDR4 2400 MT/s RAM.
We format our results relative to the algorithm with no preprocessing, to easily show how preprocessing changes this baseline performance. We first run each algorithm with no preprocessing, measuring the run-time, vocabulary size, and accuracy. We then report the scores of each preprocessing pipeline relative to the algorithm's baseline (e.g. a model with preprocessing that scores  $75\%$  of the no-preprocessing baseline's accuracy has a relative accuracy of 0.75).
As the cross product of the number of methods vs. the number of models is still far too large to include in this paper, we show the average of each model's relative proportion to its respective baseline performance.<sup>5</sup> This aggregation shows us
the average relative performance across the four models, helping us generalize our results to be model-independent. For full tables detailing specific model results, see Appendix C. Bold scores in tables indicate statistical similarity to the best score in the column (two-sample t-test,  $\alpha = 0.05$ ).
Individual Techniques We see results for the Amazon corpus in Table 1 and for the AP News corpus in Table 2. On Amazon, each individual preprocessing method performs statistically similar to the baseline's accuracy, while three algorithms (stopword removal, rare word filtering, and word segmentation) also provide a moderate decrease  $(20 - 30\%)$  in train and test time. Rare word filtering and stopwords removal are effective across both corpora (with rare word filtering being even more effective on AP News, reducing the training time in half), while the other methods do not significantly impact either train-time or accuracy on AP News. We hypothesize that these techniques are more effective on the AP corpus because of its much smaller (and less varied) vocabulary.
baseline (e.g. SVM with rare word filtering vs SVM with no preprocessing) and then take the average of the models for that method (e.g. average the relative performance of rare word filtering on models {K-NN, Naive Bayes, SVM, and Vowpal Wabbit} for the final score for rare word filtering).
We first compute each algorithm's relative score to its
Group	Method	Vocab Size ↓	Train Time ↓	Test Time ↓	Accuracy ↑
Individual Methods	rare	0.1 ± 0.0	51.4 ± 1.2	59.1 ± 2.2	99.8 ± 2.0
stop	99.5 ± 0.3	82.5 ± 2.9	86.4 ± 2.0	99.0 ± 1.4
hash	32.8 ± 0.0	98.5 ± 4.7	84.7 ± 4.0	99.5 ± 1.7
spell	65.6 ± 0.2	98.6 ± 4.7	95.2 ± 7.4	99.7 ± 0.9
lower	92.3 ± 0.3	98.9 ± 1.9	97.6 ± 3.5	99.8 ± 1.6
stem	82.7 ± 0.4	99.1 ± 5.2	95.2 ± 4.0	100.1 ± 1.4
seg	47.5 ± 0.2	99.5 ± 2.4	88.5 ± 2.9	100.3 ± 1.3
nrem	89.8 ± 0.4	99.8 ± 3.9	98.5 ± 5.0	99.2 ± 1.1
nopunct	65.6 ± 0.2	99.9 ± 4.6	92.9 ± 4.9	99.6 ± 1.4
lemma	97.4 ± 0.3	100.5 ± 1.2	98.6 ± 1.6	99.6 ± 1.7
Lowest Train/Test Time	spell+seg+nrem+stop+rare	0.1 ± 0.0	29.2 ± 0.5	49.0 ± 0.8	99.3 ± 1.7
spell+nopunct+nrem+stop	39.9 ± 0.1	71.0 ± 1.8	69.4 ± 1.8	100.1 ± 1.0
spell+nopunct+nrem+stop+lemma	36.2 ± 0.1	71.3 ± 1.3	68.4 ± 1.4	99.1 ± 1.6
spell+seg+nrem+stop	29.3 ± 0.0	72.1 ± 1.8	65.4 ± 3.2	100.1 ± 1.4
spell+nopunct+nrem+stop+stem	29.6 ± 0.1	72.4 ± 1.2	68.2 ± 1.8	98.7 ± 1.8
Highest Accuracy	spell+seg+nrem+stop+stem	19.3 ± 0.1	74.2 ± 2.3	66.9 ± 1.5	99.7 ± 1.6
spell+nopunct+nrem+stop	39.9 ± 0.1	71.0 ± 1.8	69.4 ± 1.8	100.1 ± 1.0
spell+seg+nrem+stop	29.3 ± 0.0	72.1 ± 1.8	65.4 ± 3.2	100.1 ± 1.4
spell+seg+nrem+stop+hash	19.8 ± 0.0	73.1 ± 2.7	66.6 ± 3.4	100.2 ± 1.5
lower+nopunct+nrem+stop+stem	39.4 ± 0.4	75.5 ± 2.4	72.7 ± 3.0	100.3 ± 1.0
Table 2: Effect of preprocessing techniques on AP News. Scores are the relative performance of each method over the no preprocessing baseline (e.g. stopwords removal takes only  $82.5\%$  of the baseline's training time). Results are the average (and std) relative performance of the four models, across the five dataset seeds. Bold indicates statistical similarity to the best score, from a two-sample t-test with  $\alpha = 0.05$ . For brevity, this table only includes individual methods and those with the highest accuracy or lowest train/test time. All results are in Appendix C.
Combination Techniques The combination techniques also show a mild impact on accuracy, with most methods on both corpora performing statistically similar to the baseline. On the Amazon corpus, a handful of methods trade  $2 - 5\%$  of accuracy for up to a  $65\%$  reduction in training and testing time ("Lowest Train/Test Time" section in Table 1). Those that do not reduce accuracy (such as stop+rare) can still reduce the training and testing time by up to  $55\%$ . We see in the "Highest Accuracy" section that some methods (i.e. spell+seg+rare, etc.) can even improve performance by almost  $2\%$  while also reducing run-time by  $10 - 15\%$ . Similarly, when we examine the results on AP News we can find combinations with reduced run-time (up to  $70\%$  and  $50\%$  reductions in train and test time respectively) with no accuracy loss (but also no gains).
Correlations In order to show the correlation between run-time and the other variables, we show a heatmap of these correlations in Figure 2. Most of these variables are highly correlated with each other, as expected (training time is highly correlated with testing time, etc.). However, although testing time is highly correlated with vocabulary size (0.8 correlation), training time is not highly correlated (0.17). We hypothesize that a low vo
cabulary directly leads to faster inference, while which words are removed from the vocabulary has a bigger role in how quickly the algorithm converges during training. This hypothesis is also supported by the low correlation between vocabulary size and accuracy, indicating that what is in the vocabulary is more important than its size.
Figure 2: Pearson correlation between the relative performance variables (train time, test time, accuracy, and vocabulary size) from the results of the different preprocessing methods.
These experiments relate to a large body of work that considers how preprocessing methods affect the downstream accuracy of various algorithms, ranging from topics in information retrieval (Chaudhari et al., 2015; Patil and Atique, 2013; Beil et al., 2002), text classification and regression (Forman, 2003; Yang and Pedersen, 1997; Vijayarani et al., 2015; Kumar and Harish, 2018; HaCohen-Kerner et al., 2020; Symeonidis et al., 2018; Weller et al., 2020), topic modeling (Blei et al., 2003; Lund et al., 2019; Schofield and Mimno, 2016; Schofield et al., 2017a,b), and even more complex tasks like question answering (Jijkoun et al., 2003; Carvalho et al., 2007) and machine translation (Habash, 2007; Habash and Sadat, 2006; Leusch et al., 2005; Weller et al., 2021; Mehta et al., 2020) to name a few. With the rise of noisy social media, text preprocessing has become important for tasks that use data from sources like Twitter and Reddit (Symeonidis et al., 2018; Singh and Kumari, 2016; Bao et al., 2014; Jianqiang, 2015; Weller and Seppi, 2020; Zirikly et al., 2019; Babanejad et al., 2020).
The closest lines of work to ours are those that examine how preprocessing affects text classification accuracy, where recent works like Symeonidis et al. (2018) and HaCohen-Kerner et al. (2020) analyze and cross-compare up to 16 different techniques for four machine learning algorithms. In contrast, our work is the first to examine these preprocessing techniques beyond accuracy, examining them in tandem with how they affect vocabulary size and run-time.
In this work we conduct the first study that examines the relationship between vocabulary size, run-time, and accuracy across different models and corpora for text classification. In general, we find that although vocabulary size is highly correlated with testing time, it is not highly correlated with training time or accuracy. In these cases, the specifics of the preprocessing algorithm (the content of what it removes) matter more.
Our experiments show that rare word filtering and stopwords removal are superior to many other common preprocessing methods, both in terms of their ability to reduce run-time and their potential to increase accuracy. By using these methods, we show that it is possible to reduce training and test-
ing time by up to  $65\%$  with a loss of only  $2 - 5\%$  of accuracy, or in some cases, to provide accuracy and run-time improvements simultaneously. We hope that this study can help both researchers and industry practitioners as they design machine learning pipelines to reach their end-goals.
Naomi S Altman. 1992. An introduction to kernel and nearest-neighbor nonparametric regression. The American Statistician, 46(3):175-185.
Nastaran Babanejad, Ameeta Agrawal, Aijun An, and Manos Papagelis. 2020. A comprehensive analysis of preprocessing for word representation learning in affective tasks. In Proceedings of the 58th Annual Meeting of the Association for Computational Linguistics, pages 5799-5810.
Yanwei Bao, Changqin Quan, Lijuan Wang, and Fuji Ren. 2014. The role of pre-processing in twitter sentiment analysis. Intelligent Computing Methodologies Lecture Notes in Computer Science, page 615-624.
Florian Beil, Martin Ester, and Xiaowei Xu. 2002. Frequent term-based text clustering. In Proceedings of the Eighth ACM SIGKDD International Conference on Knowledge Discovery and Data Mining, pages 436-442. Association for Computing Machinery.
David M Blei, Andrew Y Ng, and Michael I Jordan. 2003. Latent Dirichlet allocation. Journal of Machine Learning Research, 3(Jan):993-1022.
Cornelia Caragea, Adrian Silvescu, and Prasenjit Mitra. 2012. Combining hashing and abstraction in sparse high dimensional feature spaces. In Association for the Advancement of Artificial Intelligence.
Gracinda Carvalho, David Martins de Matos, and Victor Rocio. 2007. Document retrieval for question answering: a quantitative evaluation of text preprocessing. In Proceedings of the ACM first Ph.D. workshop in CIKM, pages 125-130.
Anagha Chaudhari, Pravin M Phadatare, Pranil S Kudale, Raviraj B Mohite, Rohan P Petare, Yogesh P Jagdale, and Amitabh Mudiraj. 2015. Preprocessing of high dimensional dataset for developing expert in system. In 2015 International Conference on Computing Communication Control and Automation, pages 417-421. IEEE.
George Forman. 2003. An extensive empirical study of feature selection metrics for text classification. Journal of Machine Learning Research, 3.
Nizar Habash. 2007. Syntactic preprocessing for statistical machine translation. MT Summit XI, pages 215-222.
Nizar Habash and Fatiha Sadat. 2006. Arabic preprocessing schemes for statistical machine translation. In Proceedings of the Human Language Technology Conference of the NAACL, Companion Volume: Short Papers, pages 49-52.
Yaakov HaCohen-Kerner, Daniel Miller, and Yair Yigal. 2020. The influence of preprocessing on text classification using a bag-of-words representation. PloS one, 15(5):e0232525.
Ruining He and Julian McAuley. 2016. Ups and downs: Modeling the visual evolution of fashion trends with one-class collaborative filtering. In Proceedings of the 25th International Conference on World Wide Web, pages 507-517. International World Wide Web Conferences Steering Committee.
Zhao Jianqiang. 2015. Pre-processing boosting twitter sentiment analysis? 2015 IEEE International Conference on Smart City/SocialCom/SustainCom (SmartCity).
Valentin Jijkoun, Gilad Mishne, Maarten de Rijke, et al. 2003. Preprocessing documents to answer Dutch questions. In Proceedings of the 15th Belgian-Dutch Conference on Artificial Intelligence (BNAIC'03), volume 434. Citeseer.
Thorsten Joachims. 1998. Text categorization with support vector machines: Learning with many relevant features. In European conference on machine learning, pages 137-142. Springer.
Nikos Karampatziakis and John Langford. 2010. Online Importance Weight Aware Updates. arXiv eprints, page arXiv:1011.1576.
HM Keerthi Kumar and BS Harish. 2018. Classification of short text using various preprocessing techniques: An empirical evaluation. In *Recent Findings in Intelligent Computing Techniques*, pages 19-30. Springer.
John Langford, Lihong Li, and Alex Strehl. 2007. Vowpal wabbit online learning project.
Gregor Leusch, Nicola Ueffing, David Vilar, and Hermann Ney. 2005. Preprocessing and normalization for automatic evaluation of machine translation. In Proceedings of the ACL Workshop on Intrinsic and Extrinsic Evaluation Measures for Machine Translation and/or Summarization, pages 17-24.
Huiying Li, Qiang Ye, and Rob Law. 2013. Determinants of customer satisfaction in the hotel industry: An application of online review analysis. Asia Pacific Journal of Tourism Research, 18(7):784-802.
J. Lund, Piper Armstrong, Wilson Fearn, Stephen Cowley, Emily Hales, and K. Seppi. 2019. Cross-referencing using fine-grained topic modeling. In NAACL-HLT.
Robert MacIntyre. 1998. North american news text supplement. LDC98T30, Linguistic Data Consortium.