import json import datasets logger = datasets.logging.get_logger(__name__) _DESCRIPTION = """[ConceptNet with high confidence](https://home.ttic.edu/~kgimpel/commonsense.html)""" _NAME = "conceptnet_relational_similarity" _VERSION = "3.0.0" _CITATION = """ @inproceedings{li-16, title = {Commonsense Knowledge Base Completion}, author = {Xiang Li and Aynaz Taheri and Lifu Tu and Kevin Gimpel}, booktitle = {Proc. of ACL}, year = {2016} } @InProceedings{P16-1137, author = "Li, Xiang and Taheri, Aynaz and Tu, Lifu and Gimpel, Kevin", title = "Commonsense Knowledge Base Completion", booktitle = "Proceedings of the 54th Annual Meeting of the Association for Computational Linguistics (Volume 1: Long Papers) ", year = "2016", publisher = "Association for Computational Linguistics", pages = "1445--1455", location = "Berlin, Germany", doi = "10.18653/v1/P16-1137", url = "http://aclweb.org/anthology/P16-1137" } """ _HOME_PAGE = "https://github.com/asahi417/relbert" _URL = f'https://huggingface.co/datasets/relbert/conceptnet/resolve/main/dataset' _URLS = { str(datasets.Split.TRAIN): [f'{_URL}/train.jsonl'], str(datasets.Split.VALIDATION): [f'{_URL}/valid.jsonl'], str(datasets.Split.TEST): [f'{_URL}/test.jsonl'], } class ConceptNetRelationalSimilarityConfig(datasets.BuilderConfig): """BuilderConfig""" def __init__(self, **kwargs): """BuilderConfig. Args: **kwargs: keyword arguments forwarded to super. """ super(ConceptNetRelationalSimilarityConfig, self).__init__(**kwargs) class ConceptNetRelationalSimilarity(datasets.GeneratorBasedBuilder): """Dataset.""" BUILDER_CONFIGS = [ ConceptNetRelationalSimilarityConfig(name=_NAME, version=datasets.Version(_VERSION), description=_DESCRIPTION), ] def _split_generators(self, dl_manager): downloaded_file = dl_manager.download_and_extract(_URLS) return [datasets.SplitGenerator(name=i, gen_kwargs={"filepaths": downloaded_file[i]}) for i in _URLS.keys()] def _generate_examples(self, filepaths): _key = 0 for filepath in filepaths: logger.info(f"generating examples from = {filepath}") with open(filepath, encoding="utf-8") as f: _list = [i for i in f.read().split('\n') if len(i) > 0] for i in _list: data = json.loads(i) yield _key, data _key += 1 def _info(self): return datasets.DatasetInfo( description=_DESCRIPTION, features=datasets.Features( { "relation_type": datasets.Value("string"), "positives": datasets.Sequence(datasets.Sequence(datasets.Value("string"))), "negatives": datasets.Sequence(datasets.Sequence(datasets.Value("string"))), } ), supervised_keys=None, homepage=_HOME_PAGE, citation=_CITATION, )