Xueguang Ma
commited on
Commit
·
bfaf025
1
Parent(s):
75f32b3
add script
Browse files
beir.py
ADDED
|
@@ -0,0 +1,113 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 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 |
+
@inproceedings{
|
| 24 |
+
thakur2021beir,
|
| 25 |
+
title={{BEIR}: A Heterogeneous Benchmark for Zero-shot Evaluation of Information Retrieval Models},
|
| 26 |
+
author={Nandan Thakur and Nils Reimers and Andreas R{\"u}ckl{\'e} and Abhishek Srivastava and Iryna Gurevych},
|
| 27 |
+
booktitle={Thirty-fifth Conference on Neural Information Processing Systems Datasets and Benchmarks Track (Round 2)},
|
| 28 |
+
year={2021},
|
| 29 |
+
url={https://openreview.net/forum?id=wCu6T5xFjeJ}
|
| 30 |
+
}
|
| 31 |
+
'''
|
| 32 |
+
|
| 33 |
+
all_data = [
|
| 34 |
+
'arguana',
|
| 35 |
+
'climate-fever',
|
| 36 |
+
'cqadupstack-android',
|
| 37 |
+
'cqadupstack-english',
|
| 38 |
+
'cqadupstack-gaming',
|
| 39 |
+
'cqadupstack-gis',
|
| 40 |
+
'cqadupstack-mathematica',
|
| 41 |
+
'cqadupstack-physics',
|
| 42 |
+
'cqadupstack-programmers',
|
| 43 |
+
'cqadupstack-stats',
|
| 44 |
+
'cqadupstack-tex',
|
| 45 |
+
'cqadupstack-unix',
|
| 46 |
+
'cqadupstack-webmasters',
|
| 47 |
+
'cqadupstack-wordpress',
|
| 48 |
+
'dbpedia-entity',
|
| 49 |
+
'fever',
|
| 50 |
+
'fiqa',
|
| 51 |
+
'hotpotqa',
|
| 52 |
+
'nfcorpus',
|
| 53 |
+
'quora',
|
| 54 |
+
'scidocs',
|
| 55 |
+
'scifact',
|
| 56 |
+
'trec-covid',
|
| 57 |
+
'webis-touche2020'
|
| 58 |
+
]
|
| 59 |
+
|
| 60 |
+
_DESCRIPTION = 'dataset load script for BEIR'
|
| 61 |
+
|
| 62 |
+
_DATASET_URLS = {
|
| 63 |
+
data: {
|
| 64 |
+
'test': f'https://huggingface.co/datasets/Tevatron/beir/resolve/main/{data}.jsonl',
|
| 65 |
+
} for data in all_data
|
| 66 |
+
}
|
| 67 |
+
|
| 68 |
+
class BEIR(datasets.GeneratorBasedBuilder):
|
| 69 |
+
BUILDER_CONFIGS = [datasets.BuilderConfig(
|
| 70 |
+
version=datasets.Version('1.0.0'),
|
| 71 |
+
name=data, description=f'BEIR dataset: {data}.'
|
| 72 |
+
) for data in all_data
|
| 73 |
+
]
|
| 74 |
+
|
| 75 |
+
def _info(self):
|
| 76 |
+
features = datasets.Features({
|
| 77 |
+
'query_id': datasets.Value('string'),
|
| 78 |
+
'query': datasets.Value('string'),
|
| 79 |
+
})
|
| 80 |
+
|
| 81 |
+
return datasets.DatasetInfo(
|
| 82 |
+
# This is the description that will appear on the datasets page.
|
| 83 |
+
description=_DESCRIPTION,
|
| 84 |
+
# This defines the different columns of the dataset and their types
|
| 85 |
+
features=features, # Here we define them above because they are different between the two configurations
|
| 86 |
+
supervised_keys=None,
|
| 87 |
+
# Homepage of the dataset for documentation
|
| 88 |
+
homepage='https://github.com/beir-cellar/beir',
|
| 89 |
+
# License for the dataset if available
|
| 90 |
+
license='',
|
| 91 |
+
# Citation for the dataset
|
| 92 |
+
citation=_CITATION,
|
| 93 |
+
)
|
| 94 |
+
|
| 95 |
+
def _split_generators(self, dl_manager):
|
| 96 |
+
lang = self.config.name
|
| 97 |
+
downloaded_files = dl_manager.download_and_extract(_DATASET_URLS[lang])
|
| 98 |
+
splits = [
|
| 99 |
+
datasets.SplitGenerator(
|
| 100 |
+
name='test',
|
| 101 |
+
gen_kwargs={
|
| 102 |
+
'filepath': downloaded_files['test'],
|
| 103 |
+
},
|
| 104 |
+
),
|
| 105 |
+
]
|
| 106 |
+
return splits
|
| 107 |
+
|
| 108 |
+
def _generate_examples(self, filepath):
|
| 109 |
+
with open(filepath) as f:
|
| 110 |
+
for i, line in enumerate(f):
|
| 111 |
+
data = json.loads(line)
|
| 112 |
+
qid = data['query_id']
|
| 113 |
+
yield qid, data
|