Datasets:

Languages:
English
ArXiv:
Libraries:
Datasets
License:
File size: 3,840 Bytes
992a451
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
a691b0e
 
 
 
 
 
 
992a451
 
 
 
 
 
a691b0e
 
 
 
 
 
 
 
992a451
 
 
a691b0e
992a451
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
3f10eea
992a451
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
# Copyright 2021 Cory Paik. All Rights Reserved.
#
# 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.
# ==============================================================================
""" The Color Dataset (CoDa)

CoDa is a probing dataset to evaluate the representation of visual properties
in language models. CoDa consists of color distributions for 521 common
objects, which are split into 3 groups: Single, Multi, and Any.

The default configuration of CoDa uses 10 CLIP-style templates (e.g. "A photo
of a ___"), and 10 cloze-style templates (e.g. "Everyone knows most ___ are
___." )
"""
import json

import datasets

_CITATION = """\
@misc{paik2021world,
      title={The World of an Octopus: How Reporting Bias Influences a Language Model's Perception of Color},
      author={Cory Paik and Stéphane Aroca-Ouellette and Alessandro Roncone and Katharina Kann},
      year={2021},
      eprint={2110.08182},
      archivePrefix={arXiv},
      primaryClass={cs.CL}
}
"""

_DESCRIPTION = """\
*The Color Dataset* (CoDa) is a probing dataset to evaluate the representation of visual properties in language models. CoDa consists of color distributions for 521 common objects, which are split into 3 groups: Single, Multi, and Any.
"""

_HOMEPAGE = 'https://github.com/nala-cub/coda'
_LICENSE = 'Apache 2.0'

_URL = 'https://huggingface.co/datasets/corypaik/coda/resolve/main/data'

_URLs = {
    'default': {
        'train': f'{_URL}/default_train.jsonl',
        'validation': f'{_URL}/default_validation.jsonl',
        'test': f'{_URL}/default_test.jsonl',
    }
}


class Coda(datasets.GeneratorBasedBuilder):

  VERSION = datasets.Version('1.0.1')

  # TODO(corypaik): add object and annotation configs.

  def _info(self):
    features = datasets.Features({
        'class_id':
            datasets.Value('string'),
        'display_name':
            datasets.Value('string'),
        'ngram':
            datasets.Value('string'),
        'label':
            datasets.Sequence(datasets.Value('float')),
        'object_group':
            datasets.ClassLabel(names=('Single', 'Multi', 'Any')),
        'text':
            datasets.Value('string'),
        'template_group':
            datasets.ClassLabel(names=('clip-imagenet', 'text-masked')),
        'template_idx':
            datasets.Value('int32')
    })
    return datasets.DatasetInfo(description=_DESCRIPTION,
                                features=features,
                                supervised_keys=None,
                                homepage=_HOMEPAGE,
                                license=_LICENSE,
                                citation=_CITATION)

  def _split_generators(self, dl_manager):
    """ Returns SplitGenerators."""
    files = dl_manager.download_and_extract(_URLs[self.config.name])
    return [
        datasets.SplitGenerator(datasets.Split.TRAIN,
                                gen_kwargs={'path': files['train']}),
        datasets.SplitGenerator(datasets.Split.VALIDATION,
                                gen_kwargs={'path': files['validation']}),
        datasets.SplitGenerator(datasets.Split.TEST,
                                gen_kwargs={'path': files['test']}),
    ]

  def _generate_examples(self, path):
    with open(path, 'r') as f:
      for _id, line in enumerate(f.readlines()):
        yield _id, json.loads(line)