{'fraction_non_alphanumeric': 0.0262982689747004, 'fraction_numerical': 0.00456534144949591, 'mean_word_length': 4.681977843825993, 'pattern_counts': {'":': 0, '<': 1, '<?xml version=': 0, '>': 1, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 1, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
CompText: Visualizing, Comparing&Understanding Text Corpus

A common practice in Natural Language Processing (NLP) is to visualize the text corpus without reading through the entire literature, still grasping the central idea and key points described. For a long time, researchers focused on extracting topics from the text and visualizing them based on their relative significance in the corpus. However, recently, researchers started coming up with more complex systems that not only expose the topics of the corpus but also word closely related to the topic to give users a holistic view. These detailed visualizations spawned research on comparing text corpora based on their visualization. Topics are often compared to idealize the difference between corpora. However, to capture greater semantics from different corpora, researchers have started to compare texts based on the sentiment of the topics related to the text. Comparing the words carrying the most weightage, we can get an idea about the important topics for corpus. There are multiple existing texts comparing methods present that compare topics rather than sentiments but we feel that focusing on sentiment-carrying words would better compare the two corpora. Since only sentiments can explain the real feeling of the text and not just the topic, topics without sentiments are just nouns. We aim to differentiate the corpus with a focus on sentiment, as opposed to comparing all the words appearing in the two corpora. The rationale behind this is, that the two corpora do not many have identical words for side-by-side comparison, so comparing the sentiment words gives us an idea of how the corpora are appealing to the emotions of the reader. We can argue that the entropy or the unexpectedness and divergence of topics should also be of importance and help us to identify key pivot points and the importance of certain topics in the corpus alongside relative sentiment.


I. Introduction
A common practice in Natural Language Processing (NLP) is to visualize the text corpus without reading through the entire literature, still grasping the central idea and key points described. For a long time, researchers focused on extracting topics from the text and visualizing them based on their relative significance in the corpus. However, recently, researchers started coming up with more complex systems that not only expose the topics of the corpus but also words closely related to the topic to give users a holistic view. These detailed visualizations spawned research on comparing text corpora based on their visualization. Topics are often compared to idealize the difference between corpora. However, to capture greater semantics from different corpora, researchers have started to compare texts based on the sentiment of the topics related to the text. This gives users an idea about the weightage of a particular topic in a corpus. Comparing the words carrying the most weightage, we can get an idea about the important topics for corpus.
There are multiple existing texts comparing methods present that compare topics rather than sentiments but we feel that focusing on sentiment carrying words would better compare the two corpora. Since only sentiments can explain the real feeling of the text and not just the topic, topics without sentiments are just nouns. We aim to differentiate the corpus with a focus on sentiment, as opposed to comparing all the words appearing in the two corpora. The rationale behind this is, that the two corpora do not many have identical words for side-by-side comparison, so comparing the sentiment words gives us an idea of how the corpora are appealing to the emotions of the reader. We can argue that the entropy or the unexpectedness and divergence of topics should also be of importance and help us to identify key pivot points and the importance of certain topics in the corpus alongside relative sentiment.
For the proof of concept, we theorized that the Presidential speech dataset [1] would be a good fit since politicians appeal to the public emotions, hence we expect to see dramatic contrast between the two opposing ideologies.
Our contributions are: 1) We present a pipeline, CompText, for systematic analysis of two text corpora, with a focus on sentiments.
2) We implement our proof of concept on the Presidential speech dataset 3) We provide multiple case studies and use cases of our approach A lot of work has been presented on comparing text corpora, our novelty is in the fact that we analyze the document based on sentiment. We also prove the superiority of our results compared to the present methods in the case studies section. We believe that our work can be used in various fields like understanding how the media of different countries present the same news, can be used by brands for their competitive research & marketing, analyzing call center data to improve efficiency.

