upload script
Browse files- T2Ranking.py +116 -0
T2Ranking.py
ADDED
@@ -0,0 +1,116 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
# Copyright 2020 The HuggingFace Datasets Authors and the current dataset script contributor.
|
2 |
+
#
|
3 |
+
# Licensed under the Apache License, Version 2.0 (the "License");
|
4 |
+
# you may not use this file except in compliance with the License.
|
5 |
+
# You may obtain a copy of the License at
|
6 |
+
#
|
7 |
+
# http://www.apache.org/licenses/LICENSE-2.0
|
8 |
+
#
|
9 |
+
# Unless required by applicable law or agreed to in writing, software
|
10 |
+
# distributed under the License is distributed on an "AS IS" BASIS,
|
11 |
+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
12 |
+
# See the License for the specific language governing permissions and
|
13 |
+
# limitations under the License.
|
14 |
+
# TODO: Address all TODOs and remove all explanatory comments
|
15 |
+
|
16 |
+
import datasets
|
17 |
+
import json
|
18 |
+
from typing import List
|
19 |
+
import pandas as pd
|
20 |
+
|
21 |
+
_LICENSE = "http://www.apache.org/licenses/LICENSE-2.0"
|
22 |
+
_HOMEPAGE='https://huggingface.co/datasets/THUIR/T2Ranking'
|
23 |
+
|
24 |
+
_DESCRIPTION = 'T2Ranking: A large-scale Chinese benchmark for passage retrieval.'
|
25 |
+
_CITATION = """
|
26 |
+
@article{sigir2023,
|
27 |
+
title={T2Ranking},
|
28 |
+
author={Qian Dong},
|
29 |
+
volume={2023},
|
30 |
+
number={2},
|
31 |
+
pages={99-110},
|
32 |
+
year={2022}
|
33 |
+
}
|
34 |
+
"""
|
35 |
+
|
36 |
+
_URLS_DICT = {
|
37 |
+
"collection": "data/collection.tsv",
|
38 |
+
"qrels.train": "data/qrels.train.tsv",
|
39 |
+
"queries.train": "data/queries.train.tsv",
|
40 |
+
}
|
41 |
+
|
42 |
+
_FEATURES_DICT = {
|
43 |
+
'collection': {
|
44 |
+
"pid": datasets.Value("int64"),
|
45 |
+
"text": datasets.Value("string"),
|
46 |
+
},
|
47 |
+
'qrels.train': {
|
48 |
+
"qid": datasets.Value("int64"),
|
49 |
+
"-": datasets.Value("int64"),
|
50 |
+
"pid": datasets.Value("int64"),
|
51 |
+
"rel": datasets.Value("int64"),
|
52 |
+
},
|
53 |
+
'queries.train': {
|
54 |
+
"qid": datasets.Value("int64"),
|
55 |
+
"text": datasets.Value("string"),
|
56 |
+
},
|
57 |
+
}
|
58 |
+
|
59 |
+
class T2RankingConfig(datasets.BuilderConfig):
|
60 |
+
"""BuilderConfig for T2Ranking."""
|
61 |
+
|
62 |
+
def __init__(self, splits, **kwargs):
|
63 |
+
super().__init__(version=datasets.Version("1.0.0"), **kwargs)
|
64 |
+
self.splits = splits
|
65 |
+
|
66 |
+
|
67 |
+
class T2Ranking(datasets.GeneratorBasedBuilder):
|
68 |
+
"""The T2Ranking benchmark."""
|
69 |
+
|
70 |
+
BUILDER_CONFIGS = [
|
71 |
+
T2RankingConfig(
|
72 |
+
name="collection",
|
73 |
+
splits=['train'],
|
74 |
+
),
|
75 |
+
T2RankingConfig(
|
76 |
+
name="qrels.train",
|
77 |
+
splits=['train'],
|
78 |
+
),
|
79 |
+
T2RankingConfig(
|
80 |
+
name="queries.train",
|
81 |
+
splits=['train'],
|
82 |
+
),
|
83 |
+
]
|
84 |
+
|
85 |
+
def _info(self):
|
86 |
+
return datasets.DatasetInfo(
|
87 |
+
description=_DESCRIPTION,
|
88 |
+
features=datasets.Features(_FEATURES_DICT[self.config.name]),
|
89 |
+
homepage=_HOMEPAGE,
|
90 |
+
citation=_CITATION,
|
91 |
+
license=_LICENSE,
|
92 |
+
)
|
93 |
+
|
94 |
+
def _split_generators(self, dl_manager: datasets.DownloadManager) -> List[datasets.SplitGenerator]:
|
95 |
+
split_things = []
|
96 |
+
for split_name in self.config.splits:
|
97 |
+
# print('')
|
98 |
+
split_data_path = _URLS_DICT[self.config.name]
|
99 |
+
# print(split_data_path)
|
100 |
+
filepath = dl_manager.download(split_data_path)
|
101 |
+
# print(filepath)
|
102 |
+
# print('')
|
103 |
+
split_thing = datasets.SplitGenerator(
|
104 |
+
name=datasets.Split.TRAIN,
|
105 |
+
gen_kwargs={
|
106 |
+
"filepath": filepath,
|
107 |
+
}
|
108 |
+
)
|
109 |
+
split_things.append(split_thing)
|
110 |
+
return split_things
|
111 |
+
|
112 |
+
def _generate_examples(self, filepath):
|
113 |
+
data = pd.read_csv(filepath, sep='\t')
|
114 |
+
keys = _FEATURES_DICT[self.config.name].keys()
|
115 |
+
for idx in range(data.shape[0]):
|
116 |
+
yield idx, {key: data[key][idx] for key in keys}
|