Skip to content

Commit

Permalink
Prevent crash on generating widgets if dataset column is empty
Browse files Browse the repository at this point in the history
(or if it has no string columns)
  • Loading branch information
tomaarsen committed Oct 18, 2024
1 parent 1802076 commit 40b58b9
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 @@ -427,6 +427,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 40b58b9

Please sign in to comment.