Suppose that I have a graph that has components like the image below.

A graph with several components

Graph nodes contain text data (titles) and the edges data is the similarity (percentage). I know that each component represents a cluster, but my question is how to cluster these components.

A graph component may have these data for their nodes (titles).

  • How to make pizza
  • How to make pepperoni pizza
  • Recipe for cooking pizza
  • ingredients needed for Italian pizzas

And I have one other graph component with these titles.

  • Kebab restaurants
  • Homemade Kebab
  • How is kebab cooked?

I know that these two graph components with the title mentioned are clusters individually. My question is how can I cluster these two graph components since they both may have the same topic (cooking, food, etc)?

Things I have looked into or think can be the solution:

  • There is a library called BERTopic that clusters records of text but in my problem, I already know that certain records form a cluster. I want to cluster these text clusters (graph components)
  • Maybe there is a way to form a representation using transformers or word vectorization for a graph component, and based on that representation vector and some distance metric we can cluster the components but the question is if this solution is plausible what is the best way to implement it?
  • GNN (Graph Neural Networks) is usually used for node classification or edge prediction (Functionalities that I am aware of). Can they be used for clustering graph components which do not contain connections to each other?

2 Answers 2


It seems to me that you're trying to use different methods at the same time: if your graph already contains a similarity value on the edges, then it would be redundant to use some form of topic modelling or text similarity again.

In my opinion, you either:

  • you assume that the text similarity values are reliable and exploit them. This is the simplest option, all you need is a generic graph clustering algorithm or a distance-based clustering algorithm.
  • you want to redo the processing of the text: in this case you might as well as restart from the set of titles, i.e. ignore the current graph. This leaves you with many options for topic modelling methods, from which the clusters can be derived.

You can start with spectral clustering. Spectral clustering finds clusters based on similarity scores between graph nodes.


Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.