Datasets:

Modalities:
Text
Languages:
English
Libraries:
Datasets
License:
albertvillanova HF staff commited on
Commit
28f9970
1 Parent(s): 18f251f

Optimize code to perform less calls to filesystem

Browse files
Files changed (1) hide show
  1. twadrl.py +13 -18
twadrl.py CHANGED
@@ -108,24 +108,19 @@ class TwADRL(datasets.GeneratorBasedBuilder):
108
  dl_dir = dl_manager.download_and_extract(_URLs)
109
  dataset_dir = os.path.join(dl_dir, "datasets", "TwADR-L")
110
  # dataset supports k-folds
111
- splits = []
112
- for split_name in [
113
- datasets.Split.TRAIN,
114
- datasets.Split.VALIDATION,
115
- datasets.Split.TEST,
116
- ]:
117
- for fold_filepath in glob.glob(
118
- os.path.join(dataset_dir, f"TwADR-L.fold-*.{split_name}.txt")
119
- ):
120
- fold_id = re.search("TwADR-L\.fold-(\d)\.", fold_filepath).group(1)
121
- split_id = f"{split_name}_{fold_id}"
122
- splits.append(
123
- datasets.SplitGenerator(
124
- name=split_id,
125
- gen_kwargs={"filepath": fold_filepath, "split_id": split_id},
126
- )
127
- )
128
- return splits
129
 
130
  def _generate_examples(self, filepath, split_id):
131
  with open(filepath, "r", encoding="latin-1") as f:
 
108
  dl_dir = dl_manager.download_and_extract(_URLs)
109
  dataset_dir = os.path.join(dl_dir, "datasets", "TwADR-L")
110
  # dataset supports k-folds
111
+ splits_names = ["train", "validation", "test"]
112
+ fold_ids = range(10)
113
+ return [
114
+ datasets.SplitGenerator(
115
+ name=f"{split_name}_{fold_id}",
116
+ gen_kwargs={
117
+ "filepath": os.path.join(dataset_dir, f"TwADR-L.fold-{fold_id}.{split_name}.txt"),
118
+ "split_id": f"{split_name}_{fold_id}",
119
+ },
120
+ )
121
+ for split_name in splits_names
122
+ for fold_id in fold_ids
123
+ ]
 
 
 
 
 
124
 
125
  def _generate_examples(self, filepath, split_id):
126
  with open(filepath, "r", encoding="latin-1") as f: