Datasets:

Modalities:
Video
Languages:
Chinese
Libraries:
Datasets
License:
AIMClab commited on
Commit
db0fd29
·
1 Parent(s): a14e0c4

Create ChinaOpen.py

Browse files
Files changed (1) hide show
  1. ChinaOpen.py +124 -0
ChinaOpen.py ADDED
@@ -0,0 +1,124 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+
2
+ import json
3
+
4
+ import datasets
5
+ from datasets.tasks import QuestionAnsweringExtractive
6
+
7
+
8
+ logger = datasets.logging.get_logger(__name__)
9
+
10
+ _CITATION = """\
11
+ @article{2016arXiv160605250R,
12
+ author = {{Rajpurkar}, Pranav and {Zhang}, Jian and {Lopyrev},
13
+ Konstantin and {Liang}, Percy},
14
+ title = "{SQuAD: 100,000+ Questions for Machine Comprehension of Text}",
15
+ journal = {arXiv e-prints},
16
+ year = 2016,
17
+ eid = {arXiv:1606.05250},
18
+ pages = {arXiv:1606.05250},
19
+ archivePrefix = {arXiv},
20
+ eprint = {1606.05250},
21
+ }
22
+ """
23
+
24
+ _DESCRIPTION = """\
25
+ Stanford Question Answering Dataset (SQuAD) is a reading comprehension \
26
+ dataset, consisting of questions posed by crowdworkers on a set of Wikipedia \
27
+ articles, where the answer to every question is a segment of text, or span, \
28
+ from the corresponding reading passage, or the question might be unanswerable.
29
+ """
30
+
31
+
32
+
33
+ #_URL = "./ChinaOpen-1k.zip"
34
+ _URLS = {
35
+ "train": "https://huggingface.co/datasets/AIMClab/ChinaOpen/tree/main/data"
36
+ }
37
+
38
+
39
+
40
+ class ChinaOpenConfig(datasets.BuilderConfig):
41
+ """BuilderConfig for SQUAD."""
42
+
43
+ def __init__(self, **kwargs):
44
+ """BuilderConfig for SQUAD.
45
+ Args:
46
+ **kwargs: keyword arguments forwarded to super.
47
+ """
48
+ super(ChinaOpenConfig, self).__init__(**kwargs)
49
+
50
+
51
+ class ChinaOpen(datasets.GeneratorBasedBuilder):
52
+ """SQUAD: The Stanford Question Answering Dataset. Version 1.1."""
53
+
54
+ BUILDER_CONFIGS = [
55
+ ChinaOpenConfig(
56
+ name="plain_text",
57
+ version=datasets.Version("1.0.0", ""),
58
+ description="Plain text",
59
+ ),
60
+ ]
61
+
62
+ def _info(self):
63
+ return datasets.DatasetInfo(
64
+ description=_DESCRIPTION,
65
+ features=datasets.Features(
66
+ {
67
+ "id": datasets.Value("string"),
68
+ "title": datasets.Value("string"),
69
+ "context": datasets.Value("string"),
70
+ "question": datasets.Value("string"),
71
+ "answers": datasets.features.Sequence(
72
+ {
73
+ "text": datasets.Value("string"),
74
+ "answer_start": datasets.Value("int32"),
75
+ }
76
+ ),
77
+ }
78
+ ),
79
+ # No default supervised_keys (as we have to pass both question
80
+ # and context as input).
81
+ supervised_keys=None,
82
+ citation=_CITATION,
83
+ task_templates=[
84
+ QuestionAnsweringExtractive(
85
+ question_column="question", context_column="context", answers_column="answers"
86
+ )
87
+ ],
88
+ )
89
+
90
+ def _split_generators(self, dl_manager):
91
+ downloaded_files = dl_manager.download_and_extract(_URLS)
92
+
93
+ return [
94
+ datasets.SplitGenerator(name=datasets.Split.TRAIN, gen_kwargs={"filepath": downloaded_files["train"]}),
95
+ #datasets.SplitGenerator(name=datasets.Split.VALIDATION, gen_kwargs={"filepath": downloaded_files["dev"]}),
96
+ ]
97
+ '''
98
+ def _generate_examples(self, filepath):
99
+ """This function returns the examples in the raw (text) form."""
100
+ logger.info("generating examples from = %s", filepath)
101
+ key = 0
102
+ with open(filepath, encoding="utf-8") as f:
103
+ squad = json.load(f)
104
+ for article in squad["data"]:
105
+ title = article.get("title", "")
106
+ for paragraph in article["paragraphs"]:
107
+ context = paragraph["context"] # do not strip leading blank spaces GH-2585
108
+ for qa in paragraph["qas"]:
109
+ answer_starts = [answer["answer_start"] for answer in qa["answers"]]
110
+ answers = [answer["text"] for answer in qa["answers"]]
111
+ # Features currently used are "context", "question", and "answers".
112
+ # Others are extracted here for the ease of future expansions.
113
+ yield key, {
114
+ "title": title,
115
+ "context": context,
116
+ "question": qa["question"],
117
+ "id": qa["id"],
118
+ "answers": {
119
+ "answer_start": answer_starts,
120
+ "text": answers,
121
+ },
122
+ }
123
+ key += 1
124
+ '''