Skip to content

Commit

Permalink
Merge pull request #1879 from Marlon154/master
Browse files Browse the repository at this point in the history
Add a progress bar for community detection
  • Loading branch information
tomaarsen authored Dec 12, 2023
2 parents 4f75460 + a8ae010 commit b93aac1
Showing 1 changed file with 2 additions and 2 deletions.
4 changes: 2 additions & 2 deletions sentence_transformers/util.py
Original file line number Diff line number Diff line change
Expand Up @@ -348,7 +348,7 @@ def import_from_string(dotted_path):
raise ImportError(msg)


def community_detection(embeddings, threshold=0.75, min_community_size=10, batch_size=1024):
def community_detection(embeddings, threshold=0.75, min_community_size=10, batch_size=1024, show_progress_bar=False):
"""
Function for Fast Community Detection
Finds in the embeddings all communities, i.e. embeddings that are close (closer than threshold).
Expand All @@ -366,7 +366,7 @@ def community_detection(embeddings, threshold=0.75, min_community_size=10, batch
min_community_size = min(min_community_size, len(embeddings))
sort_max_size = min(max(2 * min_community_size, 50), len(embeddings))

for start_idx in range(0, len(embeddings), batch_size):
for start_idx in tqdm(range(0, len(embeddings), batch_size), desc="Finding clusters", disable=not show_progress_bar):
# Compute cosine similarity scores
cos_scores = cos_sim(embeddings[start_idx:start_idx + batch_size], embeddings)

Expand Down

0 comments on commit b93aac1

Please sign in to comment.