abhijitt commited on
Commit
da6072d
·
1 Parent(s): 8029ec6

Upload got.py

Browse files
Files changed (1) hide show
  1. got.py +111 -0
got.py ADDED
@@ -0,0 +1,111 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ """TODO(got): Add a description here."""
2
+
3
+
4
+ import json
5
+
6
+ import datasets
7
+ from datasets.tasks import QuestionAnsweringExtractive
8
+
9
+
10
+ # TODO(got): BibTeX citation
11
+
12
+ _CITATION = """\
13
+ test 123
14
+ """
15
+ _DESCRIPTION = """\
16
+ test 567
17
+ """
18
+
19
+ _URL = "https://gitlab.com/johntang/data/-/raw/main/got/got_train.json"
20
+ _URLS = {
21
+ "train": _URL + "dev-v1.1.json",
22
+ "dev": _URL + "dev-v1.1.json"
23
+ }
24
+
25
+
26
+ class GotConfig(datasets.BuilderConfig):
27
+ """BuilderConfig for GOT."""
28
+
29
+ def __init__(self, **kwargs):
30
+ """BuilderConfig for GOT.
31
+ Args:
32
+ **kwargs: keyword arguments forwarded to super.
33
+ """
34
+ super(GotConfig, self).__init__(**kwargs)
35
+
36
+
37
+
38
+ class Got(datasets.GeneratorBasedBuilder):
39
+ """GOT: Test"""
40
+
41
+ BUILDER_CONFIGS = [
42
+ GotConfig(
43
+ name="plain_text",
44
+ version=datasets.Version("1.0.0", ""),
45
+ description="Plain text",
46
+ ),
47
+ ]
48
+
49
+ def _info(self):
50
+ return datasets.DatasetInfo(
51
+ description=_DESCRIPTION,
52
+ features=datasets.Features(
53
+ {
54
+ "id": datasets.Value("string"),
55
+ "title": datasets.Value("string"),
56
+ "context": datasets.Value("string"),
57
+ "question": datasets.Value("string"),
58
+ "answers": datasets.features.Sequence(
59
+ {
60
+ "text": datasets.Value("string"),
61
+ "answer_start": datasets.Value("int32"),
62
+ }
63
+ ),
64
+ }
65
+ ),
66
+ # No default supervised_keys (as we have to pass both question
67
+ # and context as input).
68
+ supervised_keys=None,
69
+ homepage="https://gitlab.com/johntang/data/got",
70
+ citation=_CITATION,
71
+ task_templates=[
72
+ QuestionAnsweringExtractive(
73
+ question_column="question", context_column="context", answers_column="answers"
74
+ )
75
+ ],
76
+ )
77
+
78
+ def _split_generators(self, dl_manager):
79
+ downloaded_files = dl_manager.download_and_extract(_URLS)
80
+
81
+ return [
82
+ datasets.SplitGenerator(name=datasets.Split.TRAIN, gen_kwargs={"filepath": downloaded_files["train"]}),
83
+ datasets.SplitGenerator(name=datasets.Split.VALIDATION, gen_kwargs={"filepath": downloaded_files["dev"]}),
84
+ ]
85
+
86
+ def _generate_examples(self, filepath):
87
+ """This function returns the examples in the raw (text) form."""
88
+ logger.info("generating examples from = %s", filepath)
89
+ key = 0
90
+ with open(filepath, encoding="utf-8") as f:
91
+ squad = json.load(f)
92
+ for article in squad["data"]:
93
+ title = article.get("title", "")
94
+ for paragraph in article["paragraphs"]:
95
+ context = paragraph["context"] # do not strip leading blank spaces GH-2585
96
+ for qa in paragraph["qas"]:
97
+ answer_starts = [answer["answer_start"] for answer in qa["answers"]]
98
+ answers = [answer["text"] for answer in qa["answers"]]
99
+ # Features currently used are "context", "question", and "answers".
100
+ # Others are extracted here for the ease of future expansions.
101
+ yield key, {
102
+ "title": title,
103
+ "context": context,
104
+ "question": qa["question"],
105
+ "id": qa["id"],
106
+ "answers": {
107
+ "answer_start": answer_starts,
108
+ "text": answers,
109
+ },
110
+ }
111
+ key += 1