{'fraction_non_alphanumeric': 0.026379012108399002, 'fraction_numerical': 0.008120315202767634, 'mean_word_length': 4.692833698030634, 'pattern_counts': {'":': 0, '<': 0, '<?xml version=': 0, '>': 0, 'https://': 1, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 2, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
Improving text classification with vectors of reduced precision

This paper presents the analysis of the impact of a floating-point number precision reduction on the quality of text classification. The precision reduction of the vectors representing the data (e.g. TF-IDF representation in our case) allows for a decrease of computing time and memory footprint on dedicated hardware platforms. The impact of precision reduction on the classification quality was performed on 5 corpora, using 4 different classifiers. Also, dimensionality reduction was taken into account. Results indicate that the precision reduction improves classification accuracy for most cases (up to 25% of error reduction). In general, the reduction from 64 to 4 bits gives the best scores and ensures that the results will not be worse than with the full floating-point representation.


I. INTRODUCTION
N ATURAL Language Processing (NLP), as well as Image Processing, is a part of Artificial Intelligence. Despite intensive research and huge recent progress in Deep Learning Techniques, applications of NLP have not reached a level that would allow a construction and a practical implementation of robots and machines operating like humans. Such human-level solutions would allow for seamless and smooth communication between machines and people. The future communication interfaces will allow to convey information directly to the machines processing units using natural language [1][2] [3]. This future vision, however, requires a substantial progress in both speech recognition and text processing domains. Applications of those two domains are in an essence very similar and share most of the processing flow. In our research [4] we focus on text processing, but the proposed modules may also be employed in voice processing solutions.
NLP as a research and application field has been developed in a course of last few decades [5] Language Processing [11]. This is due to its superior performance, which in turn results from the fact that it mimics the language representation within a human brain [12]. It is worth noting that a language as such belongs to a human cognition domain. It was developed by humans to enable communication and was implemented with biological components in a neural fashion [13]. Therefore, pure ontological models of the language tend to be inferior to the biologically-inspired ones [14].
Representation of knowledge within a human brain is highly distributed, sparse and hierarchical [12] [13]. Neural operations of cognition, which also involve language processing, are performed using single bit precision. Every bit of the information carries semantic meaning which reflects relationships between concepts acquired and stored within the brain. Inspired by this we decided to examine to what extent it is possible to implement such a bit processing scheme on a top of currently used models in NLP. We focused on the Vector Space Model as one which is popular and widely used in various applications. However, the research results may also be transferred to the other models since all of them employ vector as a basic representation structure. The vectors are a collection of fixed or floating-point numbers which represent a certain dynamic range of a data representation. It turns out that the dynamic range, at least in the case of floating-point numbers, is too large and can accommodate much more information than necessary. Therefore, we decided to reduce the range to the extent that, on the one hand still preserves a required precision and on the other hand substantially decreases the number of bits. Furthermore, such an approach also has a beneficial effect on semantics of the processed lingual content since it leads to a generalization. This, in turn, has all the positive properties of distributed representations [10]. Consequently, precision reduction of vector representation may be perceived as way of concept generalization or abstraction which is in its essence similar to latent semantic indexing [15] and random projection [16].
formance impact on standard processors, as they typically operate on fixed data width, usually stored in IEEE-754 floatingpoint representation. Therefore, reduction to below standard width or, moreover, not byte aligned width, does not introduce notable speedup. The situation improves for single instruction, multiple data (SIMD) processors, like general-purpose computing on graphics processing units (GPGPU), or vector CPUs however data alignment is still required and speedup is only achieved through parallelism and reduction of clock cycles required to process given an amount of data. Real benefits of precision reduction can be observed on fully customizable platforms, such as field-programmable gate arrays (FPGA) [17][18] [19]. They are not bound to any specific bitwidth or representation. Data may be stored in any integer bitwidth, which can also differ between consecutive processing stages. Narrower representation requires a less complicated circuit to execute calculations, which improves operating frequency. Switching to fixed point representation further reduces circuit complexity, thus increases operating frequency, which can also vary between processing stages. Data flow architecture can also be designed to process data in a parallel manner. A combination of aforementioned features makes FPGA a very interesting choice as a hardware platform. However, creating efficient design architecture and its implementation are not trivial and generate interesting research task. As authors of this paper already began work on the dedicated hardware platform and presented their initial results in [20], we will not cover this topic. Still much effort needs to be put into FPGA implementation in order to utilize its potential in NLP tasks.
Consequently, the paper addressed three main objectives: • an examination of the precision reduction impact on the text classification results, • proposition and practical verification of various popular classification methods with different grade of reduced precision, • building a framework for precision reduction which is available on-line.
The rest of the paper is organized as follows. Section II introduces vector space model as text documents representation. Section III describe a procedure of precision reduction used in our experiments. Sections IV and V describes SVD and parameters of the employed classifiers, respectively. Experiments are presented in Section VI. Finally, we present our conclusions in Section VII.

II. VECTOR SPACE MODEL
We decided to use Vector Space Model in our experiments to validate an adopted approach to semantic vector reduction. The section that follows may be considered as a short introduction to the model and its aspects that we address in the paper. The VSM has already been successfully used as a conventional method for the text representation [21]. The documents are represented as vectors in an N -dimensional vector space that is built upon the N different terms that occur in the considered document set (i.e. text corpus). Since the model ignores the order of the words it is usually called a bag-ofwords model, to reflect the proces of throwing the words form the text to an unstructured bag. The coefficients of the vector are the weights that identify the significance of a particular term in the document. Consequently, a set of documents in this scheme may be presented as the term-document matrix. An example of such a matrix is given in Table I. Fig. 1 presents a simple example of the three different documents mapped to the two-dimensional vector space, which means that they are built from two different words.
The text similarity can be easily calculated by the cosine similarity measure in the VSM. The cosine measure is given by the equation where v = (v 0 , . . . , v N −1 ) and u = (u 0 , . . . , u N −1 ) are the vectors representing documents.
The most common method of words weighing in VSM is the computation of the coefficients of so-called Term Frequencies (TF) and Inverted Document Frequencies (IDF). TF is the number of times a word appears in a given document that is normalized i.e. it is divided by the total number of words in a document under consideration. Respectively, IDF measures how common a word is among all documents in consideration. The more common the word is, the lower its IDF is. The IDF is computed as the ratio of the total number of documents to the number of documents containing a given word.
Consequently, TF-IDF is a numerical statistic that indicates how important the word is in characterizing a given document in the context of the whole collection. It is often used as a weighting factor in information retrieval 1 and text mining. The mathematical formula for TF-IDF computation is The tf t value is the term t t frequency in the document d, and it is computed as where n t is the number of occurrences of term t t in a document d∈D. The idf t value is the inverse document frequency that is given as where |D| is the number of documents in the corpus, and |{d ∈ D : t t ∈ d}| is the number of documents containing at least one occurrence of the term t t . The TF-IDF value increases proportionally to the number of times a word appears in the document, but it is scaled down by the frequency of the word in the corpus, which helps control the fact that some words are generally more common than others. Therefore, common words which appear in many documents will be almost ignored. Words that appear frequently in a single document will be scaled up. In this work, the algorithms use the TF-IDF coefficients.

III. PRECISION REDUCTION
Language models are usually very large multidimensional structures composed of vectors. The vectors contain IEEE-754 floating-point numbers which can be either stored in dense or sparse format for a sake of a storage space utilization reduction. In the sparse representation only non-zero vector elements are kept and the rest is skipped. Regardless of the representation, the low-level elements of the vectors are numbers. In order to reduce the representation precision, we apply a three-stage procedure given by Eq. 5, 7, 9, 11 and 13 for the IEEE-754 single precision case. The procedure for IEEE-754 double precision is the same and the equations were provided for a sake of completeness and consistency.
We reduce precision of each vector element given by Eq. 5 and 6: where S and n is a vector of IEEE-754 floating-point numbers and its dimension, respectively.
In the first step a vector of floating-point numbers: Eq. 5 and 6 are mapped to the fixed-point representation: Eq. 7 and 8 by means of projection operation: Eq. 9 and 10: In the second step the vector elements represented as fixedpoint numbers are mapped to the reduced representation: Eq. 11 and 12 which may be regarded as a projection expressed by Eq. 13 and 14.
Generated TF-IDF coefficients are in IEEE-754 double floating-point format and their values span between 0 and 1. Therefore to map these values to desired fixed precision is enough to multiply them by the maximal value possible to encode with that precision.
Back normalization to floating-point format is performed accordingly, only the value needs to be divided by maximal value.
1) max_value = 2 bitwidth − 1 2) f or norm_value in results : The reduction parameter r strongly affects performance results since it directly decides about a number of bits which are left for the vector elements representation. It is worth noting that it is possible to employ global dimensionality reduction techniques such as SVD along with the methods proposed in this paper. In this work, we consider the order of these operations (precision reduction before or after SVD) for the sake of the best final results.

