Datasets:

Modalities:
Tabular
Text
Languages:
English
ArXiv:
Libraries:
Datasets
License:
File size: 5,369 Bytes
f25f5f1
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
95e4d2d
 
 
 
f25f5f1
 
 
 
 
 
 
 
fcfa82f
f25f5f1
 
fcfa82f
f25f5f1
 
fcfa82f
f25f5f1
 
 
 
 
 
 
 
 
 
707a3fe
f25f5f1
 
 
 
fcfa82f
 
f25f5f1
f266587
f25f5f1
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
33bc2f5
be43cd2
d4b4724
 
 
 
 
 
 
 
 
 
be43cd2
f25f5f1
33bc2f5
be43cd2
 
d4b4724
be43cd2
f25f5f1
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
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
# coding=utf-8
# Copyright 2020 The TensorFlow Datasets Authors and the HuggingFace Datasets Authors.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
#     http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

# Lint as: python3
"""COMPS: Conceptual Minimal Pair Sentences for analyzing property knowledge."""

import json

import datasets


_CITATION = """
@article{misra2022comps,
  title={COMPS: Conceptual Minimal Pair Sentences for testing Property Knowledge and Inheritance in Pre-trained Language Models},
  author={Misra, Kanishka and Rayz, Julia Taylor and Ettinger, Allyson},
  journal={arXiv preprint arXiv:2210.01963},
  year={2022}
}
"""

_DESCRIPTION = """
COMPS is a dataset of minimal pair sentences in English that enables the 
testing knowledge of concepts and their properties in language models (LMs).
Specifically, it tests the ability of LMs to attribute properties to everyday 
concepts, and demonstrate reasoning compatible with property inheritance, where
subordinate concepts inherit the properties of their superordinate (hypernyms).
"""

_PROJECT_URL = "https://github.com/kanishkamisra/comps"
_DOWNLOAD_URL = "https://raw.githubusercontent.com/kanishkamisra/comps/main/" \
    "data/comps/"


class CompsConfig(datasets.BuilderConfig):
    """BuilderConfig for COMPS."""

    def __init__(self, name, version=datasets.Version("0.1.0"), **kwargs):
        """BuilderConfig for COMPS.

        Args:
          name (str): subset id
          **kwargs: keyword arguments forwarded to super.
        """
        description = _DESCRIPTION
        if name == "base":
            description += " This subset tests for base property knowledge."
        elif name == "wugs":
            description += " This subset tests for property inheritance" \
                " without distraction."
        else:
            description += " This subset tests for property inheritance with" \
                 f" distraction ({name.replace('wugs-dist-', '')})."

        super().__init__(name=name, description=description, version=version, **kwargs)


class Comps(datasets.GeneratorBasedBuilder):
    """Minimal pairs to analyze property knowledge."""

    subsets = ("base", "wugs", "wugs_dist", "wugs_dist-before", "wugs_dist-in-between")

    BUILDER_CONFIGS = [CompsConfig(subset) for subset in subsets]

    def _info(self):
        return datasets.DatasetInfo(
            description=_DESCRIPTION,
            features=datasets.Features(
                {
                    "id": datasets.Value("int32"),
                    "property": datasets.Value("string"),
                    "acceptable_concept": datasets.Value("string"),
                    "unacceptable_concept": datasets.Value("string"),
                    "prefix_acceptable": datasets.Value("string"),
                    "prefix_unacceptable": datasets.Value("string"),
                    "property_phrase": datasets.Value("string"),
                    "negative_sample_type": datasets.Value("string"),
                    "similarity": datasets.Value("float32"),
                    "distraction_type": datasets.Value("string"),
                }
            ),
            homepage=_PROJECT_URL,
            citation=_CITATION,
        )

    def _split_generators(self, dl_manager):
        """Returns SplitGenerators."""
        download_urls = _DOWNLOAD_URL + f"comps_{self.config.name}.jsonl"
        downloaded_file = dl_manager.download_and_extract(download_urls)
        return [datasets.SplitGenerator(name=datasets.Split.TRAIN, gen_kwargs={"filepath": downloaded_file})]

    def _generate_examples(self, filepath):
        """Yields examples."""
        with open(filepath, "r", encoding="utf-8") as f:
            for line in f:
                line_dict = json.loads(line)
                if "wugs" in self.config.name:
                    id_ = str(line_dict["base_id"]) + "_" + line_dict["distraction_type"]
                    feats = {
                        "id": line_dict["id"],
                        "property": line_dict["property"],
                        "acceptable_concept": line_dict["acceptable_concept"],
                        "unacceptable_concept": line_dict["unacceptable_concept"],
                        "prefix_acceptable": line_dict["prefix_acceptable"],
                        "prefix_unacceptable": line_dict["prefix_unacceptable"],
                        "property_phrase": line_dict["property_phrase"],
                        "negative_sample_type": line_dict["negative_sample_type"],
                        "similarity": line_dict["similarity"],
                        "distraction_type": line_dict["distraction_type"],
                    }
                else:
                    id_ = str(line_dict['id'])
                    feats = {
                        **line_dict,
                        "distraction_type": "None"
                    }
                yield id_, feats