Datasets:

Modalities:
Tabular
Text
Languages:
Chinese
ArXiv:
Libraries:
Datasets
License:
T2Ranking / T2Ranking.py
qian's picture
fix bug
40212e9
raw
history blame
No virus
3.55 kB
# Copyright 2020 The HuggingFace Datasets Authors and the current dataset script contributor.
#
# 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.
# TODO: Address all TODOs and remove all explanatory comments
import datasets
import json
from typing import List
import pandas as pd
_LICENSE = "http://www.apache.org/licenses/LICENSE-2.0"
_HOMEPAGE='https://huggingface.co/datasets/THUIR/T2Ranking'
_DESCRIPTION = 'T2Ranking: A large-scale Chinese benchmark for passage retrieval.'
_CITATION = """
@article{sigir2023,
title={T2Ranking},
author={Qian Dong},
volume={2023},
number={2},
pages={99-110},
year={2022}
}
"""
_URLS_DICT = {
"collection": "data/collection.tsv",
"qrels.train": "data/qrels.train.tsv",
"queries.train": "data/queries.train.tsv",
}
_FEATURES_DICT = {
'collection': {
"pid": datasets.Value("int64"),
"text": datasets.Value("string"),
},
'qrels.train': {
"qid": datasets.Value("int64"),
"-": datasets.Value("int64"),
"pid": datasets.Value("int64"),
"rel": datasets.Value("int64"),
},
'queries.train': {
"qid": datasets.Value("int64"),
"text": datasets.Value("string"),
},
}
class T2RankingConfig(datasets.BuilderConfig):
"""BuilderConfig for T2Ranking."""
def __init__(self, splits, **kwargs):
super().__init__(version=datasets.Version("1.0.0"), **kwargs)
self.splits = splits
class T2Ranking(datasets.GeneratorBasedBuilder):
"""The T2Ranking benchmark."""
BUILDER_CONFIGS = [
T2RankingConfig(
name="collection",
splits=['train'],
),
T2RankingConfig(
name="qrels.train",
splits=['train'],
),
T2RankingConfig(
name="queries.train",
splits=['train'],
),
]
def _info(self):
return datasets.DatasetInfo(
description=_DESCRIPTION,
features=datasets.Features(_FEATURES_DICT[self.config.name]),
homepage=_HOMEPAGE,
citation=_CITATION,
license=_LICENSE,
)
def _split_generators(self, dl_manager: datasets.DownloadManager) -> List[datasets.SplitGenerator]:
split_things = []
for split_name in self.config.splits:
# print('')
split_data_path = _URLS_DICT[self.config.name]
# print(split_data_path)
filepath = dl_manager.download(split_data_path)
# print(filepath)
# print('')
split_thing = datasets.SplitGenerator(
name=datasets.Split.TRAIN,
gen_kwargs={
"filepath": filepath,
}
)
split_things.append(split_thing)
return split_things
def _generate_examples(self, filepath):
data = pd.read_csv(filepath, sep='\t', quoting=3)
keys = _FEATURES_DICT[self.config.name].keys()
for idx in range(data.shape[0]):
yield idx, {key: data[key][idx] for key in keys}