notrichardren commited on
Commit
fa8bd9d
·
1 Parent(s): 3c4a58b

Upload 2 files

Browse files
Files changed (2) hide show
  1. easy_facts.csv +0 -0
  2. easy_qa.py +105 -0
easy_facts.csv ADDED
The diff for this file is too large to render. See raw diff
 
easy_qa.py ADDED
@@ -0,0 +1,105 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # Copyright 2020 The HuggingFace Datasets Authors and the current dataset script contributor.
2
+ #
3
+ # Licensed under the Apache License, Version 2.0 (the "License");
4
+ # you may not use this file except in compliance with the License.
5
+ # You may obtain a copy of the License at
6
+ #
7
+ # http://www.apache.org/licenses/LICENSE-2.0
8
+ #
9
+ # Unless required by applicable law or agreed to in writing, software
10
+ # distributed under the License is distributed on an "AS IS" BASIS,
11
+ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12
+ # See the License for the specific language governing permissions and
13
+ # limitations under the License.
14
+
15
+ # Code here based on TruthfulQA code: https://huggingface.co/datasets/truthful_qa/blob/main/truthful_qa.py
16
+
17
+ import csv
18
+ import datasets
19
+ from datasets import load_dataset
20
+
21
+ _DESCRIPTION = """\
22
+ EasyQA is a GPT-3.5-turbo-generated dataset of easy kindergarten-level facts, meant to be used to prompt and evaluate large language models for "common sense" truthful responses. It was originally created to understand how different types of truthfulness may be represented in the intermediate activations of large language models. EasyQA compromises 2346 questions that span 50 categories, including art, technology, education, music, and animals. Questions are crafted to be extremely simple and obvious, eliciting an obvious truth that would not be susceptible to misconceptions.
23
+ """
24
+
25
+ _LICENSE = "Apache License 2.0"
26
+
27
+ _HOMEPAGE = "https://huggingface.co/datasets/notrichardren/easy_qa"
28
+
29
+ _CITATION = """\
30
+ @misc{ez_QA,
31
+ title={EasyQA: A Kindergarten-Level QA Benchmark},
32
+ author={Kevin Wang and Richard Ren and Phillip Guo},
33
+ year={2023},
34
+ }
35
+ """
36
+
37
+ class TruthfulQaConfig(datasets.BuilderConfig):
38
+
39
+ def __init__(self, url, features, **kwargs):
40
+ super().__init__(version=datasets.Version("1.1.0"), **kwargs)
41
+ self.url = url
42
+ self.features = features
43
+
44
+ class TruthfulQa(datasets.GeneratorBasedBuilder):
45
+ """TruthfulQA is a benchmark to measure whether a language model is truthful in generating answers to questions."""
46
+
47
+ BUILDER_CONFIGS = [
48
+ TruthfulQaConfig(
49
+ name="easy_qa",
50
+ url="easy_facts.csv",
51
+ features=datasets.Features(
52
+ {
53
+ "question": datasets.Value("string"),
54
+ "right_answer": datasets.Value("string"),
55
+ "wrong_answer": datasets.Value("string"),
56
+ "category": datasets.Value("string"),
57
+ }
58
+ ),
59
+ description="easy_qa",
60
+ )
61
+ ]
62
+
63
+ def _info(self):
64
+ return datasets.DatasetInfo(
65
+ description=_DESCRIPTION,
66
+ features=self.config.features,
67
+ homepage=_HOMEPAGE,
68
+ license=_LICENSE,
69
+ citation=_CITATION,
70
+ )
71
+
72
+ def _split_generators(self, dl_manager):
73
+ data_dir = dl_manager.download(self.config.url)
74
+ return [
75
+ datasets.SplitGenerator(
76
+ name=datasets.Split.VALIDATION,
77
+ gen_kwargs={
78
+ "filepath": data_dir,
79
+ },
80
+ ),
81
+ ]
82
+
83
+ def _split_csv_list(self, csv_list: str, delimiter: str = ";") -> str:
84
+ """
85
+ Splits a csv list field, delimited by `delimiter` (';'), into a list
86
+ of strings.
87
+ """
88
+ csv_list = csv_list.strip().split(delimiter)
89
+ return [item.strip() for item in csv_list]
90
+
91
+ def _generate_examples(self, filepath):
92
+ # Generation data is in a `CSV` file.
93
+ with open(filepath, newline="", encoding="utf-8-sig") as f:
94
+ contents = csv.DictReader(f)
95
+ for key, row in enumerate(contents):
96
+ # Ensure that references exist.
97
+ row
98
+ if not row["Right"] or not row["Wrong"]:
99
+ continue
100
+ yield key, {
101
+ "question": row["Question"],
102
+ "right_answer": row["Right"],
103
+ "wrong_answer": row["Wrong"],
104
+ "category": row["Category"],
105
+ }