abdoelsayed commited on
Commit
56ed485
·
1 Parent(s): 7ffafbf
Files changed (1) hide show
  1. arabicaqa.py +62 -0
arabicaqa.py ADDED
@@ -0,0 +1,62 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
+ }
38
+ downloaded_files = dl_manager.download(urls_to_download)
39
+
40
+ return [
41
+ datasets.SplitGenerator(name=datasets.Split.TRAIN, gen_kwargs={"filepath": downloaded_files["train"]}),
42
+ datasets.SplitGenerator(name=datasets.Split.VALIDATION, gen_kwargs={"filepath": downloaded_files["dev"]}),
43
+ ]
44
+
45
+ def _generate_examples(self, filepath):
46
+ with open(filepath, encoding="utf-8") as f:
47
+ squad_data = json.load(f)["data"]
48
+ for article in squad_data:
49
+ title = article.get("title", "")
50
+ for paragraph in article["paragraphs"]:
51
+ context = paragraph["context"]
52
+ for qa in paragraph["qas"]:
53
+ id_ = qa["id"]
54
+ question = qa["question"]
55
+ answers = [{"text": answer["text"], "answer_start": answer["answer_start"]} for answer in qa.get("answers", [])]
56
+
57
+ yield id_, {
58
+ "title": title,
59
+ "context": context,
60
+ "question": question,
61
+ "answers": answers,
62
+ }