# 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 """TODO: Add a description here.""" import csv import json import os import datasets import pandas as pd import zipfile # TODO: Add BibTeX citation # Find for instance the citation on arxiv or on the dataset repo/website _CITATION = """\ @inproceedings{santhanam-etal-2022-colbertv2, title = "{C}ol{BERT}v2: Effective and Efficient Retrieval via Lightweight Late Interaction", author = "Santhanam, Keshav and Khattab, Omar and Saad-Falcon, Jon and Potts, Christopher and Zaharia, Matei", booktitle = "Proceedings of the 2022 Conference of the North American Chapter of the Association for Computational Linguistics: Human Language Technologies", month = jul, year = "2022", address = "Seattle, United States", publisher = "Association for Computational Linguistics", url = "https://aclanthology.org/2022.naacl-main.272", pages = "3715--3734", abstract = "Neural information retrieval (IR) has greatly advanced search and other knowledge-intensive language tasks. While many neural IR methods encode queries and documents into single-vector representations, late interaction models produce multi-vector representations at the granularity of each token and decompose relevance modeling into scalable token-level computations. This decomposition has been shown to make late interaction more effective, but it inflates the space footprint of these models by an order of magnitude. In this work, we introduce Maize, a retriever that couples an aggressive residual compression mechanism with a denoised supervision strategy to simultaneously improve the quality and space footprint of late interaction. We evaluate Maize across a wide range of benchmarks, establishing state-of-the-art quality within and outside the training domain while reducing the space footprint of late interaction models by 6{--}10x.", } """ # TODO: Add description of the dataset here # You can copy an official description _DESCRIPTION = """\ LoTTE Passages Dataset for ColBERTv2 """ # TODO: Add a link to an official homepage for the dataset here _HOMEPAGE = "https://huggingface.co/datasets/colbertv2/lotte" # TODO: Add the licence for the dataset here if you can find it _LICENSE = "" _URL = { "pooled": "https://huggingface.co/datasets/colbertv2/lotte/resolve/main/pooled/", "lifestyle": "https://huggingface.co/datasets/colbertv2/lotte/resolve/main/lifestyle/", "recreation": "https://huggingface.co/datasets/colbertv2/lotte/resolve/main/recreation/", "science": "https://huggingface.co/datasets/colbertv2/lotte/resolve/main/science/", "technology": "https://huggingface.co/datasets/colbertv2/lotte/resolve/main/technology/", "writing": "https://huggingface.co/datasets/colbertv2/lotte/resolve/main/writing/" } # TODO: Name of the dataset usually match the script name with CamelCase instead of snake_case class NewDataset(datasets.GeneratorBasedBuilder): """TODO: Short description of my dataset.""" VERSION = datasets.Version("1.1.0") # This is an example of a dataset with multiple configurations. # If you don't want/need to define several sub-sets in your dataset, # just remove the BUILDER_CONFIG_CLASS and the BUILDER_CONFIGS attributes. # If you need to make complex sub-parts in the datasets with configurable options # You can create your own builder configuration class to store attribute, inheriting from datasets.BuilderConfig # BUILDER_CONFIG_CLASS = MyBuilderConfig # You will be able to load one or the other configurations in the following list with # data = datasets.load_dataset('my_dataset', 'first_domain') # data = datasets.load_dataset('my_dataset', 'second_domain') BUILDER_CONFIGS = [ datasets.BuilderConfig(name="pooled", version=VERSION, description=""), datasets.BuilderConfig(name="lifestyle", version=VERSION, description=""), datasets.BuilderConfig(name="recreation", version=VERSION, description=""), datasets.BuilderConfig(name="science", version=VERSION, description=""), datasets.BuilderConfig(name="technology", version=VERSION, description=""), datasets.BuilderConfig(name="writing", version=VERSION, description=""), #datasets.BuilderConfig(name="pooled_search_valid", version=VERSION, description=""), #datasets.BuilderConfig(name="pooled_search_test", version=VERSION, description=""), #datasets.BuilderConfig(name="pooled_forum_valid", version=VERSION, description=""), #datasets.BuilderConfig(name="pooled_forum_test", version=VERSION, description=""), #datasets.BuilderConfig(name="lifestyle_search", version=VERSION, description=""), #datasets.BuilderConfig(name="lifestyle_forum", version=VERSION, description=""), #datasets.BuilderConfig(name="recreation_search", version=VERSION, description=""), #datasets.BuilderConfig(name="recreation_forum", version=VERSION, description=""), #datasets.BuilderConfig(name="science_search", version=VERSION, description=""), #datasets.BuilderConfig(name="science_forum", version=VERSION, description=""), #datasets.BuilderConfig(name="technology_search", version=VERSION, description=""), #datasets.BuilderConfig(name="technology_forum", version=VERSION, description=""), #datasets.BuilderConfig(name="writing_search", version=VERSION, description=""), #datasets.BuilderConfig(name="writing_forum", version=VERSION, description=""), ] DEFAULT_CONFIG_NAME = "pooled" # It's not mandatory to have a default configuration. Just use one if it make sense. def _info(self): # TODO: This method specifies the datasets.DatasetInfo object which contains informations and typings for the dataset features = datasets.Features( { "qid": datasets.Value("int32"), "query": datasets.Value("string"), "author": datasets.Value("string"), "answers": datasets.Sequence(feature={"views": datasets.Value(dtype='int32', id=None), "score": datasets.Value(dtype='int32', id=None), "answer_pids": datasets.Value(dtype='int32', id=None)}) } ) return datasets.DatasetInfo( # This is the description that will appear on the datasets page. description=_DESCRIPTION, # This defines the different columns of the dataset and their types features=features, # Here we define them above because they are different between the two configurations # If there's a common (input, target) tuple from the features, uncomment supervised_keys line below and # specify them. They'll be used if as_supervised=True in builder.as_dataset. # supervised_keys=("sentence", "label"), # Homepage of the dataset for documentation homepage=_HOMEPAGE, # License for the dataset if available license=_LICENSE, # Citation for the dataset citation=_CITATION, ) def _split_generators(self, dl_manager): # TODO: This method is tasked with downloading/extracting the data and defining the splits depending on the configuration # If several configurations are possible (listed in BUILDER_CONFIGS), the configuration selected by the user is in self.config.name # dl_manager is a datasets.download.DownloadManager that can be used to download and extract URLS # It can accept any type or nested list/dict and will give back the same structure with the url replaced with path to local files. # By default the archives will be extracted and a path to a cached folder where they are extracted is returned instead of the archive _URLS = { "forum_dev": _URL[self.config.name] + "dev_qas.forum.jsonl", "forum_test": _URL[self.config.name] + "test_qas.forum.jsonl", "search_dev": _URL[self.config.name] + "dev_qas.search.jsonl", "search_test": _URL[self.config.name] + "test_qas.search.jsonl", } downloaded_files = dl_manager.download_and_extract(_URLS) return [ datasets.SplitGenerator(name="forum_dev", gen_kwargs={"filepath": downloaded_files["forum_dev"]}), datasets.SplitGenerator(name="forum_test", gen_kwargs={"filepath": downloaded_files["forum_test"]}), datasets.SplitGenerator(name="search_dev", gen_kwargs={"filepath": downloaded_files["search_dev"]}), datasets.SplitGenerator(name="search_test", gen_kwargs={"filepath": downloaded_files["search_test"]}), ] # method parameters are unpacked from `gen_kwargs` as given in `_split_generators` def _generate_examples(self, filepath): # TODO: This method handles input defined in _split_generators to yield (key, example) tuples from the dataset. # The `key` is for legacy reasons (tfds) and is not important in itself, but must be unique for each example. print("Generating examples") with open(filepath, encoding="utf-8") as f: for key, row in enumerate(f): data = json.loads(row) answers = {} if "score" in data.keys(): answers.update({"score": [data['score']]}) else: answers.update({"score": []}) if "views" in data.keys(): answers.update({"views": [data['views']]}) else: answers.update({"views": []}) answers.update({"answer_pids": data['answer_pids']}) if "question_author" in data.keys(): author = data['question_author'] else: author = "" yield key, { "qid": data["qid"], "query": data["query"], "author": author, "answers": answers }