IV. SINGULAR VALUE DECOMPOSITION
Singular value decomposition (SVD) is used frequently with the term-document matrix representation. SVD allows for dimensionality reduction of the sparse data to a low-rank dense matrix. It also addresses the problem of polysemy in the context of text documents, since words that share meaning are mapped to vectors occupying narrow region in the reduced vector space.
SVD is explained with the following formula: where M is the sparse term-document matrix, m is the number of terms, n is the number of documents, r is min(m, n). In such case U and V are orthogonal matrices and Σ is a diagonal matrix.
Lowering rank to k is done by taking k of the largest values (components) along the diagonal of Σ and truncating U and V.
This approach is named as Latent Semantic Analysis (LSA) or Latent Semantic Indexing (LSI) [23]. A simple interpretation of LSI is that SVD combines terms into more general concepts (synonyms or topics) and documents are represented by a weighted set of the topics.

V. CLASSIFICATION
In order to evaluate the influence of the precision reduction on the robustness of VSM model we employed them in the problem of multi-class (single-lable) text classification. We have chosen k-nearest neighbors algorithm (KNN), linear regression (LR) and support vector machines (SVM) as the tested classifiers.
KNN was used with cosine similarity metric and the number of neighbors k ∈ {1, 5}. The algorithm does not require training, but the testing phase involves calculating similarity with every document. It also needs to store all the documents from the training corpus. As such it is not well suited for large corpora, which are much more popular in the recent years.
LR and SVM are similar algorithms. In LR we applied L2 regularization. SVM was trained with hinge loss and linear kernel. Both execute iterative training and do not store documents for testing.
For macro-averaged objective the weights associated with classes were adjusted inversely proportional to class frequencies in the input data where w c is a weight associated with class c and n i is a number of samples in class i.

