BHSo commited on
Commit
8331f75
1 Parent(s): 90ac92c

Change documentation and remove unused field

Browse files
Files changed (2) hide show
  1. JaQuAD.py +67 -54
  2. README.md +2 -2
JaQuAD.py CHANGED
@@ -1,50 +1,50 @@
 
 
 
1
  import json
2
  import os
3
 
4
  import datasets
5
 
6
-
7
- _CITATION = """\
8
  @article{SkelterLabsInc:JaQuAD,
9
  title = {{JaQuAD}: Japanese Question Answering Dataset for Machine
10
  Reading Comprehension},
11
- author = {Byunghoon, So and
12
- Kyuhong, Byun and
13
- Kyungwon, Kang and
14
- Seongjin, Cho},
15
  year = {2022},
16
  }
17
- """
18
- _DESCRIPTION = """\
19
- Japanese Question Answering Dataset (JaQuAD), released in 2022, is a
20
- human-annotated dataset created for Japanese Machine Reading Comprehension.
21
- JaQuAD is developed to provide a SQuAD-like QA dataset in Japanese.
22
- JaQuAD contains 39,696 question-answer pairs.
23
- Questions and answers are manually curated by human annotators.
24
- Contexts are collected from Japanese Wikipedia articles.
25
- """
26
- _LICENSE = "CC BY-SA 3.0"
27
- _HOMEPAGE=""
28
- _URL = "https://huggingface.co/datasets/SkelterLabsInc/JaQuAD/raw/main/data/"
29
 
30
 
31
  class JaQuAD(datasets.GeneratorBasedBuilder):
32
-
33
- VERSION = datasets.Version("0.1.0")
34
 
35
  def _info(self):
36
-
37
  features = datasets.Features({
38
- "id": datasets.Value("string"),
39
- "title": datasets.Value("string"),
40
- "context": datasets.Value("string"),
41
- "question": datasets.Value("string"),
42
- "question_type": datasets.Value("string"),
43
- "answers": datasets.features.Sequence({
44
- "text": datasets.Value("string"),
45
- "answer_start": datasets.Value("int32"),
46
- "answer_type": datasets.Value("string"),
47
- }),
 
48
  })
