Datasets:

Languages:
Chinese
ArXiv:
License:
File size: 3,547 Bytes
e54c647
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
40212e9
e54c647
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
# 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}