Home

Awesome

<p align="center"> πŸ€— <a href="https://huggingface.co/datasets/THUDM/LongBench" target="_blank">HF Repo</a> β€’ πŸ“ƒ <a href="https://arxiv.org/abs/2308.14508" target="_blank">Paper</a> </p>

ι˜…θ―»δΈ­ζ–‡η‰ˆζœ¬.

πŸ“– LongBench: A Bilingual, Multitask Benchmark for Long Context Understanding

LongBench is the first benchmark for bilingual, multitask, and comprehensive assessment of long context understanding capabilities of large language models. LongBench includes different languages (Chinese and English) to provide a more comprehensive evaluation of the large models' multilingual capabilities on long contexts. In addition, LongBench is composed of six major categories and twenty one different tasks, covering key long-text application scenarios such as single-document QA, multi-document QA, summarization, few-shot learning, synthetic tasks and code completion.

We are fully aware of the potentially high costs involved in the model evaluation process, especially in the context of long context scenarios (such as manual annotation costs or API call costs). Therefore, we adopt a fully automated evaluation method, aimed at measuring and evaluating the model's ability to understand long contexts at the lowest cost.

LongBench includes 14 English tasks, 5 Chinese tasks, and 2 code tasks, with the average length of most tasks ranging from 5k to 15k, and a total of 4,750 test data. For detailed statistics and construction methods of LongBench tasks, please refer here. In addition, we provide LongBench-E, a test set with a more uniform length distribution constructed by uniform sampling, with comparable amounts of data in the 0-4k, 4k-8k, and 8k+ length intervals to provide an analysis of the model's performance variations at different input lengths.

Task Type#English Task#Chinese Task#Code Task
Multi-document QA31-
Single-document QA31-
Summarization31-
Few-shot learning31-
Synthetic Tasks21-
Code Completion--2

πŸ”₯ Updates

πŸ”₯πŸ”₯πŸ”₯ [2024/09/10] Check out our new work that extends the maximum generation length of current LLMs to 10,000+ words: LongWriter. Our code & models: https://github.com/THUDM/LongWriter. Also check out LongCite that can generate fine-grained citations during generation for long context document QA. Code & models: https://github.com/THUDM/LongCite.

[2024/02/01] Check out our new effort in Long context LLMs: LongAlign. We explore the best recipe for long context alignment. We also propose LongBench-Chat, the first real-world long context evaluation benchmark (10k-100k input length). We also release an instruction-following dataset at HF Dataset, along with a suite of competitive long context LLMs trained with LongAlign!

[2023/10/30] The new ChatGLM3-6B-32k chat model is out, with better proficiency at long context modeling and is especially good at long document based question answering, reasoning and summarization. Check out its performance on LongBench.

[2023/08/29] The LongBench paper is released, along with several important updates to LongBench:

  1. More comprehensive datasets: The MultiNews dataset for multi-document summarization is added to the summarization tasks, and the summarization task SAMSum is added to the Few-shot learning tasks, replacing the previous QA task NQ. TriviaQA and RepoBench-P are resampled to ensure a more appropriate data length;
  2. More uniformed length distribution: LongBench-E is obtained by uniform sampling according to length, featuring a comparable amount of test data in the length intervals of 0-4k, 4-8k, and 8k+, which is more suitable for evaluating the model's ability in different input lengths variation;
  3. All evaluation codes made public: The code for evaluating all models has been made public, and the code for retrieval-based and summarization-based long context compression strategies are also provided.

πŸ” Table of Contents

<a name="leaderboard"></a>

πŸ–₯️ Leaderboard

Here is the average scores (%) on the main task categories in both Chinese and English languages under the Zero-shot scenario. Please refer to this link for the evaluation metrics used for each task.

Note: For text exceeding the processing length capability of the model, we truncate from the middle of the text, preserving information from the beginning and end, in accordance with the observations from Lost in the Middle. Experiments show that this truncation method has the least impact on model performance.

English

AvgSingle-Doc QAMulti-Doc QASummarizationFew-shot LearningCode CompletionSynthetic Tasks
GPT-3.5-Turbo-16k44.039.838.726.567.154.137.8
Llama2-7B-chat-4k31.024.922.624.760.048.15.9
LongChat-v1.5-7B-32k34.328.720.626.760.054.115.8
XGen-7B-8k28.324.620.424.756.238.65.3
InternLM-7B-8k24.217.420.216.150.336.44.5
ChatGLM2-6B-32k40.932.933.727.659.152.739.2
Vicuna-v1.5-7B-16k31.928.018.626.066.247.35.5
ChatGLM3-6B-32k48.540.346.629.568.156.250.5

