Skip to content

LouvainCluster

Overview

The LouvainCluster class is designed to detect communities in a graph using the Louvain algorithm. It extends the GraphClustering class.

Arguments

  • text (str): The input text containing sentences to be clustered.
  • resolution (float): The resolution parameter for the Louvain algorithm.
  • threshold (float): The similarity threshold for connecting nodes in the graph.

Example Usage

Here's an example demonstrating how to use the LouvainCluster class:

from euler.clustering import LouvainCluster

text = """
Your text data here
"""
clustering = LouvainCluster(text, resolution=1.0, threshold=0.5)
clusters = clustering.get_clusters()
print(clusters)

Functions

encode_sentences

Encodes sentences into embeddings using BERT.

build_graph

Builds the graph using sentence embeddings and cosine similarity.

detect_communities

Detects communities in the graph using the Louvain algorithm.

get_clusters

Returns the clusters detected in the graph as a dictionary.