| | from datasets import DatasetDict, load_dataset, SplitGenerator, Split |
| | import datasets |
| | import json |
| |
|
| | _Base_url = "https://huggingface.co/datasets/Arabic-Clip/xtd_11/resolve/main/test/" |
| | _Languages = ["ar", "de", "en", "es", "fr", "jp", "ko", "pl", "ru", "tr", "zh"] |
| |
|
| | class XTD_11Config(datasets.BuilderConfig): |
| | """ Builder config for Joud Dataset. """ |
| |
|
| | def __init__(self, subset, **kwargs): |
| | super(XTD_11Config, self).__init__(**kwargs) |
| |
|
| | if subset !="all": |
| | |
| | self.subset = [subset] |
| | else: |
| | self.subset = _Languages |
| |
|
| | |
| | class XTD_11(datasets.GeneratorBasedBuilder): |
| | VERSION = datasets.Version("1.0.0") |
| | BUILDER_CONFIGS_CLASS = XTD_11Config |
| | BUILDER_CONFIGS = [ |
| | XTD_11Config(name=subset, |
| | subset=subset, |
| | version=datasets.Version("1.1.0", ""), |
| | description='') |
| | for subset in _Languages |
| | ] + [ |
| | XTD_11Config( |
| | name = "all", |
| | subset="all", |
| | version=datasets.Version("1.1.0", ""), |
| | description='') |
| | ] |
| | def _info(self): |
| | |
| | return datasets.DatasetInfo( |
| | |
| | features=datasets.Features({ |
| | "text": datasets.Value("string"), |
| | "image_name": datasets.Value("string"), |
| | "url": datasets.Value("string"), |
| | }), |
| | description="A benchmark to test model capability in image retrieval named xtd.", |
| | ) |
| |
|
| | def _split_generators(self, dl_manager): |
| | """Returns SplitGenerators.""" |
| | |
| | data_urls = [f"{_Base_url}{lang}.json" for lang in self.config.subset] |
| | |
| | |
| | return [datasets.SplitGenerator( |
| | name=datasets.Split.TEST, |
| | |
| | gen_kwargs={"filepaths": dl_manager.download(data_urls)} |
| | )] |
| | |
| | |
| |
|
| | def _generate_examples(self, filepaths=None): |
| | """Yields examples.""" |
| | |
| | |
| | id_ = 0 |
| | for filepath in filepaths: |
| | |
| | with open(filepath, encoding="utf-8") as f: |
| | for row in f: |
| | if row: |
| | |
| | data = json.loads(row) |
| | yield id_, data |
| | id_ +=1 |
| |
|