II. Related Work
The sequential link between words is extremely important in the research of text sentiment analysis. Mikolov et al. [2] introduced the RNN language model, which is widely acknowledged as being capable of processing text sequence data. However, in reality, RNN was unable to properly learn the knowledge. When the gap between relative text information and the current location to be predicted widens, various issues emerge. The backpropagation through time optimization technique (BPTT) has too many unfold layers, which causes historical information loss and gradient attenuation during training. To address this issue, several researchers proposed the LSTM method [3], which improves experimental outcomes in particular application settings. When the text sequence information is fairly lengthy, the RNN model with LSTM is often more successful in overcoming the sequence information attenuation problem. So, for text sentiment analysis, we'd use an RNN with LSTM. In a document, N-grams are repeated sequences of words, symbols, or tokens. They are the adjacent sequences of things in a document, in technical terminology. They are used in NLP activities when dealing with text data.
To emphasize discriminating words, a variety of visualizations have been employed, including basic ranked lists of words, word clouds, word bubbles, and word-based scatter plots. There are a variety of methods for generating word scores for ranking that has been comprehensively discussed in prior work. For an overview of model-based term scoring methods, the reader might consult Monroe et al. [4]. Bitvai and Cohn [5] provide a method for identifying sparse words and phrase scores using a trained ANN (with bag-of-words features) and its training data. Coppersmith and Kelly [6] propose a word-cloud-based visualization for discriminating words, although it is intended for tiny subsets of a much larger corpus. A third, middle cloud is included for phrases that appear to be distinctive. Bostock et al. [7] use interactive word-bubble visualization to compare Republican and Democratic words used throughout the 2012 US presidential nominating conventions.

A. Theoretical Concepts
The technical description of the project is given according to the different views that we present for the comparison of the different corpus. First we define metrics that we use to compare the text. 1) Entropy: Entropy accounts for both a keyword's relative frequency and its unexpectedness. If we let denote the entire normalized distribution of words in a text with vocabulary T , then the (Shannon) entropy [8] is given by the equation 1.
2) Divergence: Divergence is an asymmetric measure of how texts differ from each other. If we want to compare a reference text and a comparison text, where let (1) be the relative word frequency distribution of the reference text and (2) be the distribution of the comparison, then the Kullback-Leibler divergence (KLD), or relative entropy, is given by the equation 2.
Next, the different views for text comparison are described as follows: 1) Word Cloud (Force Directed Graph): With this type of graph we aim to find the top most frequent sentiment carrying words in a corpus and link all the common words between different corporas. In this graph the node represents the different corpus and the edges represent the link between them. The user will be able to see the top most important labeled sentiment carrying words in the corpus and also the common words used by different corporas. 2) Word Shift Graphs: 1) Frequency comparison word shift graph: We take the most important words for every corpora and find 30 common words to plot their relative frequencies on the word shift graphs. If (1) is the relative frequency of word in the first text, and (2) is its relative frequency in the second text, then the proportion shift calculates their difference using = (2) − (2) . If the difference is positive ( >0), then the word is relatively more common in the second text. If it is negative ( <0), then it is relatively more common in the first text. There is also a subplot of the cumulative contribution on the bottom left, which traces how | | changes as we add more words according to their rank. The horizontal line shows the cutoff of the word contributions that are plotted versus those that are not. This helps show how much of the overall difference between the texts is explained by the top contributing words.
2) Entropy comparison word shift graph: We use the Shannon entropy, H ( ), of words to identify more surprising words and how they vary between two texts. The less often a word appears in a text, the more surprising it is. The Shannon entropy can be understood as the average surprise of a text. We can compare two texts by taking the difference between their entropies, H = H ( 2 ) − H ( 1 ). We plot the top 30 common words with the most Shannon entropy. We also note that the absolute Shanon entropy does not mean anything, it's only the relative Shannon entropy that defines the rarity of a word. The top bar pf the graph shows the cumulative sum of H and tells us which of the two texts are more unpredictable.
3) Divergence comparison word shift graph: The Kullback-Leibler Divergence (KLD) is a useful asymmetric measure of how two corpora/texts differ. We have a reference text and a comparison text. The KL divergence of the comparison text with respect to the reference text helps us identify the relative entropy of a word from the comparison text with respect to the reference text. We again take the common words and calculate their divergence score, plotting the word-shift graph.
To summarize, we compare the texts focusing on the sentiment. Through the word cloud graph, the user can view the top most labeled sentiment carrying words, for the corpus between different text corpus. This graph also shows the common link in the texts by linking the most important words. Further for in-depth evaluation, we draw the word shift graphs to analyze common, most important sentiment words based on the frequency, entropy, and divergence of two text corpora. There has been ample research on Aspect Based sentiment analysis. In the recent time, BERT based sentiment analysis have been topping the accuracy charts. We follow Sun et. al. [9] and further train their Deep Learning model on [10] to suit our needs. Similarly, there are ample methods to draw the word cloud graph. The field of word shift graphs is quite nascent. There have been a lot of explorations on what word shift graphs can represent. We follow the Gallagher et. al [11] to build the word shift graphs. We organize these two analysis methods into a novel architecture. We hypothesise that comparison on the sentiment carrying words should be able to provide the user with a detailed and meaningful difference between two corpus. The system architecture design for our project is given in the Figure 1.

