Coldog2333 commited on
Commit
d8fff6a
1 Parent(s): 066e66d

Upload tiage.py

Browse files
Files changed (1) hide show
  1. tiage.py +109 -0
tiage.py ADDED
@@ -0,0 +1,109 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # coding=utf-8
2
+ # Copyright 2020 The HuggingFace Datasets Authors and the current dataset script contributor.
3
+ #
4
+ # Licensed under the Apache License, Version 2.0 (the "License");
5
+ # you may not use this file except in compliance with the License.
6
+ # You may obtain a copy of the License at
7
+ #
8
+ # http://www.apache.org/licenses/LICENSE-2.0
9
+ #
10
+ # Unless required by applicable law or agreed to in writing, software
11
+ # distributed under the License is distributed on an "AS IS" BASIS,
12
+ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13
+ # See the License for the specific language governing permissions and
14
+ # limitations under the License.
15
+ """TIAGE: A Benchmark for Topic-Shift Aware Dialog Modeling"""
16
+
17
+
18
+ import json
19
+
20
+ import datasets
21
+
22
+
23
+ _CITATION = """\
24
+ """
25
+
26
+ _DESCRIPTION = """\
27
+ """
28
+
29
+
30
+ _HOMEPAGE = "https://github.com/HuiyuanXie/tiage"
31
+
32
+ _LICENSE = """\
33
+ """
34
+ # TODO: Add link to the official dataset URLs here
35
+ # The HuggingFace dataset library don't host the datasets but only point to the original files
36
+ # This can be an arbitrary nested dict/list of URLs (see below in `_split_generators` method)
37
+ _URLs = {
38
+ "train": "https://huggingface.co/datasets/Coldog2333/tiage/resolve/main/train.json",
39
+ "validation": "https://huggingface.co/datasets/Coldog2333/tiage/resolve/main/validation.json",
40
+ "test": "https://huggingface.co/datasets/Coldog2333/tiage/resolve/main/test.json",
41
+ }
42
+
43
+
44
+ class TIAGEConfig(datasets.BuilderConfig):
45
+ """BuilderConfig for TIAGE"""
46
+
47
+ def __init__(self, **kwargs):
48
+ """
49
+ Args:
50
+ **kwargs: keyword arguments forwarded to super.
51
+ """
52
+ super().__init__(version=datasets.Version("1.0.0", ""), **kwargs)
53
+ self.dataset_name = "tiage"
54
+
55
+
56
+ class TIAGE(datasets.GeneratorBasedBuilder):
57
+ """TIAGE: A Benchmark for Topic-Shift Aware Dialog Modeling"""
58
+
59
+ VERSION = datasets.Version("1.0.0")
60
+
61
+ def _info(self):
62
+ return datasets.DatasetInfo(
63
+ description=_DESCRIPTION,
64
+ features=datasets.Features(
65
+ {
66
+ "dial_id": datasets.Value("string"),
67
+ "utterance": datasets.features.Sequence(datasets.Value("string")),
68
+ "segmentation_label": datasets.features.Sequence(datasets.Value("int32")),
69
+ "da": datasets.features.Sequence(datasets.Value("string")),
70
+ "role": datasets.features.Sequence(datasets.Value("string")),
71
+ "turn_id": datasets.features.Sequence(datasets.Value("int32")),
72
+ "topic_id": datasets.features.Sequence(datasets.Value("int32"))
73
+ }
74
+ ),
75
+ supervised_keys=None,
76
+ homepage=_HOMEPAGE,
77
+ license=_LICENSE,
78
+ citation=_CITATION,
79
+ )
80
+
81
+ def _split_generators(self, dl_manager):
82
+ """Returns SplitGenerators."""
83
+ downloaded_files = dl_manager.download_and_extract(_URLs)
84
+ return [
85
+ datasets.SplitGenerator(
86
+ name=datasets.Split.TRAIN, gen_kwargs={"filepath": downloaded_files["train"]}
87
+ ),
88
+ datasets.SplitGenerator(
89
+ name=datasets.Split.VALIDATION, gen_kwargs={"filepath": downloaded_files["validation"]}
90
+ ),
91
+ datasets.SplitGenerator(
92
+ name=datasets.Split.TEST, gen_kwargs={"filepath": downloaded_files["test"]}
93
+ )
94
+ ]
95
+
96
+ def _generate_examples(self, filepath):
97
+ """Yields examples."""
98
+ with open(filepath, encoding="utf-8") as f:
99
+ data = json.load(f)["dial_data"][self.dataset_name]
100
+ for id_, row in enumerate(data):
101
+ yield id_, {
102
+ "dial_id": row["dial_id"],
103
+ "utterance": [utterance for utterance in row["turns"]["utterance"]],
104
+ "segmentation_label": [segmentation_label for segmentation_label in row["turns"]["segmentation_label"]],
105
+ "da": [da for da in row["turns"]["da"]],
106
+ "role": [role for role in row["turns"]["role"]],
107
+ "turn_id": [turn_id for turn_id in row["turns"]["turn_id"]],
108
+ "topic_id": [topic_id for topic_id in row["turns"]["topic_id"]]
109
+ }