abdoelsayed commited on
Commit
b2321ec
1 Parent(s): 55b9242
Files changed (1) hide show
  1. MRC/ArabicaQA.py +65 -0
MRC/ArabicaQA.py ADDED
@@ -0,0 +1,65 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ from datasets import load_dataset_builder, DatasetInfo, DownloadConfig, GeneratorBasedBuilder, datasets
2
+
3
+ class CustomSQuADFormatDataset(GeneratorBasedBuilder):
4
+ """A custom dataset similar to SQuAD but tailored for 'ArabicaQA' hosted on Hugging Face."""
5
+
6
+ VERSION = datasets.Version("1.0.0")
7
+ BUILDER_CONFIGS = [
8
+ datasets.BuilderConfig(name="ArabicaQA", version=VERSION, description="Custom dataset similar to SQuAD format.")
9
+ ]
10
+
11
+ def _info(self):
12
+ return DatasetInfo(
13
+ description="This dataset is formatted similarly to the SQuAD dataset.",
14
+ features=datasets.Features(
15
+ {
16
+ "id": datasets.Value("string"),
17
+ "title": datasets.Value("string"),
18
+ "context": datasets.Value("string"),
19
+ "question": datasets.Value("string"),
20
+ "answers": datasets.features.Sequence(
21
+ {
22
+ "text": datasets.Value("string"),
23
+ "answer_start": datasets.Value("int32"),
24
+ }
25
+ ),
26
+ }
27
+ ),
28
+ supervised_keys=None,
29
+ homepage="https://huggingface.co/datasets/abdoelsayed/ArabicaQA",
30
+ citation="",
31
+ )
32
+
33
+ def _split_generators(self, dl_manager: DownloadConfig):
34
+ urls_to_download = {
35
+ "train": "https://huggingface.co/datasets/abdoelsayed/ArabicaQA/raw/main/MRC/train.json",
36
+ "dev": "https://huggingface.co/datasets/abdoelsayed/ArabicaQA/raw/main/MRC/val.json",
37
+ "test": "https://huggingface.co/datasets/abdoelsayed/ArabicaQA/raw/main/MRC/test.json"
38
+ }
39
+ downloaded_files = dl_manager.download(urls_to_download)
40
+
41
+ return [
42
+ datasets.SplitGenerator(name=datasets.Split.TRAIN, gen_kwargs={"filepath": downloaded_files["train"]}),
43
+ datasets.SplitGenerator(name=datasets.Split.VALIDATION, gen_kwargs={"filepath": downloaded_files["dev"]}),
44
+ datasets.SplitGenerator(name=datasets.Split.VALIDATION, gen_kwargs={"filepath": downloaded_files["test"]}),
45
+
46
+ ]
47
+
48
+ def _generate_examples(self, filepath):
49
+ with open(filepath, encoding="utf-8") as f:
50
+ squad_data = json.load(f)["data"]
51
+ for article in squad_data:
52
+ title = article.get("title", "")
53
+ for paragraph in article["paragraphs"]:
54
+ context = paragraph["context"]
55
+ for qa in paragraph["qas"]:
56
+ id_ = qa["id"]
57
+ question = qa["question"]
58
+ answers = [{"text": answer["text"], "answer_start": answer["answer_start"]} for answer in qa.get("answers", [])]
59
+
60
+ yield id_, {
61
+ "title": title,
62
+ "context": context,
63
+ "question": question,
64
+ "answers": answers,
65
+ }