Delete dataset_loader.py
Browse files- dataset_loader.py +0 -56
dataset_loader.py
DELETED
@@ -1,56 +0,0 @@
|
|
1 |
-
import os
|
2 |
-
import json
|
3 |
-
from datasets import DatasetBuilder, SplitGenerator, DownloadManager, DatasetInfo, Features, Value, Sequence
|
4 |
-
|
5 |
-
class MultiFileDataset(DatasetBuilder):
|
6 |
-
"""Example of a Hugging Face dataset script for handling multiple files per split."""
|
7 |
-
|
8 |
-
VERSION = "1.0.0"
|
9 |
-
|
10 |
-
def _info(self):
|
11 |
-
return DatasetInfo(
|
12 |
-
description="This dataset includes multiple JSON lines files for text classification.",
|
13 |
-
features=Features({
|
14 |
-
"question": Value("string"),
|
15 |
-
"options": Sequence(Value("string")),
|
16 |
-
"answer": Value("string"),
|
17 |
-
"prompt": Value("string"),
|
18 |
-
"num_options": Value("string"), # Assuming numeric values are expected for this field
|
19 |
-
"question_type": Value("string"),
|
20 |
-
"exam_id": Value("string") # Assuming all records will have an exam_id; use default value otherwise
|
21 |
-
}),
|
22 |
-
homepage="https://www.example.com/mydataset",
|
23 |
-
citation="Cite the source here if applicable.",
|
24 |
-
)
|
25 |
-
|
26 |
-
def _split_generators(self, dl_manager):
|
27 |
-
"""Returns SplitGenerators."""
|
28 |
-
# Assuming `data_dir` is your dataset's root directory on Hugging Face
|
29 |
-
return [
|
30 |
-
SplitGenerator(
|
31 |
-
name=datasets.Split.TRAIN,
|
32 |
-
gen_kwargs={"filepath": os.path.join(self.config.data_dir, "train/mcq")},
|
33 |
-
),
|
34 |
-
SplitGenerator(
|
35 |
-
name=datasets.Split.TEST,
|
36 |
-
gen_kwargs={"filepath": os.path.join(self.config.data_dir, "test/mcq")},
|
37 |
-
),
|
38 |
-
]
|
39 |
-
|
40 |
-
def _generate_examples(self, filepath):
|
41 |
-
"""Yields examples from multiple files."""
|
42 |
-
for file in sorted(os.listdir(filepath)): # Ensures consistent order
|
43 |
-
full_file_path = os.path.join(filepath, file)
|
44 |
-
if full_file_path.endswith('.jsonl'): # Ensure to process only JSON Lines files
|
45 |
-
with open(full_file_path, encoding="utf-8") as f:
|
46 |
-
for id, line in enumerate(f):
|
47 |
-
data = json.loads(line)
|
48 |
-
yield f"{file}_{id}", {
|
49 |
-
"question": data["question"],
|
50 |
-
"options": data["options"],
|
51 |
-
"answer": data["answer"],
|
52 |
-
"prompt": data["prompt"],
|
53 |
-
"num_options": int(data["num_options"]), # Convert to int if it's a string in JSON
|
54 |
-
"question_type": data["question_type"],
|
55 |
-
"exam_id": data.get("exam_id", "") # Check if this optional field exists
|
56 |
-
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|