Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 13 additions & 0 deletions mteb/abstasks/clustering.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import itertools
import logging
import os
import random
from collections import defaultdict
from pathlib import Path
Expand Down Expand Up @@ -31,6 +32,7 @@


MultilingualDataset = dict[HFSubset, DatasetDict]
OMP_NUM_THREADS = 4


def _evaluate_clustering_bootstrapped(
Expand All @@ -53,6 +55,17 @@ def _evaluate_clustering_bootstrapped(
- A dictionary where keys are level names (e.g., "Level 0", "Level 1", etc.) and values are lists of V-measure scores for each clustering experiment at that level.
- A dictionary where keys are level names and values are lists of cluster assignments for each clustering experiment at that level.
"""
# set OMP_NUM_THREADS for reproductibility
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can we add a sentence to describe how this ensures reproducibility please?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah, but I am not really sure - it was just the only thing that I expected would vary across CI, @Samoed, and my implementation. However, given that the tests are flaky, it is really hard to tell if it actually ensure anything.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I will merge this for now, just to see if it resolves some of the flakiness - if it does not, I will roll it back.

if "OMP_NUM_THREADS" not in os.environ:
logger.info(
f"Setting OMP_NUM_THREADS to {OMP_NUM_THREADS} for clustering to ensure reproducibility."
)
os.environ["OMP_NUM_THREADS"] = str(OMP_NUM_THREADS)
else:
logger.info(
f"Using existing OMP_NUM_THREADS={os.environ['OMP_NUM_THREADS']} for clustering, this may lead to non-reproducible results. Set it to {OMP_NUM_THREADS} to ensure reproducibility."
)

v_measures = defaultdict(list)
cluster_assignments = defaultdict(list)
if max_depth is not None:
Expand Down