Dataset
We describe 2 datasets in our project, one being the SemEval 2014 [10] Restaurant reviews dataset for training the sentiment analysis method. This dataset has the reviews with the sentiment carrying words and their sentiment. For the second dataset [1], we collected the speeches in the Inauguration and State of the Union address and appended all of them, one after the other for each president. We have the Inauguration and the State of the Union speeches for 43 presidents and the speeches are on average 20000 words long. This dataset is the primary testing dataset, although much more regressive testing has also been done. This data set contains the name of the Presidents, their speeches, and the source of their speeches.

ML Method Used
We use transfer learning to train our sentiment analysis method. The entire code is written in python. We use the Pytorch deep learning framework to build and train the model as well as handle the dataset. The BERT model itself is made using the NN submodule of PyTorch. We also use the JSON module to parse the dataset and Pandas to transform it. To review sentences from the dataset, we also employ some of the NLP modules like tokenizer, and NLTK.

Visual Interface
We used flask, a Python-based microframework to deploy our machine learning model and make our interactive web application, because of the features it provides. For generating the forced directed graphs we have used the D3.js library. This graph is shown in Figure 3. It shows the top most common labeled sentiment carrying words of different presidents and which presidents had spoken the same sentiment-carrying words. We have separated the speeches into overall negative and positive sentiment and visualized it using a timeline as shown in Figure 2 that shows the cumulative sentiments of all the presidential speeches

IV. Evaluation and Results
In this section, we provide detailed analysis/case studies on different text corpora through our pipeline. Since our focus is mainly on the sentiment carrying words, it is in our interest to present the analysis which are rich in sentiment. We present the improved analysis of presidential speeches and academic journal reviews.

Barack H. Obama v/s Donald J. Trump
Analysing the speeches of the presidents, the first task is to analyse all the words and record their sentiment. Through these sentiment carrying words, the user can look at the different analysis and get insights about the content

Fig. 4 Word Shift Graphs for Presidential Speeches
of the corpora. 1) Word Cloud (Force Directed Graph): Since the World Cloud graph can handle more than one corpus, it helps us to explore the connections of the different document (President speeches in this case). We can look at the words with the top aggregate sentiment in the speeches and also see the common words. In Figure 3, we can see the topmost frequent words used by the presidents in Inaugural or State of the Union speeches. From the graph we see that President Trump and President Obama used the word 'united states' in a negative context. We also saw that Lyndon B. Johnson had no common words with any of the presidents. Through this graph, we can decide what two corpora (speeches) to compare with the word shift graphs. We also have an auxiliary view 2, which helps us to get an overview of the sentiment of all the entire corpora. 2) Word Shift Graphs: 1) Frequency comparison word shift graph: As mentioned above, we take the most important words for every president and find 25 common words to plot their relative frequencies on the word shift graphs. In Figure 4a, the comparison of the speeches on Barack H. Obama (B.H.O in purple) and Donald J. Trump (D.J.T in yellow) is given. The first thing we notice is the corpus size, which is twice as big for President Obama as it is for President Trump, which is expected due to the tenure of both presidents. We also notice that in spite of the smaller corpora, President trump repeats the words more than President Obama, and hence his speech is less comparatively diverse. We can see that President Trump used the word 'Billions' more than President Obama, while President Obama used the word 'Education' more than President Trump. The cumulative contribution plot on the bottom left traces how | | changes as we add more 3) Divergence comparison word shift graph: In Figure 4c, we can see that the word 'Great' in President Trump's speeches is surprising with respect to the reference speeches of President Obama. Similarly, the word 'Health' in President Obama's speeches is surprising compared to the reference, President Trump's speeches.

