Commit
·
398379d
1
Parent(s):
b273902
Create hc4
Browse files
hc4
ADDED
|
@@ -0,0 +1,103 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# coding=utf-8
|
| 2 |
+
# Copyright 2020 The HuggingFace Datasets Authors and the current dataset script contributor.
|
| 3 |
+
#
|
| 4 |
+
# Licensed under the Apache License, Version 2.0 (the 'License');
|
| 5 |
+
# you may not use this file except in compliance with the License.
|
| 6 |
+
# You may obtain a copy of the License at
|
| 7 |
+
#
|
| 8 |
+
# http://www.apache.org/licenses/LICENSE-2.0
|
| 9 |
+
#
|
| 10 |
+
# Unless required by applicable law or agreed to in writing, software
|
| 11 |
+
# distributed under the License is distributed on an 'AS IS' BASIS,
|
| 12 |
+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
| 13 |
+
# See the License for the specific language governing permissions and
|
| 14 |
+
# limitations under the License.
|
| 15 |
+
|
| 16 |
+
# Lint as: python3
|
| 17 |
+
|
| 18 |
+
import json
|
| 19 |
+
|
| 20 |
+
import datasets
|
| 21 |
+
|
| 22 |
+
_CITATION = '''
|
| 23 |
+
@article{Lawrie2022HC4,
|
| 24 |
+
author = {Dawn Lawrie and James Mayfield and Douglas W. Oard and Eugene Yang},
|
| 25 |
+
title = {HC4: A New Suite of Test Collections for Ad Hoc CLIR},
|
| 26 |
+
booktitle = {{Advances in Information Retrieval. 44th European Conference on IR Research (ECIR 2022)},
|
| 27 |
+
year = {2022},
|
| 28 |
+
month = apr,
|
| 29 |
+
publisher = {Springer},
|
| 30 |
+
series = {Lecture Notes in Computer Science},
|
| 31 |
+
site = {Stavanger, Norway},
|
| 32 |
+
url = {https://arxiv.org/abs/2201.09992}
|
| 33 |
+
}
|
| 34 |
+
'''
|
| 35 |
+
|
| 36 |
+
|
| 37 |
+
import ir_datasets
|
| 38 |
+
|
| 39 |
+
langs = ['fa', 'ru', 'zh']
|
| 40 |
+
fields = ['title', 'desc', 'title_desc']
|
| 41 |
+
lang_fields = [f'{lang}-{field}' for lang in langs for field in fields]
|
| 42 |
+
|
| 43 |
+
_DESCRIPTION = 'dataset load script for HC4'
|
| 44 |
+
|
| 45 |
+
|
| 46 |
+
class HC4(datasets.GeneratorBasedBuilder):
|
| 47 |
+
BUILDER_CONFIGS = [datasets.BuilderConfig(
|
| 48 |
+
version=datasets.Version('1.0.0'),
|
| 49 |
+
name=lf, description=f'HC4: {lf}.'
|
| 50 |
+
) for lf in lang_fields
|
| 51 |
+
]
|
| 52 |
+
|
| 53 |
+
def _info(self):
|
| 54 |
+
features = datasets.Features({
|
| 55 |
+
'query_id': datasets.Value('string'),
|
| 56 |
+
'query': datasets.Value('string'),
|
| 57 |
+
})
|
| 58 |
+
|
| 59 |
+
return datasets.DatasetInfo(
|
| 60 |
+
# This is the description that will appear on the datasets page.
|
| 61 |
+
description=_DESCRIPTION,
|
| 62 |
+
# This defines the different columns of the dataset and their types
|
| 63 |
+
features=features, # Here we define them above because they are different between the two configurations
|
| 64 |
+
supervised_keys=None,
|
| 65 |
+
# Homepage of the dataset for documentation
|
| 66 |
+
homepage='https://github.com/hltcoe/HC4',
|
| 67 |
+
# License for the dataset if available
|
| 68 |
+
license='',
|
| 69 |
+
# Citation for the dataset
|
| 70 |
+
citation=_CITATION,
|
| 71 |
+
)
|
| 72 |
+
|
| 73 |
+
def _split_generators(self, dl_manager):
|
| 74 |
+
lang_field = self.config.name
|
| 75 |
+
splits = [
|
| 76 |
+
datasets.SplitGenerator(
|
| 77 |
+
name=set_name,
|
| 78 |
+
gen_kwargs={
|
| 79 |
+
'lang_field': lang_field,
|
| 80 |
+
'set_name': set_name,
|
| 81 |
+
},
|
| 82 |
+
) for set_name in ['dev', 'test']
|
| 83 |
+
]
|
| 84 |
+
return splits
|
| 85 |
+
|
| 86 |
+
def _generate_examples(self, lang_field, set_name):
|
| 87 |
+
lang, field = lang_field.split('-')
|
| 88 |
+
|
| 89 |
+
if lang not in lang:
|
| 90 |
+
raise ValueError(f"Unexpected language: {lang}")
|
| 91 |
+
if field not in fields:
|
| 92 |
+
raise ValueError(f"Unexpected field: {field}")
|
| 93 |
+
|
| 94 |
+
dataset = ir_datasets.load(f'hc4/{lang}/{set_name}')
|
| 95 |
+
for query in dataset.queries_iter():
|
| 96 |
+
# all are English Questions
|
| 97 |
+
if field == 'title':
|
| 98 |
+
q = query.title
|
| 99 |
+
elif field == "desc":
|
| 100 |
+
q = query.description
|
| 101 |
+
else:
|
| 102 |
+
q = f"{query.title} {query.description}"
|
| 103 |
+
yield query.query_id, {'query_id': query.query_id, 'query': q}
|