suchirsalhan commited on
Commit
025b6e8
·
verified ·
1 Parent(s): f94d770

Create dataset_script.py

Browse files
Files changed (1) hide show
  1. dataset_script.py +43 -0
dataset_script.py ADDED
@@ -0,0 +1,43 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import os
2
+ from datasets import DatasetInfo, GeneratorBasedBuilder, Split, SplitGenerator, Value, Features
3
+
4
+ class CommonCorpus(GeneratorBasedBuilder):
5
+ VERSION = datasets.Version("1.0.0")
6
+ BUILDER_CONFIGS = [
7
+ datasets.BuilderConfig(name="bytelevel", version=VERSION, description="Bytelevel corpus data"),
8
+ ]
9
+
10
+ def _info(self):
11
+ return DatasetInfo(
12
+ description="Common Corpus from InfoTokenizers - bytelevel config",
13
+ features=Features({
14
+ "text": Value("string"),
15
+ }),
16
+ supervised_keys=None,
17
+ homepage="https://huggingface.co/datasets/InfoTokenizers/common-corpus",
18
+ citation="",
19
+ )
20
+
21
+ def _split_generators(self, dl_manager):
22
+ # Use the local extracted path to dataset files
23
+ data_dir = os.path.join(dl_manager.manual_dir, "bytelevel")
24
+
25
+ return [
26
+ SplitGenerator(
27
+ name=Split.TRAIN,
28
+ gen_kwargs={"data_dir": data_dir},
29
+ ),
30
+ ]
31
+
32
+ def _generate_examples(self, data_dir):
33
+ # Iterate over all .txt files inside bytelevel folder
34
+ file_paths = [os.path.join(data_dir, f) for f in os.listdir(data_dir) if f.endswith(".txt")]
35
+
36
+ example_id = 0
37
+ for file_path in file_paths:
38
+ with open(file_path, encoding="utf-8") as f:
39
+ for line in f:
40
+ text = line.strip()
41
+ if text:
42
+ yield example_id, {"text": text}
43
+ example_id += 1