{'fraction_non_alphanumeric': 0.029567588624853914, 'fraction_numerical': 0.007206856252434749, 'mean_word_length': 4.885144429160936, 'pattern_counts': {'":': 0, '<': 1, '<?xml version=': 0, '>': 0, 'https://': 0, '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}}
Network analysis of named entity co-occurrences in written texts

The use of methods borrowed from statistics and physics to analyze written texts has allowed the discovery of unprecedent patterns of human behavior and cognition by establishing links between models features and language structure. While current models have been useful to unveil patterns via analysis of syntactical and semantical networks, only a few works have probed the relevance of investigating the structure arising from the relationship between relevant entities such as characters, locations and organizations. In this study, we represent entities appearing in the same context as a co-occurrence network, where links are established according to a null model based on random, shuffled texts. Computational simulations performed in novels revealed that the proposed model displays interesting topological features, such as the small world feature, characterized by high values of clustering coefficient. The effectiveness of our model was verified in a practical pattern recognition task in real networks. When compared with traditional word adjacency networks, our model displayed optimized results in identifying unknown references in texts. Because the proposed representation plays a complementary role in characterizing unstructured documents via topological analysis of named entities, we believe that it could be useful to improve the characterization of written texts (and related systems), specially if combined with traditional approaches based on statistical and deeper paradigms.

Introduction. -The study of complex networks emerged in the beginning of the last decade as a powerful, robust and general representation of a myriad of real complex systems [1]. Biological systems, transportation networks, communication and information networks are examples of real systems whose underlying properties were unsnarled via graph representation. The investigation of many complex systems in terms of their topological structure and dynamical behavior allowed the discovery of non-trivial connectivity/functional patterns, including the discovery of specific mesoscopic, heterogeneous and hierarchical structures responsible for particular functions [1].
Even though several complex systems modeled as networks are artlessly visualized as a graph representation (e.g. street [2] or citation networks [3,4]), many others undergo a pre-processing step to allow a proper networked representation. This is the case of instances represented in an attribute space [5], images modelled as networks [6] and texts represented as graphs [7]. Of particular interest to the aims of this study are the text networks, a model that has drawn the attention of physicists in recent years and has been of paramount relevance to shed light on the structure and function of linguistic and cognitive processes [8].
In addition, such textual representations has allowed the investigation of basic human behavior through the automatic analysis of the ever increasing amount of electronic data in social and information networks [9].
Many physical models of texts have been proposed to tackle a diversity of problems [9]. The representation of unstructured documents depends on the specific language properties being studied. If writing style or language identification is relevant, syntactical networks are used to grasp stylistic-dependent features [10]. In syntactical networks, each word is mapped into a node and edges are established according to syntactical relations, which are language-dependent constraints. Interestingly, it has been shown that such networks share the same topological properties of networks representing completely different systems [10], allowing thus the construction of optimized structures for language acquisition and communication [11].
Usually, syntactical networks are analyzed using a simplified representation, the so-called word adjacency model [5,[12][13][14]. In this model, adjacent words are linked if they appear as neighbors in the text. It has been shown that, despite this seemingly naive simplification, word adp-1 arXiv:1509.05281v2 [cs.CL] 26 Jun 2016 jacency networks are efficient representations for text analysis because most of the syntactical connections occur between neighboring words [10]. The usefulness of such models has been verified in many theoretical and practical research [9]. Finally, another important class of text networks are the semantical networks, where links are established if concepts share some semantical property (e.g. a semantical similarity or a entailment relationship) [15].
Whilst several available methods grasp the relationship between all words or the relationship between specific classes of words [16,17] as a co-occurrence graph (see Section S4 of the Supplementary Information (SI) 1 ), only a few studies have investigated the properties of entity cooccurrences as a complex network. Note that this is a relevant issue because the presence of specific words other than relevant entities in networked models may hinder the accurate recognition of novel patterns. In this sense, this study aims at creating a networked textual representation that analyzes the topology emerging from the relationship between specific words, namely the named entities, which are a class of particular concepts that has been useful to shed light on the understanding of several language properties [18]. Particularly, we consider that words represent named entities whenever they name people (characters), places or organizations. Hence, unlike traditional textual networked models, the proposed representation emphasizes the complexity of the document plot rather than linguistic styles.
The application of the proposed network model that links entities co-occurring in the same context allowed the identification of some interesting topological patterns. Qualitatively, we have found that named entity networks share topological features of other complex systems, as revealed by low values of typical shortest path length and high local clustering. In addition, we have found that the networks display a modular structure. The potential of the proposed representation was verified in a typical pattern recognition problem devoted to the resolution of coreferences. Optimized results were found with our model, which confirms that the information provided by the representation goes beyond simple word frequency statistics. Because named entity networks are a complementary representation of texts as networks, we believe that it could be useful to improve the characterization of written texts and related systems with nodes playing special roles.
Extracting networks from books. -The objective of this paper is to propose a simple but relevant model that captures co-occurrences of named entities in texts. To identify pertinent entities, we used the technique referred to as "named entity recognition", which identifies relevant persons, locations and organizations in documents. Specifically, we used the method devised in [19], which tags words with three possible labels. An example of entities recognition is shown in the following extract obtained 1 The Supplementary Information (SI) is available from this link. from a modified Wikipedia article 2 . Note that the entities recovered from the method are highlighted in italic font: "Barack Hussein Obama II (US, born August 4, 1961) is the 44th and current President of the US, and the first African American to hold the office. Born in Honolulu, Hawaii, Obama is a graduate of Columbia University and Harvard Law School, where he served as president of the Harvard Law Review. He was a community organizer in Chicago before earning his law degree. He worked as a civil rights attorney and taught constitutional law at University of Chicago Law School from 1992 to 2004. He served three terms representing the 13th District in the Illinois Senate from 1997 to 2004, running in 2000 unsuccessfully for the United States House of Representatives." In the above example, the recognized entities denote persons (e.g. Obama), locations (e.g. Chicago and Hawaii ) and organizations (e.g. Harvard Law School or Columbia University). After the entity recognition step, the text undergoes a pre-processing step to eliminate ambiguities and name duplications. In this step, for example, Emma Wodehouse and Emma are mapped into the same entity. After this pre-processing phase, a set V = {v 1 , v 2 , . . .} of entities is obtained for each book. Note that, in this phase (training phase), only the known entities (such as Obama and Chicago are represented as nodes. Unknown entities (such as He) are included in a classification phase, for example, in the anaphora resolution problem (see "Results and discussion" section). To create the network of related entities, hereafter referred to as named entity (NE) network, the proposed method connects entities appearing in the same context. Thus, entities sharing some semantical relationship tend to be connected. The motivation of this approach relies on the fact that concepts appearing in the same context tend to be semantically related [20]. The separation of the text in contexts is accomplished by splitting the entire document in shorter subtexts comprising the same number of tokens W . As a consequence, each book is represented by the set Ψ = {S 1 , S 2 , . . . , S N }, where S i is the i-th subtext. Note that, we could have chosen as a representative context the segments of texts structured as chapters or other natural textual structure. Specifically, we have not used this information concerning the structure of texts because this information is not readily available in all books of the dataset. To store the information concerning the co-occurrence of distinct entities in the same subset, the matrix B is created. If entity v i appears in the j-th subset, then B ij = 1, otherwise B ij = 0. The frequency of entities in subsets, i.e. the number of subtexts in which a entity appears is defined as f i = j B ij . Analogously, the frequency of co-occurrence of two entities v i and v j is defined as The link between two entities is established if they cooccur at least in one set S i ∈ Ψ. The weight (i.e. the strength) of the link is computed as where P (v i |v j ) = f ij /f j . Here, the weight w ij defined in equation 2 is used to identify the strongest links, which are in turn stored in the adjacency matrix A. An example of network construction for a fictitious dataset is shown in Fig. S3 of the SI.
To improve the characterization of NE networks, we also considered the significance of entities co-occurrence. More specifically, two entities v i and v j were connected only if the quantity f ij was sufficiently higher than the same value expected in a null model, i.e. in a random (shuffled) text. Given two entities v i and v j , the significance of the cooccurrence is estimated by computing how likely it is to observe more than k = f ij co-occurrences of v i and v j in the null model. Equivalently, the p-value associated to the quantity k = f ij is p = k≥r p(k), where p(k) is the probability of k co-occurrences of v i and v j in the random text. To compute p(k), we followed the approach devised in [21]. If n 1 = f i and n 2 = f j , p(k) can be computed as where (x; y 1 , . . . , y 2 ) is a simplified notation: Equation 3 can be rewritten in a more convenient way, if the notation {a} b , defined as is adopted for a ≥ b. In this case, the likelihood p(k) can be written as .
Therefore, the p-value associated to the number of observed co-occurrences is [21] p(k) = k≥r n2−k−1 .
Note that the value p(k) defined in the above equation can be used to establish links between entities whose cooccurrence frequency is significant.
Results and discussion. -In this section, the topological properties of NE networks are investigated. In addition, we apply the proposed networked representation to tackle a natural language processing task related to anaphora (or co-reference) resolution. The dataset used in the experiments is shown in Table S2 of the SI. The list comprises romances by distinct authors. All books were retrieved from the Project Gutenberg dataset 3 .
Statistical properties of named entities networks. To probe the topological properties of NE networks, the following quantities were computed: the number of nodes (N ), the average degree ( k ), the clustering coefficient ( C ) and the average shortest path length ( l ). In order to compare the properties of NE and random networks, the values of clustering coefficient and average shortest path length in equivalent random networks were also computed as: The results obtained for selected books of our dataset are shown in Table 1. The results for the full dataset are shown in Table S3 of the SI. Note that, differently from traditional language networks where the number of nodes is proportional to the vocabulary size [9,10,22,23], in this case, the total number of nodes (i.e. the number of entities) is much lower. From a qualitative point of view, NE and small-world networks share similar topological properties, because in most cases C C r and l l r . Even though the Zipf's law may play a role in the observed small-world effect, the equivalence between these two effects is not straightforward because, in the proposed model, we consider segments of texts, where a quantity of K entity occurrences does not imply the formation of K edges. In addition, note that many entity occurrences tend not to be translated into an edge because of the burstiness effect, which is specially prominent in words denoting named entities [24]. An example of NE network is shown in Fig. S5 of the SI. As expected, central characters play a prominent role on the networked model. Another important feature of NE networks is their modular structure. In Fig. 1, we show the modular structure unfolded with traditional community structure methods [25] (see also Fig.  S4 of the SI). This modular structure has been noted in most of the studied networks.
In order to show how the network representation might provide complementary information for text analysis, we studied the problem of identifying the most central entities. As an example, we used the book Middlemarch, by George Eliot. The following network centrality measurements were computed: betweenness centrality, PageRank Table 1: Statistical properties of NE networks. In most of the networks, the clustering coefficient is higher than the same quantity observed in equivalent random networks. With regard to the average shortest path lengths, the values observed in real and equivalent random networks are similar. Concerning the differences across books, we have identified that most fluctuations arise from the difference in network size (result not shown). However, in specific cases (such as the value of k in MAN and PER), the statistical differences are significative, as a consequence of distinct authors' styles. Such differences could be explored in further studies aiming at identifying authorship in texts. and accessibility. The betweenness is a global measurement that computes the number of shortest paths passing through nodes. The PageRank is a global centrality measurement that considers that a node is relevant whenever it is connected to other relevant nodes. Finally, the accessibility is a local measurement which can be understood as an extension of the degree connectivity as it quantifies the effective number of neighbors at a distance h from the reference node [26]. Mathematically, the accessibility (α) is defined as

Book
where p (h) ij is the probability of a random walker to go from node i to node j in h steps. All three network centrality indices were compared with the raw frequency of appearance of the respective entities in the books. In Table 2, we show in decreasing order the 10 most relevant entities obtained with the frequency and the accessibility measurement. The most relevant entities obtained with the betweenness and PageRank are shown in Table S5 of the SI. As for the betweenness centrality, the six most relevant entities are the same as the ones obtained with the simple frequency. However, the entities appearing between seventh and tenth positions are low frequency entities that, nonetheless, are located in privileged network position. A similar behavior can be observed for the PageRank index: top relevant entities are also very frequent, even though some low frequency entities are important because they are a few hops away from the most relevant nodes. The most relevant entities captured by the accessibility index (computed for h = 2) turned out to be less influenced by the frequency. Note, for example, that Farebrother is the character with the highest effective number of neighbors at the second level, even though it is only the tenth most frequent entity in the book. In fact, a correlation analysis of less frequent entities showed that the relevance of entities according to topological indices may not be predicted by frequency alone (result not shown). By no means we are suggesting that network measurements are more relevant than traditional frequency indices. We rather suggest that network measurements could be included as an additional feature to analyze e.g. the complexity of book plots and literary movements [27][28][29][30].
Identifying patterns in NE networks: application to anaphora resolution. To show how the proposed network representation might be useful in a real application, we addressed the anaphora (or co-reference) resolution problem [32] (see a brief description of traditional methods in Section S4 of the SI). In this task, we aim at identifying the entity related to an undefined reference in the text. To illustrate the problem, consider the following example: "The ordinance was published by Ricardo and Borsari, who are responsible for the management of water resources in the state. In the document, he points out the critical situation of water in the region." Note that, in this case, the objective of a system aiming at anaphora resolution is to relate "who" and "he" to either "Ricardo" or "Borsari ".
The following methodology was applied to tackle the anaphora resolution problem. Differently from the training phase (see Section "Extracting networks from books"), in this phase (classification phase), each unknown entity (e.g. "who" or "he" in the previous example) was modelled as a different node in the network. As such, the Nicholas Bulstrode 9 James Chettam Fred Vincy 10 Candem Farebrother Laure network comprises nodes belonging to the set of unknown (E ? ) and known (E ! ) entities. In other words, the final networks in this task contain vertices of different linguistic provenance, i.e. while some vertices represent known named entities; others model unknown references. We measured all possible pairwise similarities between entities v i ∈ E ? and v j ∈ E ! . Therefore, unknown references were characterized by their similarity to the others entities in the book. In the baseline approach based on simple cooccurrence statistics (COO), which does not consider the global topology of networks, each v i ∈ E ? is considered to be similar only to those entities v j ∈ E ! that appeared in the same text window. Mathematically, the similarity f ij between v i ∈ E ? and v j ∈ E s in the baseline approach is computed as defined in equation 1.
The co-occurrence approach is based on the premise that the references to unknown entities tend to occur in the same context, thus surrounding characters, locations and organizations tend to be the same. However, the cooccurrence approach only takes into account local information to measure the similarity between entities, which may lead to a large loss of relevant information. A more informed approach can consider the full network topology to quantify the pairwise similarities and thus improve the characterization of the context around a entity. Here, we used the Katz similarity [1], which is defined as: where I is the identity matrix and α is a positive constant. If λ 1 is the leading eigenvalue of A, α must satisfy α < λ −1 1 if equation 9 is to converge [1]. We also considered a variation of the Katz similarity (κ) that does not consider the bias toward highly connected nodes. Mathematically, the similarityκ between two nodes v i ∈ E ? and v j ∈ E ! is given by: where δ ij accounts for the self-similarity term and is defined as δ ij = 1, if v i = v j ; and δ ij = 0, otherwise. In matrix terms,κ is written as where D is the diagonal matrix with elements D ij = f i , if v i = v j ; and D ij = 0; otherwise. Note that both measurements κ andκ make use of the full network structure to compute pairwise similarities. This is evident when one interprets the quantity A m as the matrix storing the number of paths of length m between two nodes [1]. An example of identification of unknown entities in a toy network is discussed in Section S3 of the SI. In our real dataset, we addressed the anaphora resolution task where two possible entities are candidates in a unsolved reference. This problem can be modelled as a supervised classification task [31] with two possible classes (see definitions in Section S1 of the SI). The pairs of evaluated entities are shown in the second column of Table 3. The best average accuracy rates obtained in our selected dataset are shown in Table 3. For each pair of entities, we show the performance obtained with the traditional method based on co-occurrence statistics (COO, see equation 1) and with methods making use of network similarity measures, as defined in equation 9 (Katz similarity). The results obtained with the normalized Katz similarity (see equation 11) were no better than the ones obtained with the non-normalized version, as shown in Table S4 of the SI. Note that the use of global network information was able to improve the characterization of unsolved references, as revealed by higher accuracy indexes obtained with nonlocal network measurements when compared to the traditional method based on simple co-occurrence statistics. This means that the co-occurrence with specific entities might be useful to discriminate unknown entities whenever the test instance tend to appear in a community dominated by a specific entity. In fact, a systematic error analysis performed in our dataset revealed that most of the errors occur when distinct entities in the training dataset appear in the same community. Another recurrent error occurs when the test instance appears between two communities dominated by distinct entities (see Section S5 of the SI). This result confirms the importance of the patterns unveiled by the proposed networked representation, which were hidden from traditional models.
A systematic comparison with other traditional anaphora resolution methods not relying on any network information was also performed, and the results are provided in Table S6 of the SI. In general, our networked approach performed better than other statistical approaches. In light of the results obtained with NE networks drawing on the Katz measurement to quantify similarity between unknown references, we advocate that topological information could be used to complement more informed approaches based on deep language analysis.
Conclusion. -In this study, we have introduced a model to form named entities networks, i.e. networks whose nodes denote people, locations and organizations. Unlike current networked representations of written texts, our model focused on the complexity arising from nontrivial co-occurrences between entities alone. In other words, we disregarded linguistic/stylist influences of the language on the construction of the networks. From this point of view, NE networks can be understood as a complementary form of text representation. A topological analysis performed on novels revealed that NE networks display high-clustering and low typical shortest path lengths, a similar behavior found in other textual and non-textual networks. Another interesting finding arising from the topological analysis of our model is that NE networks can unveil patterns that cannot be unveiled with traditional methods based on simple word count statistics. This was clear in the application of NE networks for identifying unknown references in texts. Particularly, the characterization textual relying upon NE networks outperformed the traditional representation based on statistical co-occurrence analysis. We believe that the performance of applications using NE networks could be improved with further development of enhanced automatic entity recognizers, which could treat referential opacities [33] and entities with multiple aliases (e.g. "morning star" and "evening star") [34].
NE networks turned out to play a complementary role in the characterization of written texts. While traditional approaches neglect the rich information underlying networked representations, our model is able to capture this type of information concerning the interactions between relevant entities. Given the variety of current applications and representations making use of networks in texts [9], we believe that the use of NE networks might be useful to recover language-independent patterns. From a practical point of view, the model could also lead to improved performances for recognizing styles, authorship, quality and plagiarisms in a higher level of abstraction. * * * This work was supported by FAPESP (grant no. 14/20830-0). I thank Vanessa Queiroz Marinho and Filipi Nascimento Silva for a careful reading of the manuscript.