49
  return datasets.DatasetInfo(
50
  description=_DESCRIPTION,
@@ -56,49 +56,62 @@ class JaQuAD(datasets.GeneratorBasedBuilder):
56
 
57
  def _split_generators(self, dl_manager):
58
  urls_to_download = {
59
- "train": [os.path.join(_URL, f"train/jaquad_train_{i:04d}.json") for i in range(30)],
60
- "dev": [os.path.join(_URL, f"dev/jaquad_dev_{i:04d}.json") for i in range(4)],
 
 
 
 
 
 
61
  }
62
  downloaded_files = dl_manager.download_and_extract(urls_to_download)
63
  return [
64
  datasets.SplitGenerator(
65
  name=datasets.Split.TRAIN,
66
- gen_kwargs={"filepaths": downloaded_files["train"]},
67
  ),
68
  datasets.SplitGenerator(
69
  name=datasets.Split.VALIDATION,
70
- gen_kwargs={"filepaths": downloaded_files["dev"]},
71
  ),
72
  ]
73
 
74
  def _generate_examples(self, filepaths):
75
  for filename in filepaths:
76
- with open(filename, encoding='utf-8') as f:
77
- jaquad = json.load(f)
78
  for article in jaquad['data']:
79
  title = article.get('title', '').strip()
80
  for paragraph in article['paragraphs']:
81
  context = paragraph['context'].strip()
82
  for qa in paragraph['qas']:
83
- qa_id = qa["id"]
84
- question = qa["question"].strip()
85
- question_type = qa["question_type"]
86
-
87
- answer_starts = [answer["answer_start"] for answer in qa["answers"]]
88
- answer_texts = [answer["text"].strip() for answer in qa["answers"]]
89
- answer_types = [answer["answer_type"] for answer in qa["answers"]]
90
 
91
- assert len(answer_starts) == len(answer_texts) == len(answer_types) == 1
 
 
 
 
 
 
 
 
 
 
 
92
 
93
  yield qa_id, {
94
- "title": title,
95
- "context": context,
96
- "question": question,
97
- "question_type": question_type,
98
- "id": qa_id,
99
- "answers": {
100
- "text": answer_texts,
101
- "answer_start": answer_starts,
102
- "answer_type": answer_types,
103
  },
104
  }
1
+ '''Dataset loading script for JaQuAD.
2
+ We refer to https://huggingface.co/datasets/squad_v2/blob/main/squad_v2.py
3
+ '''
4
  import json
5
  import os
6
 
7
  import datasets
8
 
9
+ _CITATION = '''
 
10
  @article{SkelterLabsInc:JaQuAD,
11
  title = {{JaQuAD}: Japanese Question Answering Dataset for Machine
12
  Reading Comprehension},
13
+ author = {Byunghoon So and
14
+ Kyuhong Byun and
15
+ Kyungwon Kang and
16
+ Seongjin Cho},
17
  year = {2022},
18
  }
19
+ '''
20
+ _DESCRIPTION = '''Japanese Question Answering Dataset (JaQuAD), released in
21
+ 2022, is a human-annotated dataset created for Japanese Machine Reading
22
+ Comprehension. JaQuAD is developed to provide a SQuAD-like QA dataset in
23
+ Japanese. JaQuAD contains 39,696 question-answer pairs. Questions and answers
24
+ are manually curated by human annotators. Contexts are collected from Japanese
25
+ Wikipedia articles.
26
+ '''
27
+ _LICENSE = 'CC BY-SA 3.0'
28
+ _HOMEPAGE = 'https://skelterlabs.com/en/'
29
+ _URL = 'https://huggingface.co/datasets/SkelterLabsInc/JaQuAD/raw/main/data/'
 
30
 
31
 
32
  class JaQuAD(datasets.GeneratorBasedBuilder):
33
+ VERSION = datasets.Version('0.1.0')
 
34
 
35
  def _info(self):
 
36
  features = datasets.Features({
37
+ 'id': datasets.Value('string'),
38
+ 'title': datasets.Value('string'),
39
+ 'context': datasets.Value('string'),
40
+ 'question': datasets.Value('string'),
41
+ 'question_type': datasets.Value('string'),
42
+ 'answers':
43
+ datasets.features.Sequence({
44
+ 'text': datasets.Value('string'),
45
+ 'answer_start': datasets.Value('int32'),
46
+ 'answer_type': datasets.Value('string'),
47
+ }),
48
  })
49
  return datasets.DatasetInfo(
50
  description=_DESCRIPTION,
56
 
57
  def _split_generators(self, dl_manager):
58
  urls_to_download = {
59
+ 'train': [
60
+ os.path.join(_URL, f'train/jaquad_train_{i:04d}.json')
61
+ for i in range(30)
62
+ ],
63
+ 'dev': [
64
+ os.path.join(_URL, f'dev/jaquad_dev_{i:04d}.json')
65
+ for i in range(4)
66
+ ],
67
  }
68
  downloaded_files = dl_manager.download_and_extract(urls_to_download)
69
  return [
70
  datasets.SplitGenerator(
71
  name=datasets.Split.TRAIN,
72
+ gen_kwargs={'filepaths': downloaded_files['train']},
73
  ),
74
  datasets.SplitGenerator(
75
  name=datasets.Split.VALIDATION,
76
+ gen_kwargs={'filepaths': downloaded_files['dev']},
77
  ),
78
  ]
79
 
80
  def _generate_examples(self, filepaths):
81
  for filename in filepaths:
82
+ with open(filename, encoding='utf-8') as ifile:
83
+ jaquad = json.load(ifile)
84
  for article in jaquad['data']:
85
  title = article.get('title', '').strip()
86
  for paragraph in article['paragraphs']:
87
  context = paragraph['context'].strip()
88
  for qa in paragraph['qas']:
89
+ qa_id = qa['id']
90
+ question = qa['question'].strip()
91
+ question_type = qa['question_type']
 
 
 
 
92
 
93
+ answer_starts = [
94
+ answer['answer_start']
95
+ for answer in qa['answers']
96
+ ]
97
+ answer_texts = [
98
+ answer['text'].strip()
99
+ for answer in qa['answers']
100
+ ]
101
+ answer_types = [
102
+ answer['answer_type']
103
+ for answer in qa['answers']
104
+ ]
105
 
106
  yield qa_id, {
107
+ 'title': title,
108
+ 'context': context,
109
+ 'question': question,
110
+ 'question_type': question_type,
111
+ 'id': qa_id,
112
+ 'answers': {
113
+ 'text': answer_texts,
114
+ 'answer_start': answer_starts,
115
+ 'answer_type': answer_types,
116
  },
117
  }
README.md CHANGED
@@ -96,7 +96,7 @@ An example of 'validation':
96
  "question_type": "Multiple sentence reasoning",
97
  "answers": {
98
  "text": "イタセンパラ",
99
- "answers_start": 0,
100
  "answer_type": "Object",
101
  },
102
  },
@@ -111,7 +111,7 @@ An example of 'validation':
111
  - `question_type`: a `string` feature.
112
  - `answers`: a dictionary feature containing:
113
  - `text`: a `string` feature.
114
- - `answers_start`: a `int32` feature.
115
  - `answer_type`: a `string` feature.
116
 
117
  ### Data Splitting
96
  "question_type": "Multiple sentence reasoning",
97
  "answers": {
98
  "text": "イタセンパラ",
99
+ "answer_start": 0,
100
  "answer_type": "Object",
101
  },
102
  },
111
  - `question_type`: a `string` feature.
112
  - `answers`: a dictionary feature containing:
113
  - `text`: a `string` feature.
114
+ - `answer_start`: a `int32` feature.
115
  - `answer_type`: a `string` feature.
116
 
117
  ### Data Splitting