CoolFace
Datasetpublic

CogComp/trec

The Text REtrieval Conference (TREC) Question Classification dataset contains 5500 labeled questions in training set and another 500 for test set. The dataset has 6 coarse class labels and 50 fine class labels. Average length of each sentence is 10, vocabulary size of 8700. Data are collected from four sources: 4,500 English questions published by USC (Hovy et al., 2001), about 500 manually constructed questions for a few rare classes, 894 TREC 8 and TREC 9 questions, and also 500 questions from TREC 10 which serves as the test set. These questions were manually labeled.

sourceHugging Faceunknownupdated 3y agoView on Hugging Face
48likes18kdownloads
trec.py163 linesDownload Raw Back to root
1# coding=utf-82# 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 at7#8#     http://www.apache.org/licenses/LICENSE-2.09#10# Unless required by applicable law or agreed to in writing, software11# 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 and14# limitations under the License.15"""The Text REtrieval Conference (TREC) Question Classification dataset."""16 17 18import datasets19 20 21_DESCRIPTION = """\22The Text REtrieval Conference (TREC) Question Classification dataset contains 5500 labeled questions in training set and another 500 for test set.23 24The dataset has 6 coarse class labels and 50 fine class labels. Average length of each sentence is 10, vocabulary size of 8700.25 26Data are collected from four sources: 4,500 English questions published by USC (Hovy et al., 2001), about 500 manually constructed questions for a few rare classes, 894 TREC 8 and TREC 9 questions, and also 500 questions from TREC 10 which serves as the test set. These questions were manually labeled.27"""28 29_HOMEPAGE = "https://cogcomp.seas.upenn.edu/Data/QA/QC/"30 31_CITATION = """\32@inproceedings{li-roth-2002-learning,33    title = "Learning Question Classifiers",34    author = "Li, Xin  and35      Roth, Dan",36    booktitle = "{COLING} 2002: The 19th International Conference on Computational Linguistics",37    year = "2002",38    url = "https://www.aclweb.org/anthology/C02-1150",39}40@inproceedings{hovy-etal-2001-toward,41    title = "Toward Semantics-Based Answer Pinpointing",42    author = "Hovy, Eduard  and43      Gerber, Laurie  and44      Hermjakob, Ulf  and45      Lin, Chin-Yew  and46      Ravichandran, Deepak",47    booktitle = "Proceedings of the First International Conference on Human Language Technology Research",48    year = "2001",49    url = "https://www.aclweb.org/anthology/H01-1069",50}51"""52 53_URLs = {54    "train": "https://cogcomp.seas.upenn.edu/Data/QA/QC/train_5500.label",55    "test": "https://cogcomp.seas.upenn.edu/Data/QA/QC/TREC_10.label",56}57 58_COARSE_LABELS = ["ABBR", "ENTY", "DESC", "HUM", "LOC", "NUM"]59 60_FINE_LABELS = [61    "ABBR:abb",62    "ABBR:exp",63    "ENTY:animal",64    "ENTY:body",65    "ENTY:color",66    "ENTY:cremat",67    "ENTY:currency",68    "ENTY:dismed",69    "ENTY:event",70    "ENTY:food",71    "ENTY:instru",72    "ENTY:lang",73    "ENTY:letter",74    "ENTY:other",75    "ENTY:plant",76    "ENTY:product",77    "ENTY:religion",78    "ENTY:sport",79    "ENTY:substance",80    "ENTY:symbol",81    "ENTY:techmeth",82    "ENTY:termeq",83    "ENTY:veh",84    "ENTY:word",85    "DESC:def",86    "DESC:desc",87    "DESC:manner",88    "DESC:reason",89    "HUM:gr",90    "HUM:ind",91    "HUM:title",92    "HUM:desc",93    "LOC:city",94    "LOC:country",95    "LOC:mount",96    "LOC:other",97    "LOC:state",98    "NUM:code",99    "NUM:count",100    "NUM:date",101    "NUM:dist",102    "NUM:money",103    "NUM:ord",104    "NUM:other",105    "NUM:period",106    "NUM:perc",107    "NUM:speed",108    "NUM:temp",109    "NUM:volsize",110    "NUM:weight",111]112 113 114class Trec(datasets.GeneratorBasedBuilder):115    """The Text REtrieval Conference (TREC) Question Classification dataset."""116 117    VERSION = datasets.Version("2.0.0", description="Fine label contains 50 classes instead of 47.")118 119    def _info(self):120        return datasets.DatasetInfo(121            description=_DESCRIPTION,122            features=datasets.Features(123                {124                    "text": datasets.Value("string"),125                    "coarse_label": datasets.ClassLabel(names=_COARSE_LABELS),126                    "fine_label": datasets.ClassLabel(names=_FINE_LABELS),127                }128            ),129            homepage=_HOMEPAGE,130            citation=_CITATION,131        )132 133    def _split_generators(self, dl_manager):134        """Returns SplitGenerators."""135        dl_files = dl_manager.download(_URLs)136        return [137            datasets.SplitGenerator(138                name=datasets.Split.TRAIN,139                gen_kwargs={140                    "filepath": dl_files["train"],141                },142            ),143            datasets.SplitGenerator(144                name=datasets.Split.TEST,145                gen_kwargs={146                    "filepath": dl_files["test"],147                },148            ),149        ]150 151    def _generate_examples(self, filepath):152        """Yields examples."""153        with open(filepath, "rb") as f:154            for id_, row in enumerate(f):155                # One non-ASCII byte: sisterBADBYTEcity. We replace it with a space156                fine_label, _, text = row.replace(b"\xf0", b" ").strip().decode().partition(" ")157                coarse_label = fine_label.split(":")[0]158                yield id_, {159                    "text": text,160                    "coarse_label": coarse_label,161                    "fine_label": fine_label,162                }163