"""Fin-Fact dataset.""" import json import os import datasets _CITATION = """\ @misc{rangapur2023finfact, title={Fin-Fact: A Benchmark Dataset for Multimodal Financial Fact Checking and Explanation Generation}, author={Aman Rangapur and Haoran Wang and Kai Shu}, year={2023}, eprint={2309.08793}, archivePrefix={arXiv}, primaryClass={cs.AI} } """ _DESCRIPTION = """\ 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. """ _HOMEPAGE = "https://github.com/IIT-DM/Fin-Fact" _LICENSE = """\ MIT License Copyright (c) 2023 Illinois Tech Data Mining Lab Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. """ _URL = "https://huggingface.co/datasets/amanrangapur/Fin-Fact/resolve/main/finfact.json" # class FinFact(datasets.GeneratorBasedBuilder): # VERSION = datasets.Version("1.0.0") # BUILDER_CONFIGS = [ # datasets.BuilderConfig( # name="finfact", # version=datasets.Version("1.0.0") # ) # ] # def _info(self): # return datasets.DatasetInfo( # description=_DESCRIPTION, # features=datasets.Features( # { # "url": datasets.Value("string"), # "claim": datasets.Value("string"), # "author": datasets.Value("string"), # "posted": datasets.Value("string"), # # "justification": datasets.Value("string"), # # "issues": datasets.Value("string"), # # "evidence": datasets.Value("string"), # # "summary": datasets.Value("string"), # # "label": datasets.Value("string"), # } # ), # supervised_keys=None, # homepage=_HOMEPAGE, # citation=_CITATION, # license=_LICENSE, # version=self.VERSION, # ) # def _split_generators(self, dl_manager): # """Returns SplitGenerators.""" # # lang = str(self.config.name) # url = _URL.format(self.VERSION.version_str[:-2]) # data_dir = dl_manager.download_and_extract(url) # return [ # datasets.SplitGenerator( # name=datasets.Split.TRAIN, # gen_kwargs={ # "filepath": os.path.join(data_dir), # }, # ) # ] # def _generate_examples(self, filepath): # """Yields examples as (key, example) tuples.""" # with open(filepath, encoding="utf-8") as f: # for idx_, row in enumerate(f): # data = json.loads(row) # yield idx_, { # "url": data["url"], # "claim": data["claim"], # "author": data["author"], # "posted": data["posted"], # # "sci_digest": data["sci_digest"], # # "justification": data["justification"], # # "issues": data["issues"], # # "image_data": data["image_data"], # # "evidence": data["evidence"], # # "label": data["label"], # } class Finfact(datasets.BuilderConfig): """BuilderConfig for Fin-Fact""" def __init__(self, **kwargs): """ Args: **kwargs: keyword arguments forwarded to super. """ super(Finfact, self).__init__(version=datasets.Version("1.0.0", ""), **kwargs) class PubmedQA(datasets.GeneratorBasedBuilder): VERSION = datasets.Version("1.0.0") BUILDER_CONFIGS = [ datasets.BuilderConfig( name="finfact", version=datasets.Version("1.0.0") ) ] def _info(self): return datasets.DatasetInfo( description=_DESCRIPTION, features=datasets.Features( { "url": datasets.Value("string"), "claim": datasets.Value("string"), "author": datasets.Value("string"), "posted": datasets.Value("string"), } ), supervised_keys=None, homepage=_HOMEPAGE, license=_LICENSE, citation=_CITATION, ) def _split_generators(self, dl_manager): downloaded_files = dl_manager.download_and_extract(_URL) return [ datasets.SplitGenerator( name=datasets.Split.TRAIN, gen_kwargs={"filepath": downloaded_files} ) ] # def _split_generators(self, dl_manager): # """Returns SplitGenerators.""" # # lang = str(self.config.name) # url = _URL.format(self.VERSION.version_str[:-2]) # data_dir = dl_manager.download_and_extract(url) # return [ # datasets.SplitGenerator( # name=datasets.Split.TRAIN, # gen_kwargs={ # "filepath": os.path.join(data_dir), # }, # ) # ] # def _generate_examples(self, filepath): # """Yields examples as (key, example) tuples.""" # with open(filepath, encoding="utf-8") as f: # for idx_, row in enumerate(f): # data = json.loads(row) # yield idx_, { # "url": data["url"], # "claim": data["claim"], # "author": data["author"], # "posted": data["posted"], # # "sci_digest": data["sci_digest"], # # "justification": data["justification"], # # "issues": data["issues"], # # "image_data": data["image_data"], # # "evidence": data["evidence"], # # "label": data["label"], # } # def _generate_examples(self, filepath): # with open(filepath, encoding="utf-8") as f: # data = json.load(f) # print(data) # for id_, row in enumerate(data): # print("id_", id_) # print("row ", row) # yield id_, { # "url": data[row]["url"], # "claim": data[row]["claim"], # "author": data[row]["author"], # "posted": data[row]["posted"], # # "context": { # # "contexts": data[row]["CONTEXTS"], # # "labels": data[row]["LABELS"], # # "meshes": data[row]["MESHES"], # # }, # # "long_answer": data[row]["LONG_ANSWER"], # # "final_decision": data[row]["final_decision"], # } def _generate_examples(self, filepath): with open(filepath, encoding="utf-8") as f: data = json.load(f) for id_, row in enumerate(data): yield id_, { "url": row["url"], "claim": row["claim"], "author": row["author"], "posted": row["posted"], }