suchirsalhan commited on
Commit
e469b84
·
verified ·
1 Parent(s): 0a244d9

Delete common-corpus.py

Browse files
Files changed (1) hide show
  1. common-corpus.py +0 -65
common-corpus.py DELETED
@@ -1,65 +0,0 @@
1
- import os
2
- import datasets
3
- from datasets import DatasetInfo, GeneratorBasedBuilder, Split, SplitGenerator, Value, Features
4
-
5
- class CommonCorpus(GeneratorBasedBuilder):
6
- VERSION = datasets.Version("1.0.0")
7
- BUILDER_CONFIGS = [
8
- datasets.BuilderConfig(name="default", version=VERSION, description="Common Corpus dataset"),
9
- ]
10
-
11
- def _info(self):
12
- return DatasetInfo(
13
- description="Common Corpus with multiple subdirectories",
14
- features=Features({
15
- "text": Value("string"),
16
- "source": Value("string"),
17
- }),
18
- supervised_keys=None,
19
- homepage="https://huggingface.co/datasets/InfoTokenizers/common-corpus",
20
- citation="",
21
- )
22
-
23
- def _split_generators(self, dl_manager):
24
- # Base URL for the dataset
25
- base_url = "https://huggingface.co/datasets/InfoTokenizers/common-corpus/"
26
-
27
- # Download and extract all data
28
- data_dir = dl_manager.download_and_extract(base_url)
29
-
30
- # List subdirectories to scan
31
- subdirs = ["bytelevel", "bytelevel-llm-data", "bytelevel-subset", "bytelevel-subset_1", "bytelevel-subset_2"]
32
-
33
- valid_dirs = [os.path.join(data_dir, subdir) for subdir in subdirs if os.path.exists(os.path.join(data_dir, subdir))]
34
-
35
- if not valid_dirs:
36
- raise FileNotFoundError(f"No valid data directories found in {data_dir}. Expected one of: {subdirs}")
37
-
38
- return [
39
- SplitGenerator(
40
- name=Split.TRAIN,
41
- gen_kwargs={"data_dirs": valid_dirs},
42
- ),
43
- ]
44
-
45
- def _generate_examples(self, data_dirs):
46
- example_id = 0
47
-
48
- for data_dir in data_dirs:
49
- subdir_name = os.path.basename(data_dir)
50
-
51
- for root, _, files in os.walk(data_dir):
52
- for filename in files:
53
- if filename.endswith(".txt"):
54
- file_path = os.path.join(root, filename)
55
-
56
- with open(file_path, encoding="utf-8") as f:
57
- for line in f:
58
- text = line.strip()
59
- if text:
60
- yield example_id, {
61
- "text": text,
62
- "source": subdir_name,
63
- }
64
- example_id += 1
65
-