ghaddara commited on
Commit
70a8151
·
verified ·
1 Parent(s): 0ee4b80

Upload 3 files

Browse files
Files changed (3) hide show
  1. CHARP.py +137 -0
  2. data/eCHARP.json +0 -0
  3. data/hCHARP.json +0 -0
CHARP.py ADDED
@@ -0,0 +1,137 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # Copyright 2020 The HuggingFace Datasets Authors, the initial dataset script creator (Nouha Drizi),
2
+ # the current dataset script contributor (Abbas Ghaddar).
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
+ """CHARP: Conversation History AwaReness Probing for Knowledge-grounded Dialogue Systems"""
16
+
17
+
18
+ import json
19
+
20
+ import datasets
21
+ from datasets import NamedSplit
22
+
23
+ # Find for instance the citation on arxiv or on the dataset repo/website
24
+ _CITATION = """\
25
+ @article{dziri2022faithdial,
26
+ title={FaithDial: A Faithful Benchmark for Information-Seeking Dialogue},
27
+ author={Dziri, Nouha and Kamalloo, Ehsan and Milton, Sivan and Zaiane, Osmar and Yu, Mo and Ponti, Edoardo and Reddy, Siva},
28
+ journal={arXiv preprint, arXiv:2204.10757},
29
+ year={2022},
30
+ url={https://arxiv.org/abs/2204.10757}
31
+ }
32
+ """
33
+
34
+ # You can copy an official description
35
+ _DESCRIPTION = """\
36
+ CHARP is a testbed, designed for evaluating supposedly non-hallucinatory models abilities to reason over the conversational history of knowledge-grounded dialogue systems.
37
+ """
38
+
39
+ _LICENSE = "MIT"
40
+
41
+ # The HuggingFace Datasets library doesn't host the datasets but only points to the original files.
42
+ # This can be an arbitrary nested dict/list of URLs (see below in `_split_generators` method)
43
+ _URLS = {
44
+ "eCHARP": "data/eCHARP.json",
45
+ "hCHARP": "data/hCHARP.json"
46
+ }
47
+
48
+ class CHARPDataset(datasets.GeneratorBasedBuilder):
49
+ """CHARP is a new benchmark for evaluating contextual history reasoning abilities of knowledge-grounded dialogue systems."""
50
+
51
+ VERSION = datasets.Version("1.0.0")
52
+
53
+ # This is an example of a dataset with multiple configurations.
54
+ # If you don't want/need to define several sub-sets in your dataset,
55
+ # just remove the BUILDER_CONFIG_CLASS and the BUILDER_CONFIGS attributes.
56
+
57
+ # If you need to make complex sub-parts in the datasets with configurable options
58
+ # You can create your own builder configuration class to store attribute, inheriting from datasets.BuilderConfig
59
+ # BUILDER_CONFIG_CLASS = MyBuilderConfig
60
+
61
+ # You will be able to load one or the other configurations in the following list with
62
+ # data = datasets.load_dataset('my_dataset', 'first_domain')
63
+ # data = datasets.load_dataset('my_dataset', 'second_domain')
64
+ BUILDER_CONFIGS = [
65
+ datasets.BuilderConfig(name="plain_text", version=VERSION, description="Plain text"),
66
+ ]
67
+
68
+ DEFAULT_CONFIG_NAME = (
69
+ "plain_text" # It's not mandatory to have a default configuration. Just use one if it make sense.
70
+ )
71
+
72
+ def _info(self):
73
+ features = datasets.Features(
74
+ {
75
+ "row_idx": datasets.Value("int32"),
76
+ "history": datasets.features.Sequence(datasets.Value("string")),
77
+ "knowledge": datasets.Value("string"),
78
+ "response": datasets.Value("string"),
79
+
80
+ }
81
+ )
82
+
83
+ return datasets.DatasetInfo(
84
+ # This is the description that will appear on the datasets page.
85
+ description=_DESCRIPTION,
86
+ # This defines the different columns of the dataset and their types
87
+ features=features, # Here we define them above because they are different between the two configurations
88
+ # If there's a common (input, target) tuple from the features, uncomment supervised_keys line below and
89
+ # specify them. They'll be used if as_supervised=True in builder.as_dataset.
90
+ # supervised_keys=("sentence", "label"),
91
+ # License for the dataset if available
92
+ license=_LICENSE,
93
+ # Citation for the dataset
94
+ citation=_CITATION,
95
+ )
96
+
97
+ def _split_generators(self, dl_manager):
98
+ # If several configurations are possible (listed in BUILDER_CONFIGS), the configuration selected by the user is in self.config.name
99
+
100
+ # dl_manager is a datasets.download.DownloadManager that can be used to download and extract URLS
101
+ # It can accept any type or nested list/dict and will give back the same structure with the url replaced with path to local files.
102
+ # By default the archives will be extracted and a path to a cached folder where they are extracted is returned instead of the archive
103
+ downloaded_files = dl_manager.download_and_extract(_URLS)
104
+
105
+ split_dict = {
106
+ "eCHARP": NamedSplit("eCHARP"),
107
+ "hCHARP": NamedSplit("hCHARP")
108
+ }
109
+
110
+ return [
111
+ datasets.SplitGenerator(
112
+ name=split_dict.get(split, split),
113
+ # These kwargs will be passed to _generate_examples
114
+ gen_kwargs={
115
+ "filepath": downloaded_file,
116
+ "split": split,
117
+ },
118
+ )
119
+ for split, downloaded_file in sorted(downloaded_files.items(), key=lambda x: x[0])
120
+ ]
121
+
122
+ # method parameters are unpacked from `gen_kwargs` as given in `_split_generators`
123
+ def _generate_examples(self, filepath, split):
124
+ # The `key` is for legacy reasons (tfds) and is not important in itself, but must be unique for each example.
125
+ with open(filepath, encoding="utf-8") as f:
126
+ rows = json.load(f)
127
+ print(type(rows))
128
+ key = 0
129
+ for row in rows:
130
+ print(row)
131
+ yield key, {
132
+ "row_idx": row["row_idx"],
133
+ "history": row["history"],
134
+ "knowledge": row["knowledge"],
135
+ "response": row["response"]
136
+ }
137
+ key += 1
data/eCHARP.json ADDED
The diff for this file is too large to render. See raw diff
 
data/hCHARP.json ADDED
The diff for this file is too large to render. See raw diff