1 Introduction

The widespread use of modern social media has created a huge amount of online social interactions, fostered the formation of communities (e.g., (Ghoshal et al., 2021; Ghoshal & Das, 2017; Ghoshal et al., 2019)) and facilitating discussions about a variety of topics. Users establish positive relationships such as friendships, agreements, and supports, as well as negative relationships such as foes, disagreements, and distrusts. The existence of such mixed interactions has led to an ever-growing polarization phenomenon, i.e., a division of the set of users into groups with opposite view on controversial topics (e.g., politics, religion, sport).

In the past few years, we have witnessed a plethora of studies about polarization on social media (Conover et al., 2011; Hohmann et al., 2023; Garimella et al., 2017). Polarization is often distinguished in ideological and affective polarization (Lelkes, 2016): the former refers to increased ideological divergence and reduced dialogue among individuals with differing views, whereas the latter focuses on affective attitude that individuals show toward others based on their opinions (Hohmann et al., 2023). Nonetheless, other approaches to the study of polarization discard a particular qualification of the term polarization, while adopting a graph-theoretic setting where the goal is to discover polarized communities in signed graphs (Bonchi et al., 2019; Tzeng et al., 2020). In this work, we follow the latter line of studies. Remarkably, a key novelty in our work is the exploitation of machine learning, particularly neural network models, for discovering a polarization structure.

Polarization in signed graphs. Signed graphs are graphs whose edges are assigned either a positive or a negative label, denoting whether the interaction depicted by an edge is friendly or antagonistic, respectively (Harary, 1953). Signed graphs are used to model a variety of data and study numerous (social) phenomena, such as emergence of polarized discussions in social media, or analysis of trust/distrust in review platforms (Beigi et al., 2016; Derr et al., 2018; Yao et al., 2022; Zheng et al., 2015). Bonchi et al. (2019) employ signed graphs to define the problem of 2-Polarized-Communities (for short, 2pc), which requires finding two subsets of nodes, generally referred to as communities, of the input signed graph such that there are (R1) mostly positive edges within each community and (R2) mostly negative edges between the two communities, and (R3) the subgraph induced by these two communities is as much dense as possible; for instance, assuming that positive (resp. negative) edges denote agreement (resp. disagreement) of social media users w.r.t. a given context of debate, identifying the two polarized communities correspond to detecting two groups of users, where users of the same group mostly agree with each other, while having divergent opinions with respect to the users of the other group. Also, the two communities are required to be non-overlapping, but they do not necessarily need to cover the entire node set. The rationale of the latter is to comply the most with real-world situations, where polarized communities are concealed within a body of other graph nodes which do not (yet) have a strongly formed opinion, and, as such, they are neutral in terms of polarization.

Fig. 1
figure 1

Example signed graph, with solid lines and red dashed lines corresponding to positive and negative edges, respectively. The optimal solution of the relaxed 2pc problem yields, after rounding, one community containing node A only and the other community containing all the remaining nodes. However, the same rounding strategy applied to a suboptimal solution of the relaxed problem leads to node A and nodes D-E forming the two communities, while nodes B-C are detected as neutral: this is not only a more likely realistic configuration (due to the roles played by nodes B-C) than the communities derived from the optimal solution, but it also turns out to have higher polarity than the latter. For more details on this example, see Example 1 in Section 3

Motivation: limitations of the state of the art in \(\textsc{2PC}\). The above R1–R3 requirements for the \(\textsc{2PC}\) problem are jointly pursued by maximizing a single objective function, termed polarity. Bonchi et al. (2019) show that maximizing polarity is \(\textbf{NP}\)-hard, but also that a continuous relaxation of that problem is solvable in polynomial time. They exploit this finding to devise algorithms which consist in properly rounding (i.e., discretizing) the optimal solution of the relaxed problem.

\(\underline{Limitation\, 1}\). Despite Bonchi et al.’s algorithms are principled and rather effective, they suffer from the fact that deriving a solution to 2pc starting from the optimal solution of the relaxed problem may be limiting in terms of polarity. In fact, as illustrated in Figure 1, suboptimal solutions to the relaxed problem can lead to better solutions to 2pc after rounding.

\(\underline{Limitation\, 2}\). The polarity function does not require or foster the detection of size-balanced communities. Indeed, maximizing polarity can easily lead to degenerate solutions with a single sufficiently large community and another (almost) empty community, even if the input signed graph does contain “natural” polarized communities that are both non-empty and possibly of comparable size. Several types of social environments, from social media platforms to online forums, from political systems to scientific communities, can benefit from identifying and maintaining balanced polarized communities. By ensuring that communities are diverse while still containing balanced viewpoints, constructive debates can be facilitated, critical thinking can be encouraged, and the individuals’ perspectives can be broadened, thus reducing echo chambers and mitigating the spread of misinformation. Also, companies involved in market research and product development can benefit from gathering insights from diverse consumer groups balanced in size, and ultimately better understand market preferences and anticipate consumer trends.

Therefore, there is a need for methods that can detect balanced polarized communities. In this respect, turning back to example of Figure 1, the assignment of A to one community, D-E to the other community, and B-C as neutral, is also much more balanced than the one derived from the optimal relaxed-solution, where node A forms its own community, and all the other nodes are assigned to the other community.

The above example also highlights the need for detecting fine-grained polarization phenomena, i.e., polarized communities that may not be apparent in terms of node size or amount of connections involved therein. This is in fact essential to recognize minorities in polarization, which in turn might correspond to harmful situations like isolation, where a small group of individuals are marginalized or isolated by a larger, cohesive group; later in this paper, we will provide an example of such polarization setting.

Contributions. In this paper, we advance the state of the art in the 2pc problem by properly addressing the above limitations. Specifically, we provide a twofold contribution.

First, targeting Limitation 1, we devise a novel machine-learning approach that allows for soundly and effectively exploring a variety of suboptimal solutions to the relaxed problem, so as to ultimately select the one that leads to the best discrete solution to 2pc after rounding.

Second, to overcome Limitation 2, we devise a generalization of the polarity function, named \(\gamma \)-polarity. When optimizing standard polarity, in fact, 2pc solutions tend to produce strongly imbalanced polarized communities, especially when dealing with large graphs. Our proposed \(\gamma \)-polarity is designed to produce polarized communities that, depending on the setting of \(\gamma \), can be either more balanced or larger than those yielded by standard polarity.

The proposed approach leverages a neural-network-based framework, whose core component is a signed graph neural network (GNN) model, to learn continuous vector representations of the input nodes, for the task of assigning each node a real-valued score between -1 and 1. Such a score is ultimately rounded onto \(\{-1, 0, 1\}\), so as to determine whether the corresponding node is part of one of the two communities (\(-1\) or 1), or is neutral (0). To this purpose, our neural framework is optimized via a loss corresponding to the relaxed polarization function, coupled with a suitable regularization term.

Rationale and benefits of our proposal are as follows:

(\(\textbf{1}\)) A neural approach is well-suited for 2pc due to the compatibility of continuous relaxation of 2pc with neural network differentiability. By setting the loss function to the relaxed 2pc objective and performing rounding after each learning step, we bridge the gap between discrete constraints of the underlying combinatorial-optimization problem and the inherently continuous mathematical framework of neural networks. Also, both input and output of (relaxed) 2pc are naturally handled by neural-network building blocks too: the input graph by a signed GNN, and the output \([-1, 1]\) score by a \(\tanh \) activation function. Furthermore, external information associated with nodes can easily be integrated into our framework, since GNNs are designed to initialize the hidden node representations (embeddings) with any available node features.

