{'fraction_non_alphanumeric': 0.03886744765873151, 'fraction_numerical': 0.010075480719969944, 'mean_word_length': 4.638359329867129, 'pattern_counts': {'":': 0, '<': 0, '<?xml version=': 0, '>': 5, '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}}
Infinite Hierarchical MMSB Model for Nested Communities/Groups in Social Networks

Actors in realistic social networks play not one but a number of diverse roles depending on whom they interact with, and a large number of such role-specific interactions collectively determine social communities and their organizations. Methods for analyzing social networks should capture these multi-faceted role-specific interactions, and, more interestingly, discover the latent organization or hierarchy of social communities. We propose a hierarchical Mixed Membership Stochastic Blockmodel to model the generation of hierarchies in social communities, selective membership of actors to subsets of these communities, and the resultant networks due to within- and cross-community interactions. Furthermore, to automatically discover these latent structures from social networks, we develop a Gibbs sampling algorithm for our model. We conduct extensive validation of our model using synthetic networks, and demonstrate the utility of our model in real-world datasets such as predator-prey networks and citation networks.


Introduction
How do the social communities and their self-organization arise from coordinated interactions and information sharing among the actors? One way to tap into this question is to understand the latent roles and minds of actors which lead to the formation and organization of these communities. We are particularly interested in uncovering the functional/sociological underpinning of network actors, and their influence on the network modularity and hierarchy.
Existing methods for inferring actor roles [10,16,9] are limited in that they assume each actor undertakes a single, invariant role when interacting with other actors. This is in stark constrast with real social networks where actors can play multiple roles (or be under multiple cultural influences); the specific role being played depends on whom the actor is interacting with. The Mixed membership stochastic blockmodel (MMSB) [2] proposed recently captures the multi-faceted, context-specific nature of an actor's role.
However, the presence of hierarchical structures in real-world social networks raises a significant challenge to current network models. The MMSB formalism described above is intrinsically flat in its structure -all roles of an actor are equal citizens in terms of their relationships to each other -so it does not induce hierarchical structures among actors. A hierar-chical structure goes beyond simple clustering by explicitly including organization at all scales in a network simultaneously. Taking a corporate email network as example (Figure 1), suppose a finance department employee in the European branch is communicating with an American branch executive. The European employee might not communicate with a (possibly businessoriented) role related to her membership in the European finance department (which normally has no business with the American finance department), but simply with a more generic social role as a member of the European branch of the same company (which has occasional acquaintance with the American colleagues). However, when this same employee interacts with a European human resource employee, she would likely do so with her role as a European finance department member. This notion of interaction-specific, multi-community membership accounts for otherwise unusual edges -like the interaction between the European finance employee and the American executive -and motivates an intuitive yet powerful approach that allows one to infer and visualize the semantic underpinnings of every actor and every link between actors.  Figure 1: Illustration of a corporate email network/graph as a set of nested communities (Left), and the corresponding hierarchy of communities (Right). Vertices in the network represent employees, and directed edges represent emails sent on a particular day.
We propose a tree-structured hierarchical MMSB (hMMSB) to model communityhierarchies and the resultant social network as a function of the community memberships undertaken by actors during different interactions. Our method treats the community structure as a hierarchy of superand sub-communities, while accounting for the interaction-specific nature of community membership. Moreover, it automatically determines the appropriate number of sub-communities in each community. This sets our method apart from spectral clustering methods, which typically do not produce hierarchies, or agglomerative clustering methods, which are inherently restricted to binary hierarchies. We will use our model to analyze a biological food web and a physics paper citation network, and examine whether the recovered hierarchies agree with the known organizational structure of both networks. Extensive simulation-based validation of both our model's consistency and the Gibbs-sampling inference algorithm will be conducted to ensure our model's feasibility for hierarchical structure identification.

Related Work
While there has been a great deal of work on graph clustering and community structure inference [7,14,18,5,8], probabilistic generative models for hierarchical community formation and latent multirole inference of every actor and link have just started to draw attention.
As mentioned earlier, the MMSB model [2] enables inference of the latent roles of every actor and link in a network, but it cannot capture hierarchical structures of possible communities in the network. The link prediction model in [17] employs an Indian Buffet Process prior over actor positions in an infinite-dimensional latent feature space. In that respect, it may be thought of as a nonparametric extension of the MMSB. However, the goal of their model is missing link prediction rather than inference of latent organizational structure.
Recently, Roy et. al. have developed an "annotated hierarchies" model [19] that generalizes an infinite relational model [13] for hierarchical group discovery. Their subsequent work on Mondrian Processes [20] provides an alternative nonparametric take on the same issues. Both the annotated hierarchies model and the Mondrian Process relational model discover binary hierarchies. The infinite stochastic blockmodel [12] recovers organizational hierarchies of arbitrary branching factor, among other types of structure like grids or partitions, but it does not offer detailed semantic underpinnings, such as context-dependent role or community membership instantiations, of every network link.

Probabilistic Hierarchical Community Model
Under the MMSB [2], network links can be instantiated by a role-specific local interaction mechanism: the link between each pair of actors, say (i, j), is instantiated according to the latent role specifically undertaken by actor i when it is to interact with j, and that of j when it is to interact with i. Crucial to the goal of role-prediction for network data, is the so-called "role vector" θ of mixed membership coefficients, which succinctly captures the probabilities of an actor being involved in different roles when he/she interacts with another actor. In this paper, we leverage and generalize the "role vector" to model context-dependent mixed memberships in communities of different scales when links between actors are formed. We propose a hierarchical MMSB (hMMSB) model for nested community structures underlying social networks, thereupon such structures as well as the community implications of every link can be inferred, given the network. In the sequel, we begin with a baseline hMMSB that requires a user to pre-specify the granularity of a tree hierarchy of communities, that is, the branching degree from each group to its subgroup at the next level. We will then relax this constraint by employing a nested Chinese Restaurant Process, described in [3], to allow hierarchies of arbitrary granularities with a fixed depth.
. . , N } is the set of vertices/actors, and E is the set of edges/interactions. We adopt the convention E ij = 1 if (i, j) ∈ E else E ij = 0, and we ignore self-edges E ii . Because the graph is directed, E is not necessarily a symmetric matrix. Given an edge E ij , we refer to actor i as the donor and actor j as the receiver.
Under an hMMSB, we assume that a link E ij follows a generative process based on two latent variables unique to each actor. The first one is a community membership-path vector (or in short, path) c i , which records the community memberships of this actor at different levels of the community hierarchy in the network. Our model requires an integer parameter K, denoting the maximum depth to which the hierarchy should be learnt. Given K, we can represent an actor path c i as a vector of positive integers (c i1 , c i2 , . . . , c iK ), where c ik denotes the branch taken by the path at level k ≥ 1.
We adopt the convention that the hierarchy root sits at level 0. For clarity of explanation, we will assume for now that the actor paths c i are known. Later, we shall relax this assumption by placing a suitable nonparametric prior over c i , allowing them to be posteriorly inferred.
The second variable is a mixed membership vector (in short, MM) θ i , defining the probabilities of an actor identifying himself at different community levels when interacting with other actors. We place a two-parameter stick-breaking prior [3] over θ i , so that actors are not required to participate in the same number of community levels. Stick breaking constructions work as follows: Consider a stick of length 1. Draw V i1 ∼ Beta(mπ, (1 − m)π). Let θ i1 = V i1 and let 1 − θ i1 be the remainder of the stick after chopping off this length V i1 . To calculate the length θ i2 , draw V i2 ∼ Beta(mπ, (1−m)π) and chop off this fraction of the remainder of the stick, giving Thus V ik is the fraction to chop off from the stick's remainder, and θ ik is the length of the kth stick that was chopped off. In general, we draw V ik ∼ Beta(mπ, (1 − m)π) from k = 1 to k = ∞ and the corresponding {θ ik } ∞ k=1 is defined below: This process is known as the two-parameter GEM distribution [3] and draws from GEM (m, π) are denoted as θ i ∼ GEM(m, π). m > 0 influences the mean of θ i , and π > 0 influences its variance. Because the hierarchy is only learnt up to depth K, we truncate the GEM(m, π) distribution at level K. The stick breaking prior makes it more intuitive to bias interactions toward coarser or finer levels compared to a Dirichlet prior with either a single parameter (which is not expressive enough), or K − 1 parameters (which may be too expressive).
To instantiate the edge from actor i to j, we introduce interaction level indicators z i→j (donor level) and z i←j (receiver level), which follow multinomial distributions defined by the MM vectors θ i , θ j respectively. The pair (c i , z i→j ) specifies actor i's interaction-specific position in the community hierarchy, denoted by c i [z i→j ], which contributes to determining his interaction probability with actor j. Note that we are not proposing a full hierarchical model for a tree over conditionally iid entities, as in a coalescent process [11]. Our goal is to model finite-depth nested communities of entities connected by a network; therefore our latent hierarchy is not a full binary tree over all nodes, and our generative process does not output iid nodal attributes, but links between nodes. Now, given interaction level indicators z i→j and z i←j , and paths c i and c j of the two actors involved, we can determine the community identities (not necessarily at the same level) underlying an interaction. These community identities specify a community-pair-specific distribution for the link The notation B ci,cj ,zcoarse ∈ B denotes a parameter specifying the interaction probability from community c i [z coarse ] to c j [z coarse ]. We shall explain the intuition behind this in more detail below.
With all these details, we arrive at the following generative process of a network G = {V, E}: • For each actor i ∈ V : -Sample actor i's path ci from a distribution over hierarchies (detailed in the next section).
• To generate the network, for each directed edge Eij where i, j ∈ V , i = j: -Sample the donor level zi→j ∼ Multinomial(θi).
The overall intuition behind hMMSB is that c i and z i→j specify a hierarchy position for the donor, and likewise for the receiver; and we use these positions to determine the interaction probability. There are two different scenarios worth mentioning. First, suppose that the donor and receiver positions share the same immediate parent in the hierarchy. Our model associates a "compatibility matrix" with every parent position in the hierarchy, which gives the probability of interaction between any two of its child positions. The set of all compatibility matrices is denoted by B. Since the donor and receiver positions share the same parent, we simply look up the appropriate entry in B to get the interaction probability. In the second case, the donor and receiver positions do not share the same parent; this always happens when z i→j = z i←j (i.e. the positions are at different depths). We then coarsen both levels to their minimum, z coarse . The idea is that interactions between two hierarchy positions should take place at the level of the higher (coarser) position. For example, when an executive interacts with a sales representative, we reduce the interaction to one between an executive and a generic group of "other employees" below executive rank. (It is in theory possible to explicitly model all possible interactions between communities of arbitrary levels, but this will lead to a severe over-parameterization of our model. We have decided to postpone a more thorough study of this issue to later work.) If the new positions now share the same parent, then we look up the appropriate element of B as before. Otherwise, we define the interaction probability to be zero.

Infinite hMMSB
Thus far, we have assumed knowledge of the paths c i . From a combinatorial standpoint, inferring these paths is difficult. Because the number of children at each hierarchy position is unlimited, there are infinitely many possible hierarchies or sets of paths {c i }, even with the fixed depth K. One might consider using heuristic methods that guess at the number of such children, but doing so would defeat the purpose of employing a probabilistic model.
Our solution is to place an appropriate nonparametric Bayesian prior over c i , the Nested Chinese Restaurant Process [3], or nCRP for short. The nCRP is an extension of the regular Chinese Restaurant Process (CRP), a recursively-defined prior over positive integers. For concreteness, we shall use the first level of each actor path, c i1 , to define the CRP: x is the smallest positive integer not in {c 1:(i−1),1 } where γ > 0 is a "concentration" parameter that controls the probability of drawing new integers, and for conciseness we define c 1:(i−1),1 ≡ (c 11 , . . . , c (i−1)1 ). The nCRP is essentially a hierarchy of CRP priors, beginning with a single CRP prior at the top level. With each unique integer x seen at the top-level prior, we associate a child CRP prior with |{i | c i1 = x}| observations, resulting in a two-level tree of CRP priors. We can repeat this process ad infinitum on the newly-created child priors, resulting in an infinte-level tree of CRP priors, though we only use a K-level nCRP. All CRP priors in the nCRP share the same concentration parameter γ.
Now we can finish describing our generative process: for each actor i ∈ V , we can sample c i ∼ nCRP(γ) using the recursive nCRP definition: x is the smallest positive integer not in the above set. Figure 2 displays our complete generative process as a graphical model. As a side note, the infinite nCRP prior on paths implies that B contains an infinite number of elements (there could be infinitely many children at each parent, so the compatibility matrices must be infinite-dimensional). Our Gibbs sampler finesses this issue by integrating out B, while the posterior distribution of each B ·,·,· can be recovered from the path and level samples.

Collapsed Gibbs Sampler
Exact inference on our model is intractable, so we derive a collapsed Gibbs sampling scheme for posterior inference. The θ's and B's are integrated out for faster mixing, so we only have to sample z and c. The sampling equations are provided below.
Sampling levels The distribution of z i→j conditioned on all other variables is where E −(i,j) is the set of all edges except E ij , and z i,(−j) = {z i→· , z ·←i } \ z i→j . By Beta-Bernoulli conjugacy, the first term, for a particular value of z i→j , is where we have defined the shorthand The second term can be computed by iterated expectation, conditioning on actor i's stick breaking lengths V i1 ,...,V ik : Since we have limited the maximum depth to K, we simply ignore the event z i→j > K, and renormalize the distribution of z i→j over the domain {1, . . . , K}. The conditional distribution of z i←j is derived in similar fashion.
while the first term, for a particular value of c i , is where B (i,·),(·,i) = {B ∈ B | ∃(i, j), (E ij ∈ E (i,·),(·,i) ∧ S B (E ij ) = B)} is the set of all B ∈ B associated with some edge in E (i,·),(·,i) through S B ().

Simulation
We evaluate our model's ability to recover hierarchies on simulated data. For all simulations, the number of actors N was 150, the max depth was K = 2 (2 levels plus root) and θ = (.25, .75) for all actors, meaning that actors interact at level 1 25% of the time and level 2 75% of the time.
Our experiments explore the effect of different compatibility matrices B. We first explore an ondiagonal B, where the diagonal elements are much larger than the off-diagonal elements (actors tend to interact within their own communities). We also investigate an off-diagonal B, where the off-diagonal elements are larger (actors tend to interact outside their own communities). In the "low noise" setting the off-diagonal and on-diagonal elements are far apart (to clearly distinguish them), while in the "high noise" setting they are closer together. The exact parameters for the 4 types of B's are shown below: B on−diagonal = (a, b) means that actors interacting in the same level-1 community do so with probability a, while actors interacting in the same level-2 community do so with probability b (and analogously for B of f −diagonal ).
We compare our approach to hierarchical spectral clustering (denoted HSpectral). For spectral clustering, it is unclear how the number of clusters at each node would be selected, so we give it the number of 1st-level branches as an advantage (and then let it do a binary split at each level-2 node). For hMMSB, we fix m = π = λ 1 = λ 2 = .5 and search over γ = {.01, .1, .5, 1, 1.5, 2}, picking the value that maximizes the marginal likelihood.
The Gibbs sampler was run for 1,500 iterations on each experiment. We calculate the F1 score at each level k, F1 k = 2 * P recision * Recall Recall+P recision where Recall = T P T P +F N , and P recision = T P T P +F P . T P is true positive count (actors that are in the same cluster and should be up to depth k), F P is false positive count, T N is true negative count, and F N is false negative count. The total F1 score is computed by averaging the F1 k scores for each level. Figure 3 illustrates the results as a function of the number of branches at the first level of the generated tree. The "number of branches at level 1" refers to number of branches of size ≥ 5 (since there are often branches of size 1 or 2). For fairness, the "correct" number of level-1 branches given to spectral clustering is also the number of branches of size ≥ 5.
As one can see, in Figure 3(a) and Figure 3(b), when B is strongly on-diagonal, our algorithm performs well, but a little worse than HSpectral (since HSpectral is given the number of level-1 branches). A specific example is shown in Figures 3(e), 3(f), 3(g), 3(h) where both models perform reasonably well. However, when B is strongly off-diagonal (implying that actors tend to interact with those in different communities and rather than within their own community), HSpectral performs poorly. Our method still gives good results (Figure 3(c), Figure 3(d)). An example is shown in Figures 3(i), 3(j), 3(k), 3(l) where our model performs accurately while HSpectral essentially divides the actors randomly and performs poorly. Thus HMMSB successfully models a variety of community interactions that traditional clustering methods cannot. It can also recover the actor-specific interaction levels for a richer network analysis.  We compare our algorithm to MMSB [2] on two real-world datasets, a 75-species food web of grass-feeding wasps [6,4], and the September 11th, 2001 hijacker terrorist network [15,4]. Our choices reflect two common modes of interaction seen in real-world network data: edges in the food web denote predator-prey relationships, while edges in the terrorist network reflect social cohesion. The food web could be represented as a hierarchy where different branches reflect different trophic levels (e.g. parasite, predator or prey), while the terrorist network could be interpreted as an organization chart.

Held-out Evaluation
For each dataset, we generated 5 sets of training and test subgraphs, each obtained by randomly partitioning the actors into two equal sets. For each training subgraph, we performed a gridsearch over the B parameters (λ 1 , λ 2 ) ∈ {.1, .3, .5, .7, .9} 2 according to the log marginal likelihood. The remaining parameters were fixed to γ = 1, m = π = 0.5 and K = 2. We then computed the log marginal likelihood on the corresponding 5 test subgraphs, and averaged them to obtain hMMSB's average held-out likelihood. The procedure for MMSB was similar, except that we used 100 random restarts of the MMSB variational EM algorithm [2] on the training subgraphs. MMSB also requires the number of latent roles R as a tuning parameter, so we repeated the experiment for each 2 ≤ R ≤ 20. For either algorithm, log marginal likelihoods were estimated using 10,000 iterations of importance sampling.
The results are shown in Figure 4. On either dataset, our model's held-out likelihood is superior to MMSB for all R. Notably, MMSB's likelihood peaks on both datasets at R = 2, but selecting so few roles will lead to an extremely coarse network analysis. In contrast, our model automatically recovers a suitable level of hierarchical complexity and enables rich interpretations of the data -as we shall demonstrate next. We note that the "annotated hierarchies" model [19] and infinite stochastic blockmodel [12] are good candidates for evaluation, but the authors did not make code available for computing marginal likelihoods, so we do not include those models in our evaluation.
6 Real-data Qualitative Analysis

Grass-feeding Wasp Parasitoids Food Web
We now use hMMSB to interpret real-world social networks, beginning with the grass dataset from earlier. We ran our Gibbs sampler on the full network to infer the community hierarchy structure and actor latent community MMs. The model parameters were chosen on the full network via grid search over (λ 1 , λ 2 ) ∈ {.1, .3, .5, .7, .9} 2 , according to the log marginal likelihood (estimated using 10,000 importance samples). The remaining parameters were fixed to γ = 1, m = 0.5, π = 0.5 and K = 2.
We ran our Gibbs sampler on the optimal parameters λ 1 = 0.1, λ 2 = 0.5 for 10,000 iterations of burn-in, and took 100 samples with a lag time of 5 iterations. Convergence was determined from a plateauing log complete likelihood plot.
The Gibbs samples represent a posterior distribution over paths c i . In order to represent the "average" of this posterior, we generated a consensus sample by counting the number of times each pair of actors shared the same community hierarchy position, over all samples. Actors that shared positions in > 50% of all samples were assigned to the same path in the consensus. For levels z i→j and z i←j , we simply took the mode over all samples. In a final post-processing step to reduce visual clutter, we merged bottom-level (i.e. level-2) communities with ≤ 5 actors into one community under the same parent.
The inferred community hierarchy and MM vectors from our Gibbs sampler are reported in Figure  6. We also show the original network, where links E ij = 1 have been augmented with their communities and interaction levels (missing links E ij = 0 are not shown). The dataset contains trophic level annotations, shown in the hierarchy as counts and in the network as node shapes.
We see that community 3 contains all grass species, 2 contains most herbivores, and 1 contains most parasitoids; in contrast, an assortative clustering algorithm would not discover these multi-partite divisions. The "outlier" communities are still more interesting -the herbivore in community 6 is the sole prey of the parasitoids in community 4; hMMSB has separated this sub-web from the main food-web. Moreover, the herbivores in community 2.2 are the sole prey of species 42 and 41 in community 1.1. We also observe that community 5's two apex parasitoids have the largest and 2ndlargest range of prey species, while community 1.2 contains the apex parasitoid with the third-largest range. As to why these communities are separated, we note that the parasitoid in sub-community 1.2 preys on only two herbivores, compared to at least six herbivores for either parasitoid in community 5.
The community MM vectors in Figure 6 show the frequency at which each species identifies itself with a particular community. Most species identify at the super-community level, though some occasionally identify at the sub-community level. In our model, level-2 interactions occur only within super-communities, hence they account for fine-grained, within-community interactions. For example, the within-community links in community 4, as well as the links from species 65 in subcommunity 1.2 to other members of community 1, are all level-2 interactions. Although we have not shown interaction levels for missing links, the latter are sometimes accounted for by level-2 interactions (e.g. in community 1).  Finally, we consider a 1,000-paper subgraph of the arXiv highenergy physics citation network [1], which we constructed by subsampling papers involved in citations from Jan 2002 through May 2003.

High-energy Physics Citation Network
We applied the same parameter selection, convergence criteria, and post-processing as the previous dataset, and the optimal parameters were (λ 1 = 0.7, λ 2 = 0.5). Each of the 25 parameter combinations required less than 6 hours to test on a single processor core. We ran our Gibbs sampler for 10,000 iterations of burn-in, and took 10 samples with a lag time of 50 iterations. The entire Gibbs sampling procedure completed in just under 23 hours on a single processor core.
The inferred community hierarchy is shown in Figure 7, where each sub-community has been annotated with its papers' most frequent title words 1 . We also show the adjacency matrix in Figure 5, permuted to match the order of inferred communities. We observe that the 810-paper sub-community has a sparse citation pattern, implying that its papers are not specific to a particular research topic. This is confirmed by the top 3 keywords: "theory", "field" and "quantum", which are general to physics research. The other sub-communities from the same supercommunity are more focused, with top keywords like "supergravity", "string" and "pp-wave" being more specific physical concepts. This is also reflected in the adjacency matrix, which is denser among these sub-communities. The remaining super-communities form a very dense sub-network that is mostly separated from the rest of the graph, suggesting that these papers might come from a specific community of researchers, working on a narrow set of research topics. In particular, three   of the sub-communities involve the title keyword "tachyon", which is absent from the large supercommunity. To this point, we have only scratched the surface of the citation network -a deeper analysis would involve the abstracts/contents of the papers in the hMMSB-inferred communities.

Conclusion
We have developed a tree-structured hierarchical Mixed-Membership Stochastic Blockmodel (hMMSB) that models social networks in terms of the multiple, hierarchical community memberships that actors undertake during interactions. Our model automatically infers the number of sub-communities in each community while simultaneously recovering the community-mixedmemberships of every actor, setting it apart from hierarchy-discovering methods that are restricted to binary hierarchies and/or single-role-memberships for actors. Moreover, hMMSB is expressive enough to account for non-diagonal community-compatibility matrices, as we have demonstrated through our simulation and grass dataset experiments. On real networks, we show that hMMSB recovers intuitive, mixed-membership community organization. Finally, our collapsed Gibbs sampler efficiently scales to medium-sized datasets of around 1,000 actors, completing inference in a single day on a single processor core.