A. Experimental Setup
4 modules were developed in order to execute experiments: 1) TF-IDF: Term frequency-inverse document frequency was calculated on training data without setting any limit on the number of words.

2) Precision Reduction (b): Precision reduction was performed on VSM representation of documents as described in III, where b is the precision in bits.
3) SVD (k): Singular value decomposition was used to reduce the dimensionality of data, where k is the number of components. All results were obtained by taking an average of 5-fold cross-validation scores. Each datasets was randomly shuffled, partitioned into 5 subsets. The process of evaluation was repeated 5 times, with one subset used exactly once as testing data and the rest 4 as training data.
All experiments were performed in Python using scikitlearn [24] library with default parameters. Calculations were performed on 64-bit floating point type with 4 cores of Intel Xeon E5-2680v3.
Framework performing precision reduction is available at: https://github.com/kwrobel-nlp/precision-reduction. It determines what is the best number of bits for classification of specified corpus. Datasets used in this work are shared for reproducibility of results.
All of them are pre-processed by [25]: • all letters turned to lowercase, • one and two letters long words removed, • stopwords removed, • all words stemmed.
Multi-label datasets were transformed to single-label by removing samples with more than one class.

C. Quality Measure
The macro-averaged F1 score is used as a quality evaluation of the experiments' results presented in this paper. The precision and recall for corresponding classes are calculated as follows: where tp i is the number of items of class i that were classified as members of class i, f p i is the number of items of class other than i that were wrongly classified as members of class i and f n i is the number of items of class i wrongly classified as members of class other than i. The class' F1 score is given by the following formula: The overall quality of the classification can be obtained by taking the unweighted average F1 scores for each class. It is given by the equation: where c is the number of all classes. The F1 score value ranges from 0 to 1, with a higher value indicating a higher classification quality.
The error is defined as: The error reduction is defined as: where Error ref is a reference value of error and Error new is the new value of error.
To compare the results with other studies, micro-averaged accuracy is used. Micro-averaging does not take imbalance of classes into account.
where n is a number of all training samples.