(\(\textbf{2}\)) While simple, our approach is backed by solid machine-learning fundamentals, which make it principled and sound. In fact, training our neural framework via standard gradient descent provides an elegant solution to the aforementioned requirement of exploring a variety of suboptimal solutions to relaxed 2pc. Every epoch of training of our framework ends up with a rounding which produces a discrete 2pc solution, where a proper loss regularization term is introduced to enforce the continuous scores to be closer to discrete \(\{-1, 0, 1\}\) values.

(\(\textbf{3}\)) Our framework is lightweight, yet highly versatile and modular, facilitating easy maintenance and updates to keep pace with the latest GNN models and deep learning advancements. Future improvements, like enhanced signed GNNs, can be seamlessly integrated by modifying a single building block. Additionally, our framework allows for seamlessly incorporating additional requirements on the yielded solutions, such as fostering size balance, as we discuss next.

(\(\textbf{4}\)) We effectively address non-size-balanced communities by maximizing \(\gamma \)-polarity, a generalization of standard polarity, using it as a loss in our neural framework. This links our second main contribution (\(\gamma \)-polarity) with our first (neural approach to 2pc).

(\(\textbf{5}\)) Our proposal offers multiple benefits to the research community. It represents the first machine-learning approach to 2pc, which opens the door to further research and improvement. The same applies to \(\gamma \)-polarity, which warrants additional exploration from a combinatorial optimization perspective. Moreover, our work can serve as inspiration for other combinatorial optimization problems, which share the common trait with 2pc that suboptimal relaxed solutions may lead to improved rounded solutions.

Summary  and  roadmap. Our main contributions in this work can be summarized as follows:

  • We tackle 2pc (Bonchi et al., 2019), i.e., the problem of discovering two polarized communities from an input signed graph (Section 2), and define a novel neural-network-based approach to address it (Section 3).

  • We introduce a generalization of 2pc ’s objective function, termed \(\gamma \)-polarity, which favors size balance among communities, and show how to optimize it within the proposed neural framework (Section 4).

  • We provide extensive experiments on a large variety of real-world and synthetic signed graphs (Section 5). Results (Section 6) attest high accuracy of our approach, its superiority over the state of the art, and the effectiveness of \(\gamma \)-polarity in detecting balanced communities.

Section 7 concludes the paper and discusses future work.

2 Preliminaries and background

Let \(G = (V, E^+, E^-)\) be an undirected signed graph, where V is a set of nodes, and \(E^+, E^- \subseteq V \times V\), \(E^+ \cap E^- = \emptyset \), are sets of positive and negative edges, respectively. We assume an arbitrary order over V, such that nodes are assigned a unique integer ID within \(\{1, \ldots , |V|\}\). With a little abuse of notation, we interchangeably refer to \(u \in V\) as both the node u itself and the u-th node in the order. This keeps vector/matrix notations simpler. \(\textbf{A}\in \lbrace -1, 0, 1 \rbrace ^{|V| \times |V|}\) is the signed adjacency matrix of G, defined as \(\textbf{A}[u,v] = 1\) if \((u, v) \in E^+\), \(\textbf{A}[u,v] = -1\) if \((u, v) \in E^-\), and \(\textbf{A}[u,v] = 0\) otherwise. Table 1 summarizes main notations used throughout this paper.

Table 1 Main notations used in this paper

2.1 Problem statement

We deal with the combinatorial-optimization problem of 2-Polarized-Communities (for short, 2pc), originally defined by Bonchi et al. (2019). Given a signed graph \(G = (V, E^+, E^-)\), 2pc finds two disjoint subsets \(S_1, S_2 \subseteq V\) of nodes such that (R1) there are as many positive edges and as few negative edges as possible within \(S_1\) and within \(S_2\); (R2) there are as many negative edges and as few positive edges as possible across \(S_1\) and \(S_2\); and (R3) the subgraph induced by \(S_1 \cup S_2\) is as dense as possible, according to a density defined as the ratio between number of edges and number of nodes.

\(S_1\) and \(S_2\) are interpreted as polarized communities, i.e., groups of users (nodes) who are cohesive in terms of both intra-group positive relationships (edges) and inter-group negative relationships. Nodes included into neither \(S_1\) nor \(S_2\) – denoted \(S_0 = V \setminus (S_1 \cup S_2)\) – form the set of neutral nodes. A partition \(\lbrace S_0, S_1, S_2 \rbrace\) of V can alternatively be represented by a (column) vector \(\textbf{x}\in \lbrace -1, 0, 1 \rbrace ^{|V|}\), whose u-th coordinate is \(\textbf{x}_u = 0\) if \(u \in S_0\), \(\textbf{x}_u = 1\) if \(u \in S_1\), and \(\textbf{x}_u = -1\) if \(u \in S_2\).

The above R1–R3 requirements of 2pc are altogether encoded into a single function, termed polarity:

Definition 1

(Polarity (Bonchi et al., 2019)). Given a vector \(\textbf{x}\in \{-1, 0, 1\}^{|V|}\) and a matrix \(\textbf{A}\in \{-1, 0, 1\}^{|V| \times |V|}\), the polarity \(p(\textbf{x}, \textbf{A})\) of \(\textbf{x}\) with respect to \(\textbf{A}\) is defined as:

$$\begin{aligned} p(\textbf{x}, \textbf{A}) = \frac{\textbf{x}^{\top } \! \textbf{A}~\textbf{x}}{\textbf{x}^\top \textbf{x}}. \end{aligned}$$
(1)

The numerator of \(p(\cdot , \cdot )\) accounts for R1 and R2, while numerator and denominator altogether model R3. In this regard, note that \(\textbf{x}^\top \textbf{x}= |S_1 \cup S_2|\).

The 2pc problem is formulated as follows:

Problem 1

(2pc (Bonchi et al., 2019)). Given a signed graph \(G = (V, E^+, E^-)\) with signed adjacency matrix \(\textbf{A}\), find

$$\begin{aligned} \textbf{x}^* = \mathop {\mathrm {arg\,max}}\limits _{\textbf{x}\in \lbrace -1, 0, 1 \rbrace ^{|V|}} p(\textbf{x}, \textbf{A}). \end{aligned}$$

Relaxing node-to-community assignments to be continuous, i.e., \(\in [-1, 1]\), leads to the following relaxed problem:

Problem 2

(2PC-relaxed (Bonchi et al., 2019)). Given a signed graph \(G = (V, E^+, E^-)\) with signed adjacency matrix \(\textbf{A}\), find

$$\begin{aligned} \textbf{z}^* = \mathop {\mathrm {arg\,max}}\limits _{\textbf{z}\in [-1,1]^{|V|}} p(\textbf{z}, \textbf{A}), \end{aligned}$$

where polarity \(p(\textbf{z}, \textbf{A}) = \textbf{z}^{\top } \! \textbf{A}~\textbf{z}/\textbf{z}^\top \textbf{z}\) of a real-valued vector \(\textbf{z}\in [-1,1]^{|V|}\) is defined the same as Definition 1.

State of the art in 2pc. 2pc is shown to be \(\textbf{NP}\)-hard, while 2PC-relaxed can be solved in polynomial time by finding the eigenvector of the signed adjacency matrix corresponding to the largest eigenvalue (Bonchi et al., 2019). Bonchi et al. (2019) exploit the latter to devise two approximation algorithms for 2pc. The first (deterministic) algorithm simply rounds the optimal solution \(\textbf{z}^*\) to 2PC-relaxed as \(\textbf{x}^*_u = \mathop {\textrm{sgn}}\limits (\textbf{z}^*_u)\), for all \(u \in V\), where \(\mathop {\textrm{sgn}}\limits (\cdot )\) is the sign function. The second (randomized) algorithm sets, for all \(u \in V\), \(\textbf{x}^*_u = \mathop {\textrm{sgn}}\limits (\textbf{z}^*_u)\) if a Bernoulli experiment with success probability \(|\textbf{z}^*_u|\) succeeds, otherwise \(\textbf{x}^*_u=0\).

Tzeng et al. (2020) extend 2pc to a k-community setting, where the goal is to find \(k \!\ge \! 2\) node subsets, each of which is positively connected internally, and negatively connected to the other subsets. Extending our approach to \(k \!>\! 2\) communities is an interesting direction for future work.

2.2 Related works

Besides polarization in signed graphs, which is the focus of our study, it is useful to recall here methods that address related problems.

Representation learning for signed graphs. Graph representation learning is the problem of assigning elements of a graph (e.g., nodes, edges, subgraphs) to numerical vectors (embeddings) such that the similarity between those elements in the graph corresponds to the similarity between their embeddings. The literature on graph representation learning is vast, and includes learning approaches that are shallow, which optimize a certain criterion directly (e.g., d-hop reachability, random-walk co-occurrence) and deep, i.e., based on graph neural networks (GNNs) (Cai et al., 2018; Wu et al., 2022). Representation learning has been studied for signed graphs as well, including both undirected methods (Derr et al., 2018; Liu et al., 2021; Li et al., 2020; Wang et al., 2017; Kim et al., 2018) and directed methods (Huang et al., 2021, 2019).

In this work, we regard signed graph representation learning as a building block of the proposed framework. Note that our approach is versatile w.r.t. the choice of graph representation learning model; however, creating a custom model for our specific task is beyond the scope of this work.

Clustering signed graphs has also received attention in the literature (Chiang et al., 2012; Cucuringu et al., 2019; He et al., 2022; Kunegis et al., 2010; Mercado et al., 2016).

However, those methods require every node to be part of an output cluster, hence they are not designed to detect neutral nodes and left them out of evaluation, unlike our approach. Also, signed graph clustering methods optimize criteria other than polarity. Nonetheless, given their relative popularity yet relatedness with our problem, we shall consider some of the most prominent methods in this category in our experimental evaluation (cf. Section 5).

Other patterns in signed graphs. A number of works focus on extracting subgraphs from signed graphs according to measures other than polarity. Ordozgoiti et al. (2020) aim at extracting a maximum-size subgraph which exhibits perfect balance (Harary, 1953), i.e., it can be partitioned into two sets of nodes such that there are only positive intra-group edges and only negative inter-group edges. Despite the name, Ordozgoiti et al.’s notion of balance has nothing to do with size balance of the groups of the output subgraph. Also, the output groups may be arbitrarily sparse, as the goal is to maximize the size of the output subgraph, no matter how dense it is. Xiao et al. (2020) extract subgraphs that maximize signed bipartiteness ratio. That measure mainly differs from polarity as it enforces separation from the identified subgraphs to the rest of the graph, rather than maximizing the density of the subgraphs. Also, Xiao et al. deal with a local setting, where subgraphs are built by expanding two given sets of seed nodes. Niu and Sariyüce (2023) deal with dichotomy, a variant of polarity which is more oriented to cohesiveness. Chu et al. (2016) optimize oppositive cohesiveness, a measure which considers cohesiveness in absolute terms, rather than in relation to the number of nodes (it is not based on any notion of density). Please note that handling measures other than polarity is beyond our scope.

Machine learning for combinatorial optimization leverages machine-learning techniques to solve combinatorial-optimization problems (Cappart et al., 2023; Peng et al., 2021). This research area has focused on problems such as influence maximization (Li et al., 2023), (graph) clustering (Jung & Keuper, 2022; Tsitsulin et al., 2023), community search and detection (Su et al., 2022).

To the best of our knowledge, we are the first to define a machine-learning approach to the 2pc problem.

Fig. 2
figure 2

Overview of the proposed Neural2PC approach

3 Proposed approach: Neural2PC

Overview. Unlike existing methods (Bonchi et al., 2019) which find the optimal solution \(\textbf{z}^*\) to 2PC-relaxed (Problem 2) directly, we let a neural-network model \(f_{\theta }\) – with parameters \(\theta \) – produce a set \(\{\textbf{z}_e \mid e = 1, \ldots , e_{max}\}\) of feasible solutions to 2PC-relaxed during multiple epochs \(1, \ldots , e_{max}\) of training. All the various \(\textbf{z}_e\) are rounded in order to yield feasible discrete solutions \(\textbf{x}_e\) to 2pc. The best (in terms of polarity, Definition 1) of such \(\textbf{x}_e\) solutions is the definitive output.

The rationale of our neural approach is that it soundly allows for exploring a variety of suboptimal solutions to 2PC-relaxed. As better shown in Example 1 at the end of this section, this favors obtaining ultimate discrete solutions (after rounding) which exhibit higher polarity than the one derived by rounding the optimal solution to 2PC-relaxed.

The ultimate objective in our approach is to find the model parameters \(\theta \) that maximize the polarity of the (relaxed) solutions computed via \(f_{\theta }\) (or, equivalently, minimize a loss defined based on the negative polarity). Note that, as parameter learning goes on, it is expected to get a deeper exploration of the space of relaxed solutions, and hence a higher likelihood of getting an effective discrete solution after rounding. This is confirmed by experimental evidence (Section 6).

The proposed neural approach is named Neural2PC. A graphical illustration of its main components is shown in Figure 2. Next, we delve into its technical details.

Neural model. Our \(f_\theta \) model takes as input a signed graph \(G = (V, E^+, E^-)\), and a matrix \(\textbf{H}_0\in \mathbb {R}^{|V| \times d_{I}}\) containing a \(d_I\)-dimensional (real-valued) vector of features for every node. Should such features be not available, \(\textbf{H}_0\) can be initialized by considering structural information derived from G (Derr et al., 2018).

The first block of \(f_\theta \) is a (m-layer) signed GNN (Derr et al., 2018; Liu et al., 2021; Li et al., 2020; Wang et al., 2017; Kim et al., 2018) sgnn(\(\cdot \)), with parameters \(\theta _{\textsc {sgnn}}\). sgnn(\(\cdot \)) properly processes G’s topology and (possibly) node features \(\textbf{H}_0\), and outputs a matrix \(\textbf{H}\in \mathbb {R}^{|V| \times d_H} = [\textbf{h}_u \in \mathbb {R}^{d_H}]_{u \in V}\) containing a hidden vector representation \(\textbf{h}_u\) of every node \(u \in V\):

$$\begin{aligned} \textbf{H}= \textsc {sgnn}(G,\textbf{H}_0). \end{aligned}$$
(2)

Then, vector representations produced by sgnn(\(\cdot \)) feed into fully-connected neural-network linear layers nn(\(\cdot \)), with parameters \(\theta _{\textsc {nn}}\). Ultimately, a \(\tanh \) activation function is used to cast the (node-to-community assignment) scores for every node to the desired \([-1, 1]\) range (cf. Problem 2):

$$\begin{aligned} \textbf{z}= \tanh (\textsc {nn}(\textbf{H})). \end{aligned}$$
(3)

As a result, the overall \(f_{\theta }\) model is as follows:

$$\begin{aligned} f_{\theta }(G, \textbf{H}_0) = \tanh (\textsc {nn}(\textsc {sgnn}(G,\textbf{H}_0))), \end{aligned}$$
(4)

