Update common-corpus.py
Browse files- common-corpus.py +8 -6
common-corpus.py
CHANGED
|
@@ -10,7 +10,7 @@ class CommonCorpus(GeneratorBasedBuilder):
|
|
| 10 |
|
| 11 |
def _info(self):
|
| 12 |
return DatasetInfo(
|
| 13 |
-
description="Common Corpus
|
| 14 |
features=Features({
|
| 15 |
"text": Value("string"),
|
| 16 |
"source": Value("string"),
|
|
@@ -21,13 +21,15 @@ class CommonCorpus(GeneratorBasedBuilder):
|
|
| 21 |
)
|
| 22 |
|
| 23 |
def _split_generators(self, dl_manager):
|
| 24 |
-
#
|
| 25 |
-
|
| 26 |
|
| 27 |
-
#
|
|
|
|
|
|
|
|
|
|
| 28 |
subdirs = ["bytelevel", "bytelevel-llm-data", "bytelevel-subset", "bytelevel-subset_1", "bytelevel-subset_2"]
|
| 29 |
|
| 30 |
-
# Check existence of each subdir
|
| 31 |
valid_dirs = [os.path.join(data_dir, subdir) for subdir in subdirs if os.path.exists(os.path.join(data_dir, subdir))]
|
| 32 |
|
| 33 |
if not valid_dirs:
|
|
@@ -46,7 +48,6 @@ class CommonCorpus(GeneratorBasedBuilder):
|
|
| 46 |
for data_dir in data_dirs:
|
| 47 |
subdir_name = os.path.basename(data_dir)
|
| 48 |
|
| 49 |
-
# Iterate over all .txt files in the directory
|
| 50 |
for root, _, files in os.walk(data_dir):
|
| 51 |
for filename in files:
|
| 52 |
if filename.endswith(".txt"):
|
|
@@ -61,3 +62,4 @@ class CommonCorpus(GeneratorBasedBuilder):
|
|
| 61 |
"source": subdir_name,
|
| 62 |
}
|
| 63 |
example_id += 1
|
|
|
|
|
|
| 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"),
|
|
|
|
| 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/resolve/main/"
|
| 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:
|
|
|
|
| 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"):
|
|
|
|
| 62 |
"source": subdir_name,
|
| 63 |
}
|
| 64 |
example_id += 1
|
| 65 |
+
|