albertvillanova HF staff commited on
Commit
d80f88a
1 Parent(s): b4a856f

Delete loading script auxiliary file

Browse files
Files changed (1) hide show
  1. create_dummy_data.py +0 -96
create_dummy_data.py DELETED
@@ -1,96 +0,0 @@
1
- import gzip
2
- import json
3
- import logging
4
- import os
5
- from argparse import ArgumentParser
6
-
7
-
8
- parser = ArgumentParser()
9
- parser.add_argument(
10
- "-d",
11
- "--data_path",
12
- type=str,
13
- required=True,
14
- help="Data path containing the CompGuessWhat?! datasets (files with 'jsonl.gz' extension)",
15
- )
16
- parser.add_argument(
17
- "--examples",
18
- type=int,
19
- default=5,
20
- help="Number of games to consider in the dummy dataset",
21
- )
22
- original_data_files = {
23
- "train": "compguesswhat.train.jsonl.gz",
24
- "valid": "compguesswhat.valid.jsonl.gz",
25
- "test": "compguesswhat.test.jsonl.gz",
26
- }
27
-
28
- zs_data_files = {
29
- "nd_valid": "compguesswhat.nd_valid.jsonl.gz",
30
- "od_valid": "compguesswhat.od_valid.jsonl.gz",
31
- "nd_test": "compguesswhat.nd_test.jsonl.gz",
32
- "od_test": "compguesswhat.od_test.jsonl.gz",
33
- }
34
-
35
- COMPGUESSWHAT_ROOT = "datasets/compguesswhat/"
36
-
37
-
38
- def create_dummy_data_for_split(data_path, dataset_name, dataset_version, data_files):
39
- full_dataset_name = "-".join(["compguesswhat", dataset_name])
40
- dummy_data_path = os.path.join(
41
- COMPGUESSWHAT_ROOT,
42
- "dummy",
43
- full_dataset_name,
44
- dataset_version,
45
- "dummy_data",
46
- full_dataset_name,
47
- dataset_version,
48
- )
49
-
50
- if not os.path.exists(dummy_data_path):
51
- os.makedirs(dummy_data_path)
52
-
53
- for split_name, split_file in data_files.items():
54
- logging.info(f"Generating dummy data for split {split_name} (num. examples = {args.examples})")
55
-
56
- split_filepath = os.path.join(data_path, full_dataset_name, dataset_version, split_file)
57
- logging.info(f"Reading split file {split_filepath}")
58
- with gzip.open(split_filepath) as in_file:
59
- dummy_filepath = os.path.join(dummy_data_path, split_file)
60
- with gzip.open(dummy_filepath, mode="w") as out_file:
61
- for i, line in enumerate(in_file):
62
- if i > args.examples:
63
- break
64
-
65
- data = json.loads(line.strip())
66
- out_file.write(json.dumps(data).encode("utf-8"))
67
- out_file.write(b"\n")
68
-
69
-
70
- def main(args):
71
- # args.data_path is the directory containing the already downloaded dataset files
72
- # we assume that the dataset test was successful and we have the file dataset_info.json
73
- dataset_info_path = os.path.join(COMPGUESSWHAT_ROOT, "dataset_infos.json")
74
-
75
- if not os.path.exists(dataset_info_path):
76
- raise ValueError(
77
- "The file 'dataset_info.json' doesn't exists. Make sure that you run the dataset tests via datasets-cli."
78
- )
79
-
80
- with open(dataset_info_path, encoding="utf-8") as in_file:
81
- dataset_info = json.load(in_file)
82
-
83
- dataset_version = dataset_info["compguesswhat-original"]["version"]["version_str"]
84
-
85
- logging.info(f"Creating dummy data for CompGuessWhat?! {dataset_version}")
86
-
87
- logging.info("Original dataset...")
88
- create_dummy_data_for_split(args.data_path, "original", dataset_version, original_data_files)
89
-
90
- logging.info("Zero-shot dataset...")
91
- create_dummy_data_for_split(args.data_path, "zero_shot", dataset_version, zs_data_files)
92
-
93
-
94
- if __name__ == "__main__":
95
- args = parser.parse_args()
96
- main(args)