and its parameters are \(\theta = \{\theta _{\textsc {sgnn}}, \theta _{\textsc {nn}}\}\).

Loss function. To optimize model parameters \(\theta \), we employ a loss function \(\mathcal {L}_{\text {2PC}}\) defined as a combination of (the negative of) polarity \(p(\cdot , \cdot )\) (Definition 1) and a proper regularization term. The role of the latter is to enforce the model produce continuous scores that are as close as possible to the ultimately desired discrete \(\{-1, 0, 1\}\) scores. Specifically, we define the regularization term as the \(||\cdot ||_2\) L2-norm of a vector \(\mathbf {\rho } \in \mathbb {R}^{|V|}\), whose entries \(\mathbf {\rho }[u]\), for all \(u \in V\), are set to the difference \(\min \lbrace |\textbf{z}[u]|, 1 - |\textbf{z}[u]| \rbrace \) between \(\textbf{z}[u]\) and the closest valid discrete score. The intuition is that minimizing the norm of \(\mathbf {\rho }\) (together with the other loss component) is expected to produce the desired effect of yielding output continuous \(\textbf{z}\) scores not too far from the valid discrete ones.

All in all, given \(\textbf{z}= f_{\theta }(G, \textbf{H}_0)\), the signed adjacency matrix \(\textbf{A}\) of G, and a hyperparameter \(\lambda \in \mathbb {R}\) which properly weighs the importance of the regularization term, the \(\mathcal {L}_{\text {2PC}}\) loss function is defined as:

$$\begin{aligned} \mathcal {L}_{\text {2PC}}(\textbf{z}, \textbf{A}, \lambda ) \ = \ - \underbrace{p(\textbf{z},\textbf{A})}_{\text {polarity}} \quad + \quad \lambda \!\!\!\!\underbrace{ ||\mathbf {\rho }||^2_2}_{\text {regularization}} \end{aligned}$$
(5)

Rounding. To round a continuous solution \(\textbf{z}\in [-1, 1]^{|V|}\) onto a valid discrete \(\textbf{x}\in \{-1, 0, 1\}^{|V|}\) solution to 2pc, we borrow the procedure adopted by Bonchi et al. (2019). Specifically, given a threshold \(\tau \in [0,1]\), for all \(u \in V\), \(\textbf{x}[u] = \mathop {\textrm{sgn}}\limits (\textbf{z}[u])\) if \(|z[u]| \ge \tau \), \(\textbf{x}[u] = 0\) otherwise. In order to avoid sticking to a single \(\tau \), we follow (Bonchi et al., 2019), and try all the thresholds \(\tau \in \lbrace \lceil \textbf{z}[u] \rfloor _{i} \mid u \in V \rbrace \), where \(\lceil \cdot \rfloor _i\) denotes approximating a real number at the i-th decimal digit (we use \(i = 3\)). Formally:

