| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| """ 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') |
|
|
| |
|
|
| 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) |
|
|