Chinese

AvgSingle-Doc QAMulti-Doc QASummarizationFew-shot LearningCode CompletionSynthetic Tasks
GPT-3.5-Turbo-16k44.561.228.716.029.254.177.5
Llama2-7B-chat-4k14.311.95.20.219.848.10.5
LongChat-v1.5-7B-32k23.929.119.59.923.254.17.6
XGen-7B-8k15.114.811.02.220.538.63.5
InternLM-7B-8k18.333.611.112.415.236.40.9
ChatGLM2-6B-32k41.751.637.616.227.752.764.5
Vicuna-v1.5-7B-16k26.443.019.315.128.847.35.0
ChatGLM3-6B-32k52.862.344.817.842.056.294.0

Radar Chart on Long Context Capability

Variation of Abilities under Different Context Lengths

To specifically analyze the model's performance under different context lengths, the following chart shows the models' total scores averaged across all tasks by task category over different context length intervals in LongBench-E.

<a name="how-to-evaluate-on-LongBench"></a>

βš™οΈ How to evaluate on LongBench

Load Data

You can download and load the LongBench data through the Hugging Face datasets (πŸ€— HF Repo):

from datasets import load_dataset

datasets = ["narrativeqa", "qasper", "multifieldqa_en", "multifieldqa_zh", "hotpotqa", "2wikimqa", "musique", \
            "dureader", "gov_report", "qmsum", "multi_news", "vcsum", "trec", "triviaqa", "samsum", "lsht", \
            "passage_count", "passage_retrieval_en", "passage_retrieval_zh", "lcc", "repobench-p"]

for dataset in datasets:
    data = load_dataset('THUDM/LongBench', dataset, split='test')

Similarly, you can load the LongBench-E data

from datasets import load_dataset

datasets = ["qasper", "multifieldqa_en", "hotpotqa", "2wikimqa", "gov_report", "multi_news", "trec", \
            "triviaqa", "samsum", "passage_count", "passage_retrieval_en", "lcc", "repobench-p"]

for dataset in datasets:
    data = load_dataset('THUDM/LongBench', f"{dataset}_e", split='test')

Alternatively, you can download the folder from this link to load the data.

Data Format

All data in LongBench (LongBench-E) are standardized to the following format:

{
    "input": "The input/command for the task, usually short, such as questions in QA, queries in Few-shot tasks, etc",
    "context": "The long context required for the task, such as documents, cross-file code, few-shot examples in Few-shot tasks",
    "answers": "A List of all true answers",
    "length": "Total length of the first three items (counted in characters for Chinese and words for English)",
    "dataset": "The name of the dataset to which this piece of data belongs",
    "language": "The language of this piece of data",
    "all_classes": "All categories in classification tasks, null for non-classification tasks",
    "_id": "Random id for each piece of data"
}

Evaluation

Install the requirements with pip: pip install -r requirements.txt. For Llama-2 based models, we recommend using Flash Attention for optimization and saving GPU memory The relevant dependencies can be installed according to the code base of Flash Attention.

First, run pred.py and select the model you want to evaluate via --model. Let's take ChatGLM3-6B-32k as an example (HuggingFace model weight will be downloaded automatically according to the path in model2path.json, you can change the path in this file to load the model weight from local):

CUDA_VISIBLE_DEVICES=0 python pred.py --model chatglm3-6b-32k

You can also run inference on multi-gpus in parallel (one model per gpu):

CUDA_VISIBLE_DEVICES=0,1,2,3 python pred.py --model chatglm3-6b-32k

You can obtain the output of the model under all LongBench datasets under the pred/ folder corresponding to the model name. Similarly, with the --e command:

CUDA_VISIBLE_DEVICES=0 python pred.py --model chatglm3-6b-32k --e

You can obtain the output on LongBench-E under the pred_e/ folder. After that, run the evaluation code in eval.py:

python eval.py --model chatglm3-6b-32k

You can get the evaluation results on all datasets in result.json. The average score of the model over different length intervals in all LongBench-E datasets can be obtained with the --e command.

Please note that in config/, we provide the input format suitable for each dataset and the maximum output length. Feel free to modify them to better suit the model you want to evaluate. After modification, when evaluating with pred.py, the data will be automatically organized according to the new format to get the corresponding model output.