$$\begin{aligned} Z_i = \{\lceil \textbf{z}[u] \rfloor _i \mid u \in V\}. \\ \forall u \in V: \ \textbf{x}_\tau [u] = \left\{ \!\!\begin{array}{rl} \mathop {\textrm{sgn}}\limits (\textbf{z}[u]), &{} \text{ if } |\textbf{z}[u]| \ge \tau .\\ 0, &{} \text{ otherwise }. \end{array}\right. \end{aligned}$$
$$\begin{aligned} {\textsc {round}}(\textbf{z}) \ = \!\!\! \mathop {\mathrm {arg\,max}}\limits _{\textbf{x}~\!\in ~\!\{\textbf{x}_\tau ~\!\mid ~\!\tau \in Z_i\}}p(\textbf{x}, \textbf{A}). \end{aligned}$$
(6)
Algorithm 1
figure a

Neural2PC

Algorithm. The algorithm we employ to produce a solution to 2pc simply consists in optimizing the \(\theta =\{\theta _{\textsc {sgnn}}, \theta _{\textsc {nn}}\}\) parameters of the \(f_{\theta }\) neural model end-to-end, via standard gradient descent, for a number \(e_{max}\) of training epochs. Specifically, the algorithm alternates a forward phase, which produces a continuous solution \(\textbf{z}\) given the current \(\theta \) parameters, and a backward phase, where parameters \(\theta \) are updated via gradient descent, using the \(\mathcal {L}_{\text {2PC}}\) loss function, with a certain learning rate \(\alpha \). The continuous solution \(\textbf{z}\) yielded in every epoch is rounded according to the round(\(\cdot \)) procedure described above. The discrete rounded solution with the highest polarity score out of all the ones produced in the various epochs is ultimately output. The reason of performing rounding and evaluating the polarity of the discrete solution in every epoch is that it is hard to know in advance the exact epoch leading to the best discrete solution (see Section 6).

The proposed algorithm is outlined as Algorithm 1.

Motivating example. The following example shows the relevance of considering suboptimal solutions to 2PC-relaxed, and validates the main motivation of our neural approach.

Example 1

Consider again the toy signed graph in Figure 1. For the sake of vector notation, let the order over node set \(\{{\texttt {A,B,C,D,E}}\}\) correspond to the lexicographic node order, i.e., A corresponds to entry 1 in the vectors, B corresponds to entry 2, and so on. \(\textbf{z}^* = [0.282, -0.282, -0.282, -0.616, -0.616]\) is the optimal solution to 2PC-relaxed on that example graph, and \(\textbf{z}= [0.213, -0.144, -0.144, -0.378, -0.378]\) is a suboptimal solution (yielded by our neural approach). The polarity (Definition 1) of \(\textbf{z}^*\) and \(\textbf{z}\) is 2.372 and 2.363, respectively. Adopting the aforementioned rounding (Equation (6)), \(\textbf{z}^*\) leads to a discrete solution \(\textbf{x}_1 = [1, -1, -1, -1, -1]\) (with threshold \(\tau = 0.282\)). Instead, \(\textbf{z}\) yields \(\textbf{x}_2 = [1, 0, 0, -1, -1]\) (with \(\tau = 0.213\)). The polarity of \(\textbf{x}_2\) is 2, which is higher than the polarity 1.6 of \(\textbf{x}_1\). Note also that \(\textbf{x}_2\) corresponds to the optimal solution to 2pc on the example graph at hand.

Computational complexity. We discuss computational complexity aspects of our proposed approach.

The temporal cost associated to the SGNN block depends on the particular neural-network architecture. Nonetheless, assuming a sparse input signed graph with edge set \(E = E^+ \cup E^-\), the overall time complexity of a SGNN model with m layers can be regarded as bounded by \(\mathcal {O}(m (|V|d^2 + |E|d))\), where \(d=max(d_I, d_H)\) (e.g., 64), which reduces to \(\mathcal {O}(|V|d^2 + |E|d)\), since m typically corresponds to few units. The role of the NN module is to transform the vector representations generated by the SGNN module into node-to-community assignment scores. This transformation can straightforwardly be achieved through a simple multi-layer perceptron neural network, whose computational cost is dominated by that of the SGNN module.

The time complexity of the rounding module is \(\mathcal {O}(|Z_{i}|(|V|+|E|))\), as for each potential threshold in \(Z_i\), the polarity of the rounded solution is computed in \(\mathcal {O}(|V|+|E|)\) time to select the optimal discrete solution. It is worth emphasizing that the cost of the rounding module constitutes the sole overhead introduced by us compared to the cost of existing SGNN and NN modules embedded into our approach. By combining the two aforementioned costs for \(e_{max}\) epochs, the overall time complexity of Neural2PC is \(\mathcal {O}(e_{max}((|Z_i|+d^2)|V|+(|Z_i|+d)|E|))\).

Regarding the space complexity of our method, Neural2PC requires \(\mathcal {O}(|V|)\) space to store intermediate variables \(\textbf{x}\) and \(\textbf{z}\) (lines 3-4 in Algorithm 1). This cost is to be considered as negligible compared to the space required to store intermediate node representations for all nodes, which is \(\mathcal {O}(|V|d_H)\) since we compute and store a vector of \(d_H\) components (cf. Equation (2)) for each node \(v \in V\). Moreover, the space complexity of our method also depends on the space complexity of the specific SGNN and NN modules, which in turn depends on the particular adopted models for such modules. However, the number of model parameters associated with SGNN and NN is known to be not directly affected by the size of the input graph, and for large graphs and typical network settings, the dominant term indeed corresponds to the cost of storing the node representations, i.e., \(\mathcal {O}(|V|d_H)\). Consequently, the overall space complexity of Neural2PC can be reasonably assumed to be \(\mathcal {O}(|V|d_H)\), attributed to the space required to store the node representations.

4 Balancing the size of the communities

A well-known issue of the polarity measure (Definition 1) is that it favors solutions with size-imbalanced output communities. It is not unlikely that this may even degenerate to solutions with one of the two communities overwhelming any other polarized formation, with the result of having the second community empty (Bonchi et al., 2019). Motivated by this, here we devise a generalization of the polarity measure, dubbed \(\gamma \)-polarity, which, by properly playing with its parameter \(\gamma \), yields polarized communities more balanced in size.

We define \(\gamma \)-polarity by properly modifying the denominator of the polarity measure, while keeping the numerator the same. Given a node-to-community assignment vector \(\textbf{x}\in \{-1, 0, 1\}^{|V|}\), let \(s_1 = \sum _{u \in V, \textbf{x}[u] < 0} |\textbf{x}[u]|\) and \(s_2 = \sum _{u \in V, \textbf{x}[u] > 0} \textbf{x}[u]\) be the size of the two communities, with \(s_{max} = \max \{s_1, s_2\}\), \(s_{min} = \min \{s_1, s_2\}\). The denominator of the polarity measure is equal to the sum of the sizes of the two communities, i.e., to \(\textbf{x}^\top \textbf{x}= s_{max} + s_{min}\). Noticing that \(\textbf{x}^\top \textbf{x}= (s_{max} - s_{min}) + 2~\!s_{min}\), the main intuition behind \(\gamma \)-polarity is to break \(\textbf{x}^\top \textbf{x}\) into such two terms \((s_{max} - s_{min})\) and \(2~\!s_{min}\), and weigh differently – i.e., by \(\gamma > 0\) – the \((s_{max} - s_{min})\) term corresponding to the difference in size between the two communities. This leads to the following formal definition of \(\gamma \)-polarity:

Definition 2

(\(\gamma \)-polarity) Given a vector \(\textbf{x}\in \{-1, 0, 1\}^{|V|}\), a matrix \(\textbf{A}\in \{-1, 0, 1\}^{|V| \times |V|}\), and a real number \(\gamma > 0\), the \(\gamma \)-polarity \(p_\gamma (\textbf{x}, A)\) of \(\textbf{x}\) with respect to \(\textbf{A}\) is defined as:

$$\begin{aligned} p_\gamma (\textbf{x}, \textbf{A}) = \frac{\textbf{x}^{\top } \! \textbf{A}~\textbf{x}}{(s_{max} - s_{min})~\!\gamma + 2~\!s_{min}}. \end{aligned}$$
(7)

Note that, if \(\gamma > 1\), the size-difference \((s_{max} - s_{min})\) term is amplified: thus, maximizing \(p_\gamma \) enforces such a term to be small, which corresponds to favoring size balance among communities. The opposite happens if \(\gamma \in (0, 1)\). Instead, \(\gamma = 1\) makes \(\gamma \)-polarity boil down to standard polarity.

The relaxed counterpart of \(\gamma \)-polarity, for a given continuous vector \(\textbf{z}\in [-1, 1]^{|V|}\) is defined by simply replacing \(\textbf{x}\) with \(\textbf{z}\) in Equation (7) (including in the computation of \(s_{max}\) and \(s_{min}\)). Relaxed \(\gamma \)-polarity can be incorporated in the proposed Neural2PC approach by simply replacing the polarity term \(p(\textbf{z}, \textbf{A})\) with a relaxed \(\gamma \)-polarity term \(p_\gamma (\textbf{z}, \textbf{A})\) in the \(\mathcal {L}_{\text {2PC}}\) loss function (Equation (5)).

Example 2

Consider the example graph in Figure 3, where positive edges are depicted by solid lines, while negative edges correspond to red dashed lines. Let \(P_1 = \lbrace \lbrace \texttt {A,B,C,D} \rbrace , \lbrace \texttt {E,F,G,H} \rbrace \rbrace \), \(P_2 = \lbrace \lbrace \texttt {A,B,C,D} \rbrace , \lbrace \texttt {E,F,G,H,I,J,K,L} \rbrace \rbrace \), and \(P_3 = \lbrace \emptyset , \lbrace \texttt {E,F,G,H,I,J,K,L} \rbrace \rbrace \) be three possible pairs of polarized communities.

The basic polarity (Definition 1) of \(P_1\), \(P_2\), and \(P_3\) is \((15 \times 2)/8=3.75\), \((22 \times 2)/12=3.67\), and \((15 \times 2)/8=3.75\), respectively. Despite, \(P_1\) and \(P_3\) both exhibit the highest polarity, \(P_1\) is much more size-balanced, thus intuitively preferable.

It is easy to see that using \(\gamma \)-polarity, with any \(\gamma >1\), instead of basic polarity allows for recognizing \(P_1\) as better than \(P_3\) (as \(P_1\) and \(P_3\) have the same \(\gamma \)-polarity numerator, while the \(\gamma \)-polarity denominator for \(P_3\) would be higher than the one for \(P_1\) for any \(\gamma >1\)).

Fig. 3
figure 3

Example signed graph where, unlike basic polarity, \(\gamma \)-polarity detects effective polarized communities that are also size-balanced (Example 2)

Detecting fine-grained polarization phenomena within signed networks is crucial, being essential to recognize minorities in polarization which might correspond to harmful situations like isolation, as illustrated in the following running example.

Example 3

Consider the example graph in Figure 4-(a), where positive edges are depicted by solid lines, and negative edges correspond to dashed lines. The scenario illustrated in the figure might be regarded as a case of isolation, wherein one node (\(\texttt {A}\)) has a majority of conflicting relations with a clique (i.e., \(\texttt {B, C, D, E}\)), and only few links with a lower number of nodes (i.e., \(\texttt {F,G}\)). Therefore, it is desirable to capture a polarization solution wherein the clique is regarded as one group while node \(\texttt {A}\) forms the other yet isolated group.

Existing methods fail to identify such a desired solution: indeed, given the inherent bias of the polarity objective towards outputs favoring communities with imbalanced sizes, both Eigen and R-Eigen yield \(\lbrace S_1, \emptyset \rbrace = \lbrace \lbrace \texttt {B, C, D, E, F, G} \rbrace , \emptyset \rbrace \). This also corresponds to an intermediate solution provided by our proposed method equipped with the \(\gamma -\)polarity objective (e.g., \(\gamma = 2.1\)) (cf. Figure 4-(b)), before finally producing the desired output \(\lbrace S_1, S_2 \rbrace = \lbrace \lbrace \texttt {B, C, D, E} \rbrace , \lbrace \texttt {A} \rbrace \rbrace \) at convergence (cf. Figure 4c).

Fig. 4
figure 4

Running example illustrating a scenario of node-isolation detection (Example 3)

5 Experimental methodology

Evaluation goals. We assessed accuracy of the proposed Neural2PC (Algorithm 1) and competitors/baselines on (1) real datasets, and (2) synthetic datasets; (3) impact of different signed GNNs when used as a module of Neural2PC; (4) runtimes of the considered methods; (5) effectiveness of the individual components of Neural2PC through an ablation study; (6) effectiveness of the \(\gamma \)-polarity measure in yielding communities that are both size-balanced and high-quality.

Real datasets. We selected publicly-available real-world signed graphs, whose characteristics are summarized in Table 2. Bitcoin and Epinions are the trust-distrust network of users of the Bitcoin OTC trading platform and the Epinions social network, respectively. Cloister contains the esteem/disesteem relations of monks living in a cloister in New England (USA). Congress reports (un/)favorable mentions of politicians speaking in the US Congress. HTribes describes the alliances/enemies relationships of a tribe in New Guinea. Slashdot is a friend-foe network collected from the Slashdot technology news site. TwitterRef collects the tweets about the Italian constitutional referendum in 2016, and edge signs express whether two users have the same stance or not. WikiCon contains positive/negative edit conflicts between the users of the English Wikipedia. WikiEle collects the positive/negative votes for electing admins in the English Wikipedia. WikiPol describes the signed interactions of users who have edited the English Wikipedia pages about politics.

Table 2 Main characteristics of real data used in our evaluation. \(E = E^+ \cup E^-\): overall edge set; density: \(|E|/(|V|(|V|-1)/2)\); deg\(^+\), deg\(^-\): avg of positive and negative node degrees, resp.; cc\(^+\), cc\(^-\): #connected components in the subgraph induced by \(E^+\) and \(E^-\), resp.; cc: overall #connected components
Table 3 Main characteristics of m-SSBM-generated network data used in our evaluation. \(E = E^+ \cup E^-\): overall edge set; density: \(|E|/(|V|(|V|-1)/2)\); deg\(^+\), deg\(^-\): avg of positive and negative node degrees, respectively

Synthetic datasets. We also employed synthetic signed graphs in order to test the methods in recovering ground-truth polarized communities. We used modified signed stochastic block model (m-SSBM) (Tzeng et al. 2020) as a generator. This model has three parameters, namely the total number n of nodes, the size \(n_c = |S_1| = |S_2|\) of a planted polarized community (all have the same size) and a parameter \(\eta \in [0, 1]\) to control edge probabilities: (i) an edge in the same group (resp. between two polarized groups) is drawn as positive (resp. as negative), with probability \(1-\eta \), as negative (resp. as positive), with probability \(\eta /2\), and is not drawn with probability \(\eta / 2\); (ii) all other edges have equal probability of \(\min (\eta , 1/2)\) of being positive or negative. Note that the smaller \(\eta \), the lower the noise level. The case with no noise \((\eta = 0)\) corresponds to the “perfect” structure (i.e., all nodes are disconnected except those linked within or across polarized communities), while the polarized communities only emerge when \(\eta \le 2/3\), since for \(\eta > 2/3\) the generated graph has more negative edges in the groups and more positive edges between the groups.

We considered different synthetic graphs by varying number of nodes (n), community size \(n_c\), and \(\eta \in \lbrace 0, 0.1, 0.2, 0.3, 0.4, 0.5, 0.6 \rbrace \). For each configuration, we generated 10 different graphs. Table 3 summarizes main characteristics (average statistics) of the generated network data.

Competing methods. We compare our Neural2PC (Algorithm 1) to the state-of-the-art methods for discovering polarized communities, as well as against non-trivial baselines inspired by methods devised for different yet related problems.

We consider both the methods originally conceived by Bonchi et al. (2019), namely Eigen and its randomized R-Eigen counterpart, as our direct competing methods, since they target the same optimization problem (2pc) we tackle in this work.

Like (Bonchi et al., 2019), we include Pivot too, a baseline inspired by a correlation clustering algorithm (Bansal et al., 2004). For each node \(u \in V\), Pivot identifies u and the nodes sharing a positive edge with u as one cluster, and the nodes sharing a negative edge as the other cluster. From the |V| possible solutions, it returns the one maximizing polarity. We also consider Greedy (Bonchi et al., 2019), a method inspired by a 2-approximation algorithm for densest subgraph (Charikar, 2003). It iteratively removes nodes to maximize the difference between positive and negative adjacent edges until the graph is empty. At the end, it returns the subgraph having the highest polarity among all produced subgraphs. Node-to-cluster assignment is guided by the sign of the components of the eigenvector corresponding to the largest eigenvalue of \(\textbf{A}\).

Furthermore, we consider signed graph clustering algorithms BNC (Chiang et al., 2012), SPONGE (Cucuringu et al., 2019) and SSSNet (He et al., 2022). Since they all require the number k of output clusters (communities), we denote them with BNC(k), SPONGE(k) and SSSNet(k), respectively. As previously done by Tzeng et al. (2020), we consider two variants of these competitors. The first one consists in setting \(k=2\) and return the 2 detected clusters as polarized communities. The second variant sets \(k = 3\), and it treats the largest of the 3 detected clusters as the group of neutral nodes, and return the 2 smallest clusters as polarized communities.

Experimental setting. We instantiate the sgnn(\(\cdot \)) block of our Neural2PC framework with well-established signed GNNs, namely SGCN (Derr et al., 2018), SNEA (Li et al., 2020), SGDNET (Liu et al., 2021). As for SGCN, we consider different variants by varying the neighbor aggregation operator in \(\lbrace \text {mean}, \text {sum}, \text {attention} \rbrace \). We denote such variants SGCNmean, SGCNsum and SGCNatt, respectively. Also, for any considered signed GNN, we add the “-DR” suffix if the proposed loss regularization term is used (Equation (5)). The absence of such a suffix means that \(\lambda \) was set to 0.

All signed GNN models, implemented using PyTorch Geometric and trained on CPUs, share uniform settings with a node representation dimensionality \(d_H\) of 64, number of layers m as 2, and default values for other parameters. Concerning SGDNET, we set the number of latent groups to 3. Since no initial node-features are available for the selected signed graphs, following previous works (Derr et al., 2018) we used the final embedding of a signed spectral embedding model (Kunegis et al., 2010) as the input feature matrix, with \(d_I=64\). For each configuration of our method and SSSNet, model training was carried out by the Adam optimizer, for \(e_{max} = 300\) epochs and by grid searching the \(\alpha \) learning rate from \(\lbrace 0.01, 0.005, 0.001 \rbrace \) and the \(\lambda \) regularization factor from \(\lbrace 0.1, 0.01, 0.001 \rbrace \). All reported measurements correspond to averages over 30 runs. Details about the execution environment can be found in the Appendix.

6 Results

Neural2PC vs. competitors, real datasets. Table 4 reports the values of polarity (Definition 1) achieved by all compared algorithms on all datasets, and the size of the produced two communities. Concerning our Neural2PC, we only report the results obtained by the best-performing (in terms of polarity) graph representation learning method. As for the graph clustering methods (i.e., SPONGE(k), BNC(k) and SSSNet(k)), we also report the number of desired communities \(k \in \lbrace 2, 3 \rbrace \) which led to the best results in terms of polarity.

As a first remark, our Neural2PC generally reveals to be the most competitive method in terms of polarity. Note that the exceptions of Slashdot, WikiEle and WikiPol datasets (where Greedy precedes Neural2PC) correspond, however, to a very dense subgraph returned by Greedy as one of the two polarized communities, leaving the second community totally empty, which is clearly undesired in practice. Conversely, our method is able to return both non-empty communities with high polarity in WikiEle and WikiPol.

Table 4 Polarity (Def. 1) and solution size (\(|S_1|;|S_2|\)) of the proposed Neural2PC method vs. competing methods on real datasets. Best results in bold, second-best underlined
Table 5 Edge-agreement ratio of the proposed Neural2PC method vs. competing methods on real datasets
Table 6 Performance of the proposed Neural2PC vs. competing methods on synthetic datasets, in terms of \(F_1\)-score and polarity (Def. 1) as a function of the noise parameter \(\eta \)
Table 7 Performance of the proposed Neural2PC on synthetic datasets with varying number of nodes n and community sizes \(n_c\), in terms of \(F_1\)-score, polarity (Def. 1) and running time (in seconds) as a function of the noise parameter \(\eta \)

Among our competitors, Eigen and R-Eigen, who also address the 2pc problem, both achieve strong polarity results. Eigen outperforms R-Eigen, and on the smallest datasets, Congress and HTribes, our method matches Eigen ’s solutions regardless of the adopted GNN model. In general, however, our method performs better than Eigen and R-Eigen.

Pivot overall performs poorly in terms of polarity. This can be explained since, in identifying polarized groups by exploring local neighborhoods, its search space strongly depends on the neighborhood structure of the nodes. Also, its detected communities tend to be located around high-degree nodes but, in general, the pair of communities with the highest polarity do not necessarily lie around the high-degree nodes.

Concerning the BNC and SPONGE methods, when \(k=2\), as expected, they perform poorly since all neutral nodes are put in one of the two detected communities, resulting in solutions with low polarity. In fact, the two methods often yield solutions where one community is a large group likely including all neutral nodes, and the other community consists of few nodes. Conversely, when \(k=3\), even if the methods can use the spare cluster to put the neutral nodes, they both perform worse than the case \(k=2\) yielding solutions that are of extremely small size. The same consideration holds for the SSSNet method, although to a less extent, as it performs better then SPONGE and BNC. In any case, the three selected clustering methods are consistently outperformed by our method.

We complement our evaluation by analyzing the edge-agreement ratio which measures the portion of edges in the solution that comply with the polarized structure, i.e., the number of intra-community positive edges inside \(S_1\) and \(S_2\) plus the number of inter-community negative edges, divided by all the edges in the subgraph induced by \(S_1 \cup S_2\). Table 5 reports the edge-agreement ratio corresponding to the best-polarity solutions (cf. Table 4). Overall, the edge-agreement ratio is consistently close or equal to 1, especially for Neural2PC and Eigen, with an average edge-agreement ratio across all datasets of 0.97 and 0.96, respectively. The remaining methods follow a similar, although weaker, trend: this means that the solutions have a coherent polarized structure.

Neural2PC vs. competitors, on synthetic datasets. Table 6 shows the \(F_1\)-scores and corresponding polarity scores averaged over the 10 synthetic graphs that were generated for each configuration, by varying the noise parameter \(\eta \) while keeping fixed the network size (\(n=1000\)) and the number of communities (\(n_c=100\)). For our method, we only report the results corresponding to the best-performing (in terms of \(F_1\)-score) signed GNN model, which was SGDNET for all the datasets and noise levels.

From the table, it is evident that our Neural2PC is very robust in handling an increasing noise level, as it mostly outperforms all competitors both in terms of \(F_1\)-score and polarity. The only exception arises for \(\eta = 0.6\), where BNC(2) yields a slightly higher \(F_1\)-score than Neural2PC, but the polarity of the solution yielded by BNC(2) is \(36\times \) times lower, thus resulting in a low-quality solution – recall that the m-SSBM model generates very noisy graphs for mid-high values of \(\eta \), where the ground-truth communities are “hidden” by the graph topology since there are many intra-community negative edges and many inter-community positive edges. In such cases, a higher polarity is a more reliable indicator for the quality of the discovered solutions: indeed, it holds that the polarity score is consistent with the \(F_1\)-score, i.e., high values for the polarity mostly correspond to high \(F_1\)-scores.

In addition, as shown in Table 7, our Neural2PC keeps a similar behavior and is still robust w.r.t. \(\eta \) for varying numbers of nodes and community sizes (cf. Table 3); again, results correspond to averages over 10 synthetic networks, and the group of results in the second last row coincide with those for Neural2PC reported in Table 6. Note that, according to the definition of m-SSBM and its edge-formation rules based on \(\eta \), it should not come to our surprise how the impact of \(\eta \) in terms of polarity decrease-rate tends to be higher on larger m-SSBM synthetic networks, given the increased amount of noise introduced by \(\eta \).

Impact of different signed GNNs on Neural2PC. We analyzed polarity and community size values corresponding to all the variants of our Neural2PC method based on different signed GNN models (results are shown in the Appendix).

Our experiments revealed that the polarity of the solutions provided by Neural2PC does not significantly change across the various GNNs, which indicates robustness of our approach in terms of one of its main components.

Fig. 5
figure 5

Execution times (in seconds) of the proposed Neural2PC method vs. competing methods on real-world network datasets

Execution times. Figure 5 shows the average time performance of the methods, over the various runs; in the Appendix, Table 17 reports detailed information, particularly for Neural2PC we show details about the total running time and, in brackets, the time discarding the rounding steps (i.e., by discarding the cumulative time spent in executing the step at Line 4 of Algorithm 1 over all the epochs).

As expected, the learning-based methods, i.e., SSSNet and our Neural2PC, exhibit the highest running times, which is clearly affected by their number of epochs (\(e_{max} = 300\)). Importantly, we remark that the reported running times of the Neural2PC method refer to its execution on a single CPU, without any parallelization. However, Neural2PC, like any neural-network method, can easily benefit from dedicated hardware (e.g., GPUs) and parallelization, which can drastically improve its execution time. Also, note that the time per epoch of Neural2PC is comparable to the runtime of the fastest method(s).

Among the other methods, SPONGE performs the best, followed by BNC and Eigen. R-Eigen is slightly worse than Eigen due to its randomized nature involving sampling. Among the non-learning-based methods, Pivot and Greedy are inefficient since they extract and evaluate |V| solutions.

In addition, remarks about scalability of Neural2PC can be drawn by looking at the results on synthetic networks shown in Table 7: for any given value of \(\eta \), the runtime of Neural2PC increases linearly with the size of the network, which is in accord with our previously discussed analysis of computation aspects.

Ablation study. To assess the effect of the main components of our Neural2PC framework, we focused an ablation study on the following simplifications of Neural2PC: (i) NN, which discards the sgnn\((\cdot )\) block, hence it is composed of the nn\((\cdot )\) block only, and (ii) Direct, which performs a direct optimization of the continuous \(\textbf{z}\) node-to-community assignments by minimizing the \(\mathcal {L}_{\text {2PC}}\) loss function (Equation 5) via projected gradient descent, i.e., at every step, gradient descent along with projection of the assignment variables onto the range \([-1, 1]\).

Table 8 Ablation study results for the proposed Neural2PC method

Results of the ablation study are shown in Table 8, in terms of polarity, size of the solution and total execution time. The full Neural2PC is confirmed to be necessary to achieve the best polarity on all datasets, or at least comparable with Direct (TwitterRef and WikiEle); the latter, however, is less efficient than Neural2PC, especially on larger datasets. This can be explained by the fact that the sgnn\((\cdot )\) module in Neural2PC helps produce more similar continuous scores for nodes that are assigned to the same community after rounding. That is, the rounding step of Neural2PC has to test less thresholds than Direct, hence it takes less time. Also, concerning the size of the communities, both Neural2PC and Direct yield solutions that involve more nodes than NN.

The above results are complemented by an analysis of the trends of polarity achieved by Neural2PC and its simplifications, by varying the number of training epochs (up to \(e_{max} = 300\)); results are shown in the Appendix. This analysis revealed that the Direct variant often requires more epochs (on average, at least double) than Neural2PC and NN to reach the maximum polarity.

Overall, the outcomes of this ablation study justify the need for all components of the proposed Neural2PC framework.

\(\gamma\)-polarity results. In this experimental stage, we aim to delve into the impact of the value of \(\gamma \) to the size as well as the quality of the solutions provided by Neural2PC equipped with the \(\gamma \)-polarity loss function. Given \(\gamma \), let \(\textbf{x}_\gamma \) be the solution obtained by optimizing the \(\gamma \)-polarity, e.g., \(\textbf{x}_1\) corresponds to the solutions obtained by optimizing the \(\mathcal {L}_{\text {2PC}}\) loss. We are interested in evaluating the quality of the \(\textbf{x}_\gamma \) solutions for different values of \(\gamma \) both in terms of \(\gamma \)-polarity (i.e., the same value for \(\gamma \) used for the training process) as well as in terms of the standard polarity, i.e., 1-polarity. Also, we aim to analyze the \(\gamma \)-polarity of the \(\textbf{x}_1\) solutions as well as the size of the discovered polarized communities by varying \(\gamma \). We selected several values of \(\gamma \) spanning a relatively large interval above 1 (up to 20); for each of such values, say n, we also considered the reciprocal of n, in order to explore a comparable range of values below 1; for instance, the dual of \(\gamma =1.5\) is \(\gamma =0.66\). We conducted this experiment on 5 datasets but, for the sake of simplicity, we only show a subset of these results for Congress (cf. Table 9) and Slashdot (cf. Table 10): details about these experiments and on other datasets can be found in Appendix. Concerning our Neural2PC and the competing methods, we report the results obtained by the best-performing (in terms of \(\gamma \)-polarity) method.

Table 9 \(\gamma \)-polarity scores of the proposed Neural2PC method vs. its best-performing competing method, on Congress dataset
Table 10 \(\gamma \)-polarity scores of the proposed Neural2PC method vs. its best-performing competing method, on Slashdot dataset

Looking at the tables, several remarks stand out. First, Neural2PC results to be the most competitive method in terms of \(\gamma \)-polarity on Congress for any \(\gamma \); this holds only after a certain value for \(\gamma \) (i.e., 1.5) on Slashdot. Second, as expected, the \(\gamma \)-polarity of the solutions produced by the competing methods (as well as by Neural2PC trained with the 1-polarity, i.e., \(p_\gamma (\textbf{x}_1)\)) monotonically decreases as \(\gamma \) increases. This is due since, as \(\gamma \) increases, the denominator of \(\gamma \)-polarity increases. On the other hand, the values for \(p_\gamma (\textbf{x}_\gamma )\) have a decreasing trend as \(\gamma \) increases, but not monotonic.

As for solution size, the two discovered polarized communities yielded by Neural2PC tend to become more balanced (resp. unbalanced) for higher (resp. lower) values of \(\gamma \) until, after a certain value threshold value, the two communities have the same size (resp., one community is empty). On the contrary, the solutions provided by the competing methods are highly unbalanced in size, especially on Slashdot where one of the two detected community is empty.

More interestingly, controlling the balance between the size of the discovered communities is also beneficial in terms of 1-polarity. In particular, this happens on Congress, where favoring polarized communities more balanced in size (i.e., by setting \(\gamma > 1\)) leads to the best solutions in terms of 1-polarity, i.e., \(p_{1}(\textbf{x}_{4.0}) = 6.67 > 6.64 = p_{1}(\textbf{x}_{1}) \) (cf. Table 9).

Fig. 6
figure 6

Solutions yielded by Neural2PC by optimizing \(\gamma \)-polarity (Def. 2), for different values of \(\gamma \), on the Congress dataset

Figure 6 complements the above results by providing insights into the structural properties of the detected polarized communities by Neural2PC (equipped with the SGCNmean GNN) on the Congress dataset. Specifically, for \(\gamma = 0.1\), one community is empty and the other has 31 nodes with 81 inter-community positive edges and no negative edges. With \(\gamma = 0.66\), the empty community becomes a singleton (i.e., one node), and the second has 36 nodes with 93 intra-community positive edges and 11 inter-community negative edges (1 positive edge). For \(\gamma = 1\), there are two communities with 32 and 23 nodes, with 83 (resp. 52) internal positive edges, and they are connected by 50 negative and 3 positive edges. Optimizing for 4-polarity results in two communities with 24 nodes each, featuring 57 and 58 intra-community positive edges, connected by 46 negative and 1 positive edge.

Overall, our experiments revealed the practical benefit of \(\gamma \)-polarity since we can inspect the communities obtained for different \(\gamma \) values and keep the ones that best suit our purposes.

7 Conclusion

Summary. In this paper, we advanced the state of the art in 2pc, a well-established combinatorial-optimization problem which aims to discover two polarized communities from a signed graph, through maximization of the so-called polarity function. We provided a twofold contribution: (i) a novel neural-network-based approach to 2pc, and (ii) a generalization of the polarity function, \(\gamma \)-polarity, which we suitably incorporate into the proposed neural framework. Notably, we addressed two key limitations in the state of the art in 2pc: relying on a single relaxed solution for producing the ultimate discrete solution, and mitigating size-unbalanced output communities.

Our experimental evaluation, which was conducted on 10 real-world signed networks and synthetically generated signed networks has provided empirical evidence of the meaningfulness and relevance of our Neural2PC versus all competing methods for discovering polarized groups. In particular, (i) Neural2PC outperforms all competitors in terms of polarity value as well as coherent polarized structure and ability to produce non-empty groups; (ii) using the \(\gamma \)-polarity loss enables flexibility of our Neural2PC, which is useful to effectively control the balance of the sizes of the discovered polarized groups; (iii) all components of Neural2PC are justified to lead it to achieve the best polarity performance, and (iv) this appears to be relatively robust w.r.t. different signed GNN models constituting its SGNN component; (v) the runtime of Neural2PC scales linearly with the size of the network.

Future works. We believe that a number of further developments are worthy of investigation. First, we aim to address two main limitations of our framework, namely the number of polarized groups that can be detected, and the separation of the rounding block from the neural-network components. Addressing the former would be key-enabling for extended polarization scenarios, such as on multi-party political networks. To this purpose, major interventions would be to revise our approach to integrate the extension of the 2pc task to a \(k>2\) polarization setting (Tzeng et al., 2020), and to refine the (\(\gamma \)-)polarity loss and the computation of the continuous node-to-community assignment solutions. The latter limitation would be overcome by integrating the rounding block into the neural architecture: this way, by learning the rounding of the continuous solution, the repeated trials of rounding thresholds \(\tau \) could be avoided, thus also overcoming a limitation of the early approximation algorithms for 2pc. Further interesting research paths include to devise a custom GNN model for the 2pc task, and to delve into the \(\gamma \)-polarity function from a combinatorial-optimization perspective.