ECS289H: Reading Assignment 10's Summary by Divjeet Singh Jas and Suvi Varshney
To test our model on academic reviews, we thought the best reviews to compare would be our own reviews. The word shift graphs are given in 5 1) Frequency comparison word shift graph: In Figure 5a, the comparison of the Reading assignments is given, Suvi Varshney (in purple) and Divjeet Singh Jas (in yellow). The first thing we notice is the small difference in the corpus size. We also notice that the top 50 sentiment-carrying words, ranked by frequency, have an equal number of words from both the assignments, indicating that both the assignments are equally diverse. We can see that while Divjeet's assignment has more positive sentiment words like 'improvement', 'groundbreaking', etc. Suvi's assignment has more negative sentiment words like 'disagreement', 'descent', etc. This indicates that Divjeet's assignment paints the Reading in a more positive light, while Suvi's assignment is more critical of it. Since the corpus size is small, we can also notice that most of the difference is explained by the top 50 words combined, evident by the cumulative contribution plot on the bottom left.
2) Entropy comparison word shift graph: In Figure 5b, we can see which words are relatively surprising in which assignment. The words 'costly', 'ambient' are much more surprising for Divjeet, while the words, 'Volume', 'Algorithms' are much more surprising in Suvi's speech. The top bar shows the cumulative sum of H and tells us that both the assignments are equally unpredictable.
3) Divergence comparison word shift graph: In Figure 5c, we can see that the word 'reduce' in Divjeet's assignment is surprising with respect to the reference assignment of Suvi. Similarly, the word 'information' in Suvi's assignment is surprising compared to the reference i.e Divjeet's assignment.
We also tested our pipeline on much more rigorously on other journal reviews and movie reviews, the results of which we have reserved for the presentation due to limited space.

B. Comparison with existing work
To highlight our contribution and the uniqueness of our pipeline, we present the result of word shift graphs on topics (not sentiment words) and try to see if they convey as much meaning. This comparison of speeches of Barack H. Obama (B.H.O in purple) and Donald J. Trump (D.J.T in yellow) is given.is given in Figure 6. As we can see in the frequency comparison word shift graph 6a, we have all kinds of words and not just sentiment words, they tell us with what frequency they appear, but do not convey anything about the sentiment or the intent of the corpus. Words such as 'people', 'make', 'white', 'much', 'kids' are not of much help to see the context. We can also see the cumulative contribution plot is not smooth, indicating that taking more words does not contribute equally in explaining the difference. Some words explain much more difference than others, which are probably sentiment-carrying words. The same trend is continued in the entropy and divergence word shift graphs in figure 6b and figure 6c

V. Discussion, Limitation and Future Work
This research is valuable for anyone who wants to analyze huge corpora in very little time. For example, a dataset containing critiques of an academic journal by different reviewers across the world. First, our model will generate a high-level view using the word cloud graph. This will provide the user with the topmost labeled sentiment-carrying words for every node. Along with the sentiment carrying common words among the different nodes. After this, the users can choose any 2 nodes they want to further analyze in-depth. This can be done by the word shift graphs generated by our model.
Since our current research is a proof of concept there is a need to further improve it and work on some of its limitations. Since we are calculating the sentiment of every word, our process takes a lot of time due to the huge corpus. This is a bottleneck in our current process. In the future, this can be solved by running the processes in parallel threads. Our current implementation is a proof of concept focusing on the presidential dataset. In the future, we can make this a more generalized approach for different datasets. Also currently, there is no support to add a dataset for evaluation in the world cloud graph. Our future implementation will evaluate the entire dataset and generate all the graphs.

VI. Documentation and Access
The code base for this project is available at GitHub at [12].