-def subsets_as_tuples(batches, cs):
- s = set()
- for batch in batches:
- for x in batch:
- s.add(tuple([v.item() for v in x]))
- if len(s) == cs:
- yield s
- s = set()
- yield s
-
-
-nb_test, nb_in_train = 0, 0
-for test_subset in subsets_as_tuples(task.batches(split="test"), 25000):
- in_train = set()
- for train_subset in subsets_as_tuples(task.batches(split="train"), 25000):
- in_train.update(test_subset.intersection(train_subset))
- nb_in_train += len(in_train)
- nb_test += len(test_subset)
-
-log_string(
- f"data_check {nb_in_train*100/nb_test:.02f}% ({nb_in_train}/{nb_test}) of test samples are in the train set"
-)
-
-assert (
- nb_in_train <= args.max_percents_of_test_in_train * nb_test / 100
-), f"More than {args.max_percents_of_test_in_train}% of test samples are in the train set"
+ assert (
+ nb_in_train <= args.max_percents_of_test_in_train * nb_test / 100
+ ), f"More than {args.max_percents_of_test_in_train}% of test samples are in the train set"