D. Results
Error values on the corpora for each classifier in function of precision bits are shown in Fig. 2. For every dataset logistic regression and SVM obtain smaller error than KNNs. LR and SVM are more powerful because they model inputs (i.e. terms) in relation to classes. Precision reduction with KNNs improves results on webkb, r8 and 20ng datasets. KNN 5 scores higher than KNN 1 on webkb and cade. Fig. 3 shows averaged error reduction among the corpora for the classifiers. For SVM the precision reduction is the least beneficial. For other classifiers macro-averaged errors decrease with the reduction of precision down to 3 bits. However, micro-averaged errors are the smallest for the precision of 1-3 bits. Four times reduction of precision from 64 bits to 16 bits does not change the classification results. Fig. 4 shows averaged error reduction measure among the corpora for the classifiers with a precision reduction after SVD. The results indicate that introducing the precision reduction after SVD generates more errors in every case. Fig. 5 presents F1 measure for 3 variants: TF-IDF, TF-IDF with the best precision reduction and TF-IDF with the best SVD. Precision reduction gives better or similar results as applying SVD except for KNNs on r8. k-nearest neighbors algorithm with precision reduction gives similar results as raw logistic regression on r8, r52, and 20ng datasets. In the raw form SVM has the best results for the English datasets. Fig. 6 presents comparison of F1 score on variant TF-IDF with SVD with and without precision reduction before SVD. Precision reduction before SVD has always positive impact, especially seen on webkb dataset.  Table III shows overall macro-averaged F1 scores for every classifier on each corpus. The best results are obtained by logistic regression and SVM. Classification of cade is the most difficult task, the best classifier has only 55% of F1 measure. Table IV shows overall micro-averaged accuracy for every classifier on each corpus compared with the results of SVM from [25] and SVM with random search from [26]. Our SVM with precision reduction is superior on 4 datasets: webkb, r52, 20ng and cade. Table V presents execution time of training and testing. SVD is the most time-consuming phase in training in comparison to classification. However, it can reduce time of testing. Time of testing using KNNs is higher than other classifiers, because it is proportional to number of documents. Time of precision reduction is negligible.

VII. CONCLUSIONS AND FUTURE WORK
The conducted experiments show that it is beneficial to the perform precision reduction on the term-document representations. However, it is unclear what number of bits gives the best results for the specific corpus. For some corpora, a precision reduction to 1 bit is possible without loss of accuracy. On the other hand it is safe to reduce the number of bits from 64 to 4, which usually improves the quality of the obtained results and never leads to their degradation. As such, precision reduction seems the be very promising result, especially combined with FPGA implementation, which should lead to significant computation speed-up and memory footprint reduction.
The precision reduction is also a good alternative to di- mensionality reduction by SVD. It can lead to better accuracy and does not required time-consuming matrix manipulation. This feature is specially important for scenarios with very large vocabularies and document data sets. If SVD is still considered, the precision reduction should be applied before SVD, not in opposite order.
It should be also observed that focusing on micro-averaged objective allows for stronger reduction than in macro-averaged measures.
Nowadays neural networks are one of the most popular machine learning tools used to solve NLP problems. Our further research will be focused on testing precision reduction on distributional representations, which are typically used as inputs to neural networks. It is not uncommon that neural networks have millions of parameters -the reduction of precision of the vector weights is an interesting direction of research, which will be pursued in our future work.