I have been using graph-tool to create hierarchical topic models with excellent results using a hierarchical stochastic block model (hSBM). The approach is described here: https://github.com/martingerlach/hSBM_Topicmodel
The library creates a bipartite graph with two kinds of nodes: words and documents.
While the approach yields clear topics, I would like to change the bipartite visualisation that the hSBM produces by default, to a circular graph layout using only the word groups.
My question is if it is possible to visualise the bipartite structure in a single circular graph?
All the edges exist between documents and words, and corresponding topics/groups. However, the circular graph should only contain the words and word groups (or blocks), not the document groups, which is where the problem is. I have tried two approaches:
Creating a dummy anchor vertex that all the words connect to, instead of the documents. Something like:
#create anchor and add edges to words anchor = model.g.add_vertex() for v in model.g.iter_vertices(): if model.g.vp['kind'][v] == 1: model.g.add_edge(v, anchor) # delete document vertices del_list = [v for v in model.g.vertices() if model.g.vp['kind'][v] == 0] for v in reversed(sorted(del_list)): model.g.remove_vertex(v)
Creating edges between all word neighbours and then filtering the word-doc edges as described here. Something like:
from itertools import combinations for v, bipartite_label in enumerate(model.g.vp['kind']): if bipartite_label == 1: neighbours = list(model.g.vertex(v).all_neighbours()) for s, t in combinations(neighbours, 2): model.g.add_edge(s, t) g_projected = gt.Graph(gt.GraphView(model.g, vfilt=model.g.vp.kind.a == 0), prune=True)
So far I have not succeeded and I can't visualise the graph. Either my attempts above are not right or it may be that it is impossible to change the graph without retraining the block model on the new graph.
Any help or guidance would be greatly appreciated as I am new to using this library.