Datasets:
:reliability of download
Browse files- prepare_for_release.py +26 -24
- requirements.txt +1 -1
prepare_for_release.py
CHANGED
@@ -9,19 +9,18 @@ import json
|
|
9 |
from contextlib import ExitStack
|
10 |
from functools import partial
|
11 |
from multiprocessing import Manager, Pool, cpu_count, set_start_method
|
|
|
12 |
from queue import Queue
|
13 |
from threading import Thread
|
14 |
from time import sleep
|
|
|
15 |
from typing import List, Optional, Tuple
|
16 |
|
17 |
from smashed.utils import (
|
18 |
MultiPath,
|
19 |
-
compress_stream,
|
20 |
-
decompress_stream,
|
21 |
-
open_file_for_write,
|
22 |
recursively_list_files,
|
23 |
-
stream_file_for_read,
|
24 |
)
|
|
|
25 |
from tqdm import tqdm
|
26 |
|
27 |
|
@@ -33,30 +32,32 @@ def process_single(
|
|
33 |
all_src, dst = io_paths
|
34 |
docs_cnt = 0
|
35 |
|
36 |
-
|
37 |
-
|
38 |
-
|
|
|
39 |
for src in all_src:
|
40 |
-
|
41 |
-
in_stream = in_stack.enter_context(decompress_stream(in_file, "rt"))
|
42 |
|
43 |
-
|
44 |
-
|
45 |
-
|
46 |
-
|
47 |
-
|
48 |
-
|
|
|
|
|
|
|
49 |
|
50 |
-
|
51 |
-
|
52 |
|
53 |
-
|
54 |
-
|
55 |
-
|
56 |
|
57 |
-
|
58 |
-
|
59 |
-
pbar_queue.put((1, 0))
|
60 |
|
61 |
if pbar_queue is not None:
|
62 |
pbar_queue.put((0, docs_cnt))
|
@@ -110,7 +111,8 @@ def main():
|
|
110 |
src_paths.append([MultiPath.parse(p) for p in dir_values])
|
111 |
dir_path = MultiPath.parse(dir_name.replace("part_id=", "") + ".gz")
|
112 |
dst_path = dst / (diff) if len(diff := (dir_path - src)) > 0 else dst
|
113 |
-
dst_path.path =
|
|
|
114 |
dst_paths.append(dst_path)
|
115 |
|
116 |
if opts.debug:
|
|
|
9 |
from contextlib import ExitStack
|
10 |
from functools import partial
|
11 |
from multiprocessing import Manager, Pool, cpu_count, set_start_method
|
12 |
+
from pathlib import Path
|
13 |
from queue import Queue
|
14 |
from threading import Thread
|
15 |
from time import sleep
|
16 |
+
import re
|
17 |
from typing import List, Optional, Tuple
|
18 |
|
19 |
from smashed.utils import (
|
20 |
MultiPath,
|
|
|
|
|
|
|
21 |
recursively_list_files,
|
|
|
22 |
)
|
23 |
+
import smart_open
|
24 |
from tqdm import tqdm
|
25 |
|
26 |
|
|
|
32 |
all_src, dst = io_paths
|
33 |
docs_cnt = 0
|
34 |
|
35 |
+
if dst.is_local:
|
36 |
+
Path(dst.as_str).parent.mkdir(parents=True, exist_ok=True)
|
37 |
+
|
38 |
+
with smart_open.open(dst.as_str, "wt") as out_stream:
|
39 |
for src in all_src:
|
40 |
+
with smart_open.open(src.as_str, "rt") as in_stream:
|
|
|
41 |
|
42 |
+
for line in in_stream:
|
43 |
+
data = json.loads(line)
|
44 |
+
data.pop("metadata", None)
|
45 |
+
data["source"] = (
|
46 |
+
("s2ag" if "dataset=s2ag" in src.as_str else "s2orc") +
|
47 |
+
'/' +
|
48 |
+
("train" if "split=train" in src.as_str else "valid")
|
49 |
+
)
|
50 |
+
data["version"] = version
|
51 |
|
52 |
+
out_stream.write(json.dumps(data) + "\n")
|
53 |
+
docs_cnt += 1
|
54 |
|
55 |
+
if pbar_queue is not None and docs_cnt % 10000 == 0:
|
56 |
+
pbar_queue.put((0, docs_cnt))
|
57 |
+
docs_cnt = 0
|
58 |
|
59 |
+
if pbar_queue is not None:
|
60 |
+
pbar_queue.put((1, 0))
|
|
|
61 |
|
62 |
if pbar_queue is not None:
|
63 |
pbar_queue.put((0, docs_cnt))
|
|
|
111 |
src_paths.append([MultiPath.parse(p) for p in dir_values])
|
112 |
dir_path = MultiPath.parse(dir_name.replace("part_id=", "") + ".gz")
|
113 |
dst_path = dst / (diff) if len(diff := (dir_path - src)) > 0 else dst
|
114 |
+
dst_path.path = re.sub(r'dataset=(\w+)/', '\\1.', dst_path.path)
|
115 |
+
dst_path.path = re.sub(r'split=(\w+)/', '\\1.', dst_path.path)
|
116 |
dst_paths.append(dst_path)
|
117 |
|
118 |
if opts.debug:
|
requirements.txt
CHANGED
@@ -1,2 +1,2 @@
|
|
1 |
-
|
2 |
tqdm
|
|
|
1 |
+
smart_open
|
2 |
tqdm
|