In addition we provide the code for the long context compression evaluation based on retrieval and summarization (see Section 4.2 in the LongBench paper for the implementation details) in the folders retrieval/ and summ/, respectively.

<a name="evaluation-result-on-each-dataset"></a>

πŸ“Š Evaluation Result on Each Dataset

The following tables show the Zero-shot evaluation results (%) on all datasets, where Chinese datasets are denoted by "zh" (please refer to this link for the evaluation metrics used for each task).

Single-Document QA

NarrativeQAQasperMultiFieldQA-enMultiFieldQA-zh
GPT-3.5-Turbo-16k23.643.352.361.2
Llama2-7B-chat-4k18.719.236.811.9
LongChat-v1.5-7B-32k16.927.741.429.1
XGen-7B-8k18.018.137.714.8
InternLM-7B-8k12.116.723.433.6
ChatGLM2-6B-32k21.131.546.251.6
Vicuna-v1.5-7B-16k19.426.138.543.0
ChatGLM3-6B-32k26.043.351.762.3

Multi-Document QA

HotpotQA2WikiMQAMusiqueDuReader (zh)
GPT-3.5-Turbo-16k51.637.726.928.7
Llama2-7B-chat-4k25.432.89.45.2
LongChat-v1.5-7B-32k31.520.69.719.5
XGen-7B-8k29.721.110.311.0
InternLM-7B-8k28.722.89.011.1
ChatGLM2-6B-32k45.134.021.937.6
Vicuna-v1.5-7B-16k25.320.89.819.3
ChatGLM3-6B-32k54.444.940.444.78

Summarization

GovReportQMSumMultiNewsVCSUM (zh)
GPT-3.5-Turbo-16k29.523.426.716.0
Llama2-7B-chat-4k27.320.825.80.2
LongChat-v1.5-7B-32k30.822.726.49.9
XGen-7B-8k27.320.526.22.2
InternLM-7B-8k9.715.922.812.4
ChatGLM2-6B-32k32.424.026.516.2
Vicuna-v1.5-7B-16k27.922.827.215.1
ChatGLM3-6B-32k36.823.927.917.8

Few-shot Learning

TRECTriviaQASAMSumLSHT (zh)
GPT-3.5-Turbo-16k68.091.441.729.2
Llama2-7B-chat-4k61.577.840.719.8
LongChat-v1.5-7B-32k63.582.334.223.2
XGen-7B-8k65.577.825.320.5
InternLM-7B-8k52.077.821.215.2
ChatGLM2-6B-32k62.578.736.327.7
Vicuna-v1.5-7B-16k71.586.240.828.8
ChatGLM3-6B-32k79.087.138.242.0

Synthetic Tasks

Passage CountPassageRetrieval-enPassageRetrieval-zh
GPT-3.5-Turbo-16k4.571.077.5
Llama2-7B-chat-4k2.19.80.5
LongChat-v1.5-7B-32k1.030.57.6
XGen-7B-8k2.18.53.5
InternLM-7B-8k3.06.00.9
ChatGLM2-6B-32k1.577.064.5
Vicuna-v1.5-7B-16k6.54.55.0
ChatGLM3-6B-32k2.099.094.0

Code Completion

LCCRepoBench-P
GPT-3.5-Turbo-16k54.753.6
Llama2-7B-chat-4k52.443.8
LongChat-v1.5-7B-32k53.055.3
XGen-7B-8k38.638.6
InternLM-7B-8k44.128.8
ChatGLM2-6B-32k55.649.9
Vicuna-v1.5-7B-16k51.043.5
ChatGLM3-6B-32k57.6654.76

<a name="acknowledgement"></a>

πŸ“„ Acknowledgement

<a name="citation"></a>

πŸ“ Citation

@article{bai2023longbench,
  title={LongBench: A Bilingual, Multitask Benchmark for Long Context Understanding},
  author={Bai, Yushi and Lv, Xin and Zhang, Jiajie and Lyu, Hongchang and Tang, Jiankai and Huang, Zhidian and Du, Zhengxiao and Liu, Xiao and Zeng, Aohan and Hou, Lei and Dong, Yuxiao and Tang, Jie and Li, Juanzi},
  journal={arXiv preprint arXiv:2308.14508},
  year={2023}
}

When citing our work, please kindly consider citing the original dataset papers. The relevant citation information is listed here.