GirvanNewmanClustering¶
Overview¶
The GirvanNewmanClustering
class is designed to detect communities in a graph using the Girvan-Newman algorithm. It extends the GraphClustering
class.
Arguments¶
text
(str): The input text containing sentences to be clustered.resolution
(float): The resolution parameter for the Girvan-Newman algorithm.threshold
(float): The similarity threshold for connecting nodes in the graph.
Example Usage¶
Here's an example demonstrating how to use the GirvanNewmanClustering
class:
from euler.clustering import GirvanNewmanClustering
text = """
Your text data here
"""
clustering = GirvanNewmanClustering(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 Girvan-Newman algorithm.
get_clusters
¶
Returns the clusters detected in the graph as a dictionary.