File size: 3,045 Bytes
f63efd0
 
 
 
 
876637e
0452bba
f63efd0
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
c669ea0
f63efd0
 
 
8748528
f63efd0
 
 
876637e
f63efd0
 
 
 
 
 
 
876637e
f63efd0
 
876637e
f63efd0
 
 
876637e
f63efd0
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
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.1"
_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/{_NAME}/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,
        )