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""
|
2 |
+
|
3 |
+
|
4 |
+
import json
|
5 |
+
import os
|
6 |
+
|
7 |
+
import datasets
|
8 |
+
|
9 |
+
|
10 |
+
_CITATION = """\
|
11 |
+
@misc{rangapur2023finfact,
|
12 |
+
title={Fin-Fact: A Benchmark Dataset for Multimodal Financial Fact Checking and Explanation Generation},
|
13 |
+
author={Aman Rangapur and Haoran Wang and Kai Shu},
|
14 |
+
year={2023},
|
15 |
+
eprint={2309.08793},
|
16 |
+
archivePrefix={arXiv},
|
17 |
+
primaryClass={cs.AI}
|
18 |
+
}
|
19 |
+
"""
|
20 |
+
|
21 |
+
|
22 |
+
_DESCRIPTION = """\
|
23 |
+
Welcome to the Fin-Fact repository! Fin-Fact is a comprehensive dataset designed specifically for financial fact-checking and explanation generation. The dataset consists of 3121 claims spanning multiple financial sectors.
|
24 |
+
"""
|
25 |
+
|
26 |
+
_HOMEPAGE = "https://github.com/IIT-DM/Fin-Fact"
|
27 |
+
|
28 |
+
_LICENSE = """\
|
29 |
+
MIT License
|
30 |
+
Copyright (c) 2023 Illinois Tech Data Mining Lab
|
31 |
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
32 |
+
of this software and associated documentation files (the "Software"), to deal
|
33 |
+
in the Software without restriction, including without limitation the rights
|
34 |
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
35 |
+
copies of the Software, and to permit persons to whom the Software is
|
36 |
+
furnished to do so, subject to the following conditions:
|
37 |
+
The above copyright notice and this permission notice shall be included in all
|
38 |
+
copies or substantial portions of the Software.
|
39 |
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
40 |
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
41 |
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
42 |
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
43 |
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
44 |
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
45 |
+
SOFTWARE.
|
46 |
+
"""
|
47 |
+
|
48 |
+
_URL = "https://huggingface.co/datasets/amanrangapur/Fin-Fact/resolve/main/finfact.json"
|
49 |
+
|
50 |
+
# class FinFact(datasets.GeneratorBasedBuilder):
|
51 |
+
# VERSION = datasets.Version("1.0.0")
|
52 |
+
# BUILDER_CONFIGS = [
|
53 |
+
# datasets.BuilderConfig(
|
54 |
+
# name="finfact",
|
55 |
+
# version=datasets.Version("1.0.0")
|
56 |
+
# )
|
57 |
+
# ]
|
58 |
+
|
59 |
+
# def _info(self):
|
60 |
+
# return datasets.DatasetInfo(
|
61 |
+
# description=_DESCRIPTION,
|
62 |
+
# features=datasets.Features(
|
63 |
+
# {
|
64 |
+
# "url": datasets.Value("string"),
|
65 |
+
# "claim": datasets.Value("string"),
|
66 |
+
# "author": datasets.Value("string"),
|
67 |
+
# "posted": datasets.Value("string"),
|
68 |
+
# # "justification": datasets.Value("string"),
|
69 |
+
# # "issues": datasets.Value("string"),
|
70 |
+
# # "evidence": datasets.Value("string"),
|
71 |
+
# # "summary": datasets.Value("string"),
|
72 |
+
# # "label": datasets.Value("string"),
|
73 |
+
# }
|
74 |
+
# ),
|
75 |
+
# supervised_keys=None,
|
76 |
+
# homepage=_HOMEPAGE,
|
77 |
+
# citation=_CITATION,
|
78 |
+
# license=_LICENSE,
|
79 |
+
# version=self.VERSION,
|
80 |
+
# )
|
81 |
+
|
82 |
+
# def _split_generators(self, dl_manager):
|
83 |
+
# """Returns SplitGenerators."""
|
84 |
+
# # lang = str(self.config.name)
|
85 |
+
# url = _URL.format(self.VERSION.version_str[:-2])
|
86 |
+
# data_dir = dl_manager.download_and_extract(url)
|
87 |
+
# return [
|
88 |
+
# datasets.SplitGenerator(
|
89 |
+
# name=datasets.Split.TRAIN,
|
90 |
+
# gen_kwargs={
|
91 |
+
# "filepath": os.path.join(data_dir),
|
92 |
+
# },
|
93 |
+
# )
|
94 |
+
# ]
|
95 |
+
|
96 |
+
# def _generate_examples(self, filepath):
|
97 |
+
# """Yields examples as (key, example) tuples."""
|
98 |
+
# with open(filepath, encoding="utf-8") as f:
|
99 |
+
# for idx_, row in enumerate(f):
|
100 |
+
# data = json.loads(row)
|
101 |
+
# yield idx_, {
|
102 |
+
# "url": data["url"],
|
103 |
+
# "claim": data["claim"],
|
104 |
+
# "author": data["author"],
|
105 |
+
# "posted": data["posted"],
|
106 |
+
# # "sci_digest": data["sci_digest"],
|
107 |
+
# # "justification": data["justification"],
|
108 |
+
# # "issues": data["issues"],
|
109 |
+
# # "image_data": data["image_data"],
|
110 |
+
# # "evidence": data["evidence"],
|
111 |
+
# # "label": data["label"],
|
112 |
+
# }
|
113 |
+
|
114 |
+
|
115 |
+
class Finfact(datasets.BuilderConfig):
|
116 |
+
"""BuilderConfig for Fin-Fact"""
|
117 |
+
|
118 |
+
def __init__(self, **kwargs):
|
119 |
+
"""
|
120 |
+
Args:
|
121 |
+
**kwargs: keyword arguments forwarded to super.
|
122 |
+
"""
|
123 |
+
super(Finfact, self).__init__(version=datasets.Version("1.0.0", ""), **kwargs)
|
124 |
+
|
125 |
+
|
126 |
+
class PubmedQA(datasets.GeneratorBasedBuilder):
|
127 |
+
|
128 |
+
VERSION = datasets.Version("1.0.0")
|
129 |
+
BUILDER_CONFIGS = [
|
130 |
+
datasets.BuilderConfig(
|
131 |
+
name="finfact",
|
132 |
+
version=datasets.Version("1.0.0")
|
133 |
+
)
|
134 |
+
]
|
135 |
+
|
136 |
+
def _info(self):
|
137 |
+
|
138 |
+
return datasets.DatasetInfo(
|
139 |
+
description=_DESCRIPTION,
|
140 |
+
features=datasets.Features(
|
141 |
+
{
|
142 |
+
"url": datasets.Value("string"),
|
143 |
+
"claim": datasets.Value("string"),
|
144 |
+
"author": datasets.Value("string"),
|
145 |
+
"posted": datasets.Value("string"),
|
146 |
+
}
|
147 |
+
),
|
148 |
+
supervised_keys=None,
|
149 |
+
homepage=_HOMEPAGE,
|
150 |
+
license=_LICENSE,
|
151 |
+
citation=_CITATION,
|
152 |
+
)
|
153 |
+
|
154 |
+
|
155 |
+
def _split_generators(self, dl_manager):
|
156 |
+
downloaded_files = dl_manager.download_and_extract(_URL)
|
157 |
+
return [
|
158 |
+
datasets.SplitGenerator(
|
159 |
+
name=datasets.Split.TRAIN, gen_kwargs={"filepath": downloaded_files}
|
160 |
+
)
|
161 |
+
]
|
162 |
+
# def _split_generators(self, dl_manager):
|
163 |
+
# """Returns SplitGenerators."""
|
164 |
+
# # lang = str(self.config.name)
|
165 |
+
# url = _URL.format(self.VERSION.version_str[:-2])
|
166 |
+
# data_dir = dl_manager.download_and_extract(url)
|
167 |
+
# return [
|
168 |
+
# datasets.SplitGenerator(
|
169 |
+
# name=datasets.Split.TRAIN,
|
170 |
+
# gen_kwargs={
|
171 |
+
# "filepath": os.path.join(data_dir),
|
172 |
+
# },
|
173 |
+
# )
|
174 |
+
# ]
|
175 |
+
|
176 |
+
# def _generate_examples(self, filepath):
|
177 |
+
# """Yields examples as (key, example) tuples."""
|
178 |
+
# with open(filepath, encoding="utf-8") as f:
|
179 |
+
# for idx_, row in enumerate(f):
|
180 |
+
# data = json.loads(row)
|
181 |
+
# yield idx_, {
|
182 |
+
# "url": data["url"],
|
183 |
+
# "claim": data["claim"],
|
184 |
+
# "author": data["author"],
|
185 |
+
# "posted": data["posted"],
|
186 |
+
# # "sci_digest": data["sci_digest"],
|
187 |
+
# # "justification": data["justification"],
|
188 |
+
# # "issues": data["issues"],
|
189 |
+
# # "image_data": data["image_data"],
|
190 |
+
# # "evidence": data["evidence"],
|
191 |
+
# # "label": data["label"],
|
192 |
+
# }
|
193 |
+
|
194 |
+
# def _generate_examples(self, filepath):
|
195 |
+
# with open(filepath, encoding="utf-8") as f:
|
196 |
+
# data = json.load(f)
|
197 |
+
# print(data)
|
198 |
+
# for id_, row in enumerate(data):
|
199 |
+
# print("id_", id_)
|
200 |
+
# print("row ", row)
|
201 |
+
# yield id_, {
|
202 |
+
# "url": data[row]["url"],
|
203 |
+
# "claim": data[row]["claim"],
|
204 |
+
# "author": data[row]["author"],
|
205 |
+
# "posted": data[row]["posted"],
|
206 |
+
|
207 |
+
# # "context": {
|
208 |
+
# # "contexts": data[row]["CONTEXTS"],
|
209 |
+
# # "labels": data[row]["LABELS"],
|
210 |
+
# # "meshes": data[row]["MESHES"],
|
211 |
+
# # },
|
212 |
+
# # "long_answer": data[row]["LONG_ANSWER"],
|
213 |
+
# # "final_decision": data[row]["final_decision"],
|
214 |
+
# }
|
215 |
+
|
216 |
+
def _generate_examples(self, filepath):
|
217 |
+
with open(filepath, encoding="utf-8") as f:
|
218 |
+
data = json.load(f)
|
219 |
+
for id_, row in enumerate(data):
|
220 |
+
yield id_, {
|
221 |
+
"url": row["url"],
|
222 |
+
"claim": row["claim"],
|
223 |
+
"author": row["author"],
|
224 |
+
"posted": row["posted"],
|
225 |
+
}
|