Datasets:

Modalities:
Text
ArXiv:
Libraries:
Datasets
davidlvxin commited on
Commit
175e6ae
1 Parent(s): f4baf0b

Init commit

Browse files
Files changed (3) hide show
  1. LongBench.py +113 -0
  2. README.md +127 -0
  3. data.zip +3 -0
LongBench.py ADDED
@@ -0,0 +1,113 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
+ import os
15
+
16
+ import datasets
17
+ import json
18
+
19
+
20
+ _DESCRIPTION = """\
21
+ LongBench is a comprehensive benchmark for multilingual and multi-task purposes, with the goal to fully measure and evaluate the ability of pre-trained language models to understand long text. This dataset consists of twenty different tasks, covering key long-text application scenarios such as multi-document QA, single-document QA, summarization, few-shot learning, synthetic tasks, and code completion.
22
+ """
23
+
24
+ _HOMEPAGE = "https://github.com/THUDM/LongBench"
25
+
26
+
27
+ _URL = r"https://huggingface.co/datasets/THUDM/LongBench/resolve/main/data.zip"
28
+
29
+ task_list = [
30
+ "multifieldqa_en",
31
+ "lcc",
32
+ "passage_retrieval_zh",
33
+ "qasper",
34
+ "nq",
35
+ "passage_retrieval_en",
36
+ "gov_report",
37
+ "triviaqa",
38
+ "qmsum",
39
+ "trec",
40
+ "2wikimqa",
41
+ "dureader",
42
+ "lsht",
43
+ "passage_count",
44
+ "repobench-p",
45
+ "hotpotqa",
46
+ "narrativeqa",
47
+ "vcsum",
48
+ "musique",
49
+ "multifieldqa_zh"
50
+ ]
51
+
52
+
53
+ class LongBenchConfig(datasets.BuilderConfig):
54
+ def __init__(self, **kwargs):
55
+ super().__init__(version=datasets.Version("1.0.0"), **kwargs)
56
+
57
+
58
+ class LongBench(datasets.GeneratorBasedBuilder):
59
+ BUILDER_CONFIGS = [
60
+ LongBenchConfig(
61
+ name=task_name,
62
+ )
63
+ for task_name in task_list
64
+ ]
65
+
66
+ def _info(self):
67
+ features = datasets.Features(
68
+ {
69
+ "input": datasets.Value("string"),
70
+ "context": datasets.Value("string"),
71
+ "answers": [datasets.Value("string")],
72
+ "length": datasets.Value("int32"),
73
+ "dataset": datasets.Value("string"),
74
+ "language": datasets.Value("string"),
75
+ "all_classes": [datasets.Value("string")],
76
+ "_id": datasets.Value("string"),
77
+ }
78
+ )
79
+ return datasets.DatasetInfo(
80
+ description=_DESCRIPTION,
81
+ features=features,
82
+ homepage=_HOMEPAGE,
83
+ )
84
+
85
+ def _split_generators(self, dl_manager):
86
+ data_dir = dl_manager.download_and_extract(_URL)
87
+ task_name = self.config.name
88
+ return [
89
+ datasets.SplitGenerator(
90
+ name=datasets.Split.TEST,
91
+ gen_kwargs={
92
+ "filepath": os.path.join(
93
+ data_dir, "data", f"{task_name}.jsonl"
94
+ ),
95
+ },
96
+ )
97
+ ]
98
+
99
+ def _generate_examples(self, filepath):
100
+ with open(filepath, encoding="utf-8") as f:
101
+ for idx, line in enumerate(f):
102
+ key = f"{self.config.name}-{idx}"
103
+ item = json.loads(line)
104
+ yield key, {
105
+ "input": item["input"],
106
+ "context": item["context"],
107
+ "answers": item["answers"],
108
+ "length": item["length"],
109
+ "dataset": item["dataset"],
110
+ "language": item["language"],
111
+ "_id": item["_id"],
112
+ "all_classes": item["all_classes"],
113
+ }
README.md ADDED
@@ -0,0 +1,127 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ ---
2
+ task_categories:
3
+ - question-answering
4
+ - text-generation
5
+ - summarization
6
+ - conversational
7
+ - text-classification
8
+ language:
9
+ - en
10
+ - zh
11
+ tags:
12
+ - Long Context
13
+ size_categories:
14
+ - 1K<n<10K
15
+ ---
16
+
17
+ # Introduction
18
+
19
+ **LongBench** is the first comprehensive dataset for multi-language, multi-task, and comprehensive assessment of **long text understanding** capabilities of large language models. In the context of the widespread attention to the multi-language capabilities of large models, LongBench includes different languages (Chinese and English) to provide a more comprehensive evaluation of the large models' multi-language capabilities in long texts. In addition, LongBench consists of twenty different tasks, covering key long-text application scenarios such as single-document QA, multi-document QA, summaries, few-shot learning, code completion, and synthesis tasks.
20
+
21
+ We are fully aware of the potentially high costs involved in the model evaluation process, especially in the context of long-text scenarios (such as manual annotation costs or API call costs). Therefore, we have adopted a fully automated evaluation method, aimed at measuring and evaluating the model's ability to understand long texts at the lowest cost and most effectively.
22
+
23
+ LongBench includes 13 English tasks, 5 Chinese tasks, and 2 code tasks, with the average length of most tasks ranging from 5k to 15k. From the main task categories, LongBench includes six types of tasks, namely multi-document QA, single-document QA, summaries, Few-shot learning, synthetic tasks, and code completion.
24
+
25
+ # How to use it?
26
+
27
+ #### Loading Data
28
+
29
+ ```python
30
+ from datasets import load_dataset
31
+
32
+ datasets = ["hotpotqa", "2wikimqa", "musique", "dureader", "narrativeqa", "qasper", "multifieldqa_en", \
33
+ "multifieldqa_zh", "gov_report", "qmsum", "vcsum", "trec", "nq", "triviaqa", "lsht", "passage_count", \
34
+ "passage_retrieval_en", "passage_retrieval_zh", "lcc", "repobench-p"]
35
+
36
+ for dataset in datasets:
37
+ data = load_dataset('THUDM/LongBench', dataset, split='test')
38
+ ```
39
+
40
+ #### Data Format
41
+
42
+ All data in **LongBench** are standardized to the following format:
43
+
44
+ ```json
45
+ {
46
+ "input": "The input/command for the task, usually short, such as questions in QA, queries in Few-shot tasks, etc.",
47
+ "context": "The long context text required for the task, such as documents, cross-file code, few-shot samples in Few-shot tasks",
48
+ "answers": "List composed of all standard answers",
49
+ "length": "Total length of the first three items of text (counted in characters for Chinese and words for English)",
50
+ "dataset": "The name of the dataset to which this piece of data belongs",
51
+ "language": "The language of this piece of data",
52
+ "all_classes": "All categories in classification tasks, null for non-classification tasks",
53
+ "_id": "Random id for each piece of data"
54
+ }
55
+ ```
56
+
57
+ #### Evaluation
58
+
59
+ This repository provides data download for LongBench. If you wish to use this dataset for automated evaluation, please refer to our [github](https://github.com/THUDM/LongBench).
60
+
61
+ # Task statistics
62
+
63
+ | Task | Task Type | Eval metric | Avg len |Language | \#Sample |
64
+ | --------- | -------------| ------------- |--------- | ------------- |--------- |
65
+ | HotpotQA | Multi-doc QA | F1 |9149 |EN |200 |
66
+ | 2WikiMultihopQA| Multi-doc QA | F1 |4885 |EN |200 |
67
+ | Musique| Multi-doc QA | F1 |7798 |EN |200 |
68
+ | DuReader| Multi-doc QA | Rouge-L |15768 |ZH |200 |
69
+ | MultiFieldQA-en| Single-doc QA | F1 |4559 |EN |150 |
70
+ | MultiFieldQA-zh| Single-doc QA | F1 |6771 |ZH |200 |
71
+ | NarrativeQA| Single-doc QA | F1 |18405 |EN |200 |
72
+ | Qasper| Single-doc QA | F1 |3619 |EN |200 |
73
+ | GovReport| Summarization | Rouge-L |8169 |EN |200 |
74
+ | QMSum| Summarization | Rouge-L |10546 |EN |200 |
75
+ | VCSUM| Summarization | Rouge-L |15147 |ZH |200 |
76
+ | TriviaQA| Few shot | F1 |8015 |EN |200 |
77
+ | NQ| Few shot | F1 |8210 |EN |200 |
78
+ | TREC| Few shot | Accuracy |5176 |EN |200 |
79
+ | LSHT| Few shot | Accuracy |22333 |ZH |200 |
80
+ | PassageRetrieval-en| Synthetic | Accuracy |9288 |EN |200 |
81
+ | PassageCount| Synthetic | Accuracy |11141 |EN |200 |
82
+ | PassageRetrieval-zh | Synthetic | Accuracy |6745 |ZH |200 |
83
+ | LCC| Code | Edit Sim |1235 |Python/C#/Java |500 |
84
+ | RepoBench-P| Code | Edit Sim |5622 |Python/Java |500 |
85
+
86
+ > Note: In order to avoid discrepancies caused by different tokenizers, we use the word count (using Python's split function) to calculate the average length of English datasets and code datasets, and use the character count to calculate the average length of Chinese datasets.
87
+
88
+ # Task description
89
+
90
+ | Task | Task Description |
91
+ | ----------------- | ------------------------------------------------------------ |
92
+ | HotpotQA | Answer related questions based on multiple given documents |
93
+ | 2WikiMultihopQA | Answer related questions based on multiple given documents |
94
+ | Musique | Answer related questions based on multiple given documents |
95
+ | DuReader | Answer related Chinese questions based on multiple retrieved documents |
96
+ | MultiFieldQA-en | Answer English questions based on a single document, which comes from a relatively diverse field |
97
+ | MultiFieldQA-zh | Answer Chinese questions based on a single document, which comes from a relatively diverse field |
98
+ | NarrativeQA | Ask questions based on stories or scripts, including understanding of important elements such as characters, plots, themes, etc. |
99
+ | Qasper | Ask questions based on a single paper, questions proposed by NLP readers, and answered by NLP practitioners |
100
+ | GovReport | A summarization task that requires summarizing government work reports |
101
+ | QMSum | A summarization task that requires summarizing meeting records based on user queries |
102
+ | VCSUM | A summarization task that requires summarizing Chinese meeting records |
103
+ | TriviaQA | Single document question answering task, providing several Few Shot examples |
104
+ | NQ | Single document question answering task, providing several Few Shot examples |
105
+ | TREC | A classification task that requires categorizing questions, includes 50 categories in total |
106
+ | LSHT | A Chinese classification task that requires categorizing news, includes 24 categories in total |
107
+ | PassageRetrieval-en | Given 30 English Wikipedia paragraphs, determine which paragraph the given summary belongs to |
108
+ | PassageCount | Determine the number of non-repeating paragraphs in a given number of paragraphs |
109
+ | PassageRetrieval-zh | Given several Chinese paragraphs from the C4 data set, determine which paragraph the given abstract belongs to |
110
+ | LCC | Given a longer piece of code, predict the next line of code |
111
+ | RepoBench-P | Given code in multiple files within a GitHub repository (including inter-file dependencies), predict the next line of code |
112
+
113
+
114
+ # Task construction
115
+
116
+ > Note: For all tasks constructed from existing datasets, we use data from the validation or test set of the existing dataset (except for VCSUM).
117
+
118
+ - The tasks of [HotpotQA](https://hotpotqa.github.io/), [2WikiMultihopQA](https://aclanthology.org/2020.coling-main.580/), [Musique](https://arxiv.org/abs/2108.00573), and [DuReader](https://github.com/baidu/DuReader) are built based on the original datasets and processed to make them suitable for long text evaluation. Specifically, for questions in the validation set, we select the evidence passage that contains the answer and several distracting articles. These articles together with the original question constitute the input of the related tasks.
119
+ - The tasks of MultiFiedQA-zh and MultiFieldQA-en consist of long-text data from about 10 sources, including Latex papers, judicial documents, government work reports, and PDF documents indexed by Google. For each long text, we invite several PhD and master students to annotate, i.e., to ask questions based on the long text and give the correct answers. To better automate evaluation, we require the annotators to ask questions with definitive answers as much as possible.
120
+ - The tasks of [NarrativeQA](https://arxiv.org/pdf/1712.07040.pdf), [Qasper](https://arxiv.org/pdf/2105.03011.pdf), [GovReport](https://arxiv.org/pdf/2104.02112.pdf), and [QMSum](https://arxiv.org/pdf/2104.05938.pdf) directly use the data provided by the original papers. In the specific construction, we use the template provided by [ZeroSCROLLS](https://www.zero.scrolls-benchmark.com/) to convert the corresponding data into pure text input.
121
+ - The [VCSUM](https://arxiv.org/abs/2305.05280) task is built based on the original dataset, and we have designed a corresponding template to convert the corresponding data into pure text input.
122
+ - The tasks of [TriviaQA](https://nlp.cs.washington.edu/triviaqa/) and [NQ](https://ai.google.com/research/NaturalQuestions/) are constructed in the manner of [CoLT5](https://arxiv.org/abs/2303.09752), which provides several examples of question and answering based on documents, and requires the language model to answer related questions based on new documents.
123
+ - The tasks of [TREC](https://aclanthology.org/C02-1150.pdf) and [LSHT](http://tcci.ccf.org.cn/conference/2014/dldoc/evatask6.pdf) are built based on the original datasets. For each question in the validation set, we sample several data from the training set to form few-shot examples. These examples together with the questions in the validation set constitute the input for this task.
124
+ - The PassageRetrieval-en task is constructed based on English Wikipedia. For each piece of data, we randomly sample 30 paragraphs from English Wikipedia and select one for summarization (using GPT3.5 Turbo). The task requires the model to specify which original paragraph the summary corresponds to.
125
+ - The PassageCount task is constructed based on the English wiki. For each piece of data, we randomly sample several passages from English Wikipedia, repeat each paragraph at random several times, and finally shuffle the paragraphs at random. This task requires the model to determine how many paragraphs are not repeated in a given number of paragraphs.
126
+ - The PasskeyRetrieval-zh task is constructed based on [C4](https://arxiv.org/abs/1910.10683). For each piece of data, we randomly sample several Chinese paragraphs from C4 and select one of them for summary (using GPT3.5 Turbo). This task requires the model to give the original paragraph to which the summary should correspond.
127
+ - For the [LCC](https://arxiv.org/abs/2306.14893) task, we sample from the original code completion dataset. In the [RepoBench-P](https://arxiv.org/abs/2306.03091) task, we select the most challenging XF-F (Cross-File-First) setting from the original dataset and refer to the Oracle-Filled scenario in the original text. For each original piece of data, we randomly extract multiple cross-file code snippets, including the effective cross-file code snippet (gold snippet), and concatenate them as input, requiring the model to use the effective cross-file code to complete the current file's code.
data.zip ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:5f97abb5457f43a28d7c15526f54ed4fe93a706e94402d16479efb9f23b020a7
3
+ size 65232859