Commit
·
76e185d
1
Parent(s):
e59c943
Upload my_uspto.py
Browse files- my_uspto.py +110 -0
my_uspto.py
ADDED
@@ -0,0 +1,110 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
from datasets import DatasetBuilder, GeneratorBasedBuilder, SplitGenerator, Features, Value
|
2 |
+
import json
|
3 |
+
import datasets
|
4 |
+
import os
|
5 |
+
from glob import glob
|
6 |
+
import zstandard as zstd
|
7 |
+
from datasets.utils import Version
|
8 |
+
import io
|
9 |
+
from huggingface_hub import snapshot_download
|
10 |
+
|
11 |
+
|
12 |
+
class MyUSPTODataset(GeneratorBasedBuilder):
|
13 |
+
VERSION = Version("1.0.0")
|
14 |
+
|
15 |
+
def _info(self):
|
16 |
+
return datasets.DatasetInfo(
|
17 |
+
description="USPTO Patents Dataset",
|
18 |
+
features=datasets.Features(
|
19 |
+
{
|
20 |
+
"text": datasets.Value("string"),
|
21 |
+
|
22 |
+
}
|
23 |
+
),
|
24 |
+
supervised_keys=None,
|
25 |
+
|
26 |
+
)
|
27 |
+
|
28 |
+
def _split_generators(self, dl_manager):
|
29 |
+
snapshot_download(repo_id="jordiclive/my_uspto",repo_type='dataset')
|
30 |
+
return [
|
31 |
+
datasets.SplitGenerator(
|
32 |
+
name=datasets.Split.TRAIN,
|
33 |
+
# These kwargs will be passed to _generate_examples
|
34 |
+
gen_kwargs={
|
35 |
+
"data_dir": "train",
|
36 |
+
"split": None,
|
37 |
+
},
|
38 |
+
|
39 |
+
),
|
40 |
+
datasets.SplitGenerator(
|
41 |
+
name="validation_pile",
|
42 |
+
# These kwargs will be passed to _generate_examples
|
43 |
+
gen_kwargs={
|
44 |
+
"data_dir": "val",
|
45 |
+
"split": "pile",
|
46 |
+
},
|
47 |
+
),
|
48 |
+
datasets.SplitGenerator(
|
49 |
+
name="validation_domain",
|
50 |
+
# These kwargs will be passed to _generate_examples
|
51 |
+
gen_kwargs={
|
52 |
+
"data_dir": "val",
|
53 |
+
"split": "domain",
|
54 |
+
},
|
55 |
+
),
|
56 |
+
datasets.SplitGenerator(
|
57 |
+
name="test_pile",
|
58 |
+
# These kwargs will be passed to _generate_examples
|
59 |
+
gen_kwargs={
|
60 |
+
"data_dir": "test_pile",
|
61 |
+
"split": "pile"
|
62 |
+
},
|
63 |
+
|
64 |
+
),
|
65 |
+
datasets.SplitGenerator(
|
66 |
+
name="test_domain",
|
67 |
+
# These kwargs will be passed to _generate_examples
|
68 |
+
gen_kwargs={
|
69 |
+
"data_dir": "test_domain",
|
70 |
+
"split": "domain"
|
71 |
+
},
|
72 |
+
|
73 |
+
),
|
74 |
+
|
75 |
+
]
|
76 |
+
|
77 |
+
def _generate_examples(self, data_dir, split):
|
78 |
+
dctx = zstd.ZstdDecompressor()
|
79 |
+
idx = -1
|
80 |
+
file_paths = glob(os.path.join(data_dir, f"*.jsonl.zst"))
|
81 |
+
if split is not None:
|
82 |
+
file_paths = [f for f in file_paths if split in f]
|
83 |
+
for file in file_paths:
|
84 |
+
with open(file, "rb") as f:
|
85 |
+
reader = dctx.stream_reader(f)
|
86 |
+
buffer = io.BufferedReader(reader)
|
87 |
+
for _, line in enumerate(buffer.readlines()):
|
88 |
+
data = json.loads(line)
|
89 |
+
idx += 1
|
90 |
+
yield idx, data
|
91 |
+
|
92 |
+
|
93 |
+
# if __name__ == "__main__":
|
94 |
+
# b = datasets.load_dataset('/Users/jordanclive/Desktop/MDEL/my_uspto')
|
95 |
+
# # import os
|
96 |
+
# # import shutil
|
97 |
+
# # import glob
|
98 |
+
# # cache_directory = "/Users/jordanclive/.cache/huggingface/datasets"
|
99 |
+
# #
|
100 |
+
# # dataset = MyUSPTODataset()
|
101 |
+
# #
|
102 |
+
# # #
|
103 |
+
# # dataset = MyUSPTODataset()
|
104 |
+
# # dataset.download_and_prepare()
|
105 |
+
# # dataset = dataset.as_dataset()
|
106 |
+
# # # # x = 1
|
107 |
+
# # # print(dataset)
|
108 |
+
# # # print(dataset["train"][0])
|
109 |
+
# # # print(dataset["test"][0])
|
110 |
+
# # # print(dataset["validation"][0])
|