Skip to content

Commit

Permalink
[model cards] Prevent crash on generating widgets if dataset column…
Browse files Browse the repository at this point in the history
… is empty (#2997)

(or if it has no string columns)
  • Loading branch information
tomaarsen authored Oct 18, 2024
1 parent 5e1a7a4 commit 0e59af6
Showing 1 changed file with 3 additions and 0 deletions.
3 changes: 3 additions & 0 deletions sentence_transformers/model_card.py
Original file line number Diff line number Diff line change
Expand Up @@ -429,6 +429,9 @@ def set_widget_examples(self, dataset: Dataset | DatasetDict) -> None:
]
str_dataset = dataset[dataset_name].select_columns(columns)
dataset_size = len(str_dataset)
if dataset_size == 0:
continue

lengths = {}
for idx, sample in enumerate(
str_dataset.select(random.sample(range(dataset_size), k=min(num_samples_to_check, dataset_size)))
Expand Down

0 comments on commit 0e59af6

Please sign in to comment.