Code Monkey home page Code Monkey logo

loogle's Introduction

Long Context Generic Language Evaluation benchmark for LLM long context understanding

License: MIT Documentation Documentation Documentation

LooGLE is a comprehensive evaluation benchmark for LLM long context understanding which contains up-to-date (all after 2022) and extremely long realistic documents (over 24k tokens per document, many of which exceed 100k words) and 6,000 newly generated questions spanning diverse domains and categories. Details statistics of our dataset can be seen in the table below.

Short and long dependency tasks 📜 LooGLE is composed of 7 major tasks to evaluate LLMs' ability to understand both short and long dependency content. We refer to ``long dependency" tasks as those that require the understanding of the inter-dependency across multiple shreds of evidence widely spanning over the entire long text. We delicately design 5 types of long dependency tasks, including comprehension and reasoning, computation, timeline reorder, multiple information retrieval, and summarization.

Long context evaluation 📊 In order to provide more comprehensive and general results, LooGLE relies on automatic metrics based on semantic similarity, GPT4-as-judgment and human evaluation to get an overall performance for reference. We conducted the evaluation of 8 representative LLMs. We specifically select LLMs which have made great effort in addressing the challenge of understanding long contexts by utilizing flash attention, position interpolation, optimized Transformer and finetuning, external memory etc.

LooGLE not only provides a systematic and comprehensive evaluation schema on long-context LLMs, but also sheds light on the future development of enhanced models toward “true long-context understanding”.

📌 Statistics of LooGLE

✏️ Table of Contents

🚀 Capability leaderboard

The overall performance comparisons of different models on different tasks in our dataset are shown in the figure below.


💁 Quick Start

Step 1. Prerequisites

Clone this repo and install the dependencies. The test environment is under torch 2.0.1+cu121.

cd LooGLE   
conda create -n loogle python=3.9
conda activate loogle
pip install -r requirements.txt
export OPENAI_API_KEY="[your_openai_api_key]"

Step 2. Download the data

You can download and load the LooGLE data through the Hugging Face datasets (🤗 HF Repo):

from datasets import load_dataset

datasets = ["shortdep_qa", "shortdep_cloze", "longdep_qa", "longdep_summarization"]

for testset in datasets:
    data = load_dataset('bigainlco/LooGLE', testset, split='test')
    # evaluate your model

You can also access our sample data LooGLE-testdata/.

All data in LooGLE are standardized to the following format:

{
    "input": "The original long input texts",
    "title": "The title of the given document",  //for arxiv paper, we use "title" to refer the identical ID for specific paper
    "qa_pairs":[
            {
                "Q": "Question to ask based on the given input",
                "A": "Groundtruth answer for the question",
                "S": [ "One or more evidence (complete sentences) for answering the question, which are extracted directly from the original input"
                ]
            },  
        ]        // There are multiple questions and corresponding answers in the list (each of them is in json format)
                 // For arxiv paper summarization, we use "none" instead for non-qa/non-cloze tasks
    "output": "none"   // the predicted outputs of LLM given the long input and instructions, which is initialized as "none"

To mention that, in long dependency QA data, we add an extra key type for each question in json to indicate the 4 types of long dependency tasks(apart from summarization).


Step 3. Generate the prediction results

We test LLMs using 3 Python codes under the path Prediction/ for corresponding types of models. We select the model for evaluation via --model_name and the specific task via --task. Let's take short dependency QA as an example:

For GPT-3.5-turbo and GPT4:

python Prediction/pred_gpt_models.py  --model_name gpt-3.5-turbo-16k --task shortdep_qa --max_length 500

For LlamaIndex:

python Prediction/pred_llamaindex.py --task shortdep_qa --max_length 500

For other open-source models (take chatglm2-6b-32k as an example):

python Prediction/pred_opensource_models.py  --model_name chatglm2-6b-32k --task shortdep_qa --max_length 500

Open-source models can be downloaded and loaded from Models/ by default, you can change the path via --model_path

You can also determine the long text output result through --output_path.

Please note that in config/, we provide the prompt format suitable for each task and the maximum generation length. The input parameter --max_length limits the max length of the input prompt for selected model. Feel free to modify them to better suit the model you want to evaluate.

We test all the open-source baselines with a single 80G A800 GPU in BF16 precision. For Llama-2 based models, we recommend using Flash Attention for optimization and saving GPU memory.

Prediction for retrieval-based methods

To evaluate the effectiveness of retrieval techniques for long-context dependency questions, we undertook extensive experiments by replacing the base LLM model in LlamaIndex with different baseline LLMs.

For retrieval-based methods (take chatglm2-6b-32k as an example):

python Retrieval/pred_retrieval_based_method.py --model_name chatglm2-6b-32k --task shortdep_qa --max_length 500 --emb_model_name sentence-transformers/all-mpnet-base-v2

Use --emb_model_name to set embedding models for retrieval-based methods. Here we used all-mpnet-base-v2 as default.

📊 Evaluation

Given the prediction file generated in Step 2, we run the evaluation code in Evaluation/.

For automatic evaluation in short and long-dependency QA, summarization task (eg. short-dependency QA):

python Evaluation/automatic_eval.py --model_name chatglm2-6b-32k --task shortdep_qa --eval_metric automatic_sim

For automatic evaluation in cloze task:

python Evaluation/automatic_eval.py --model_name chatglm2-6b-32k --task shortdshortdep_cloze --eval_metric automatic_match

For LLM-as-judge in short and long dependency QA, summarization task (eg. short dependency QA):

python Evaluation/llm_eval.py --model_name chatglm2-6b-32k --task shortdep_qa

Besides the parameters specifying the --model_name and --task, we provide --eval_metric for users to choose the method for automatic evaluation from [automatic_sim, automatic_match].

Automatic metrics based on semantic similarity matching including Bleu, Rouge, Meteor, Bertscore and exact/partial match are supported. Feel free to add other metrics for your needs in Evaluation/automatic_metrics.py. Besides, the prompt of GPT4 given in the repo can be altered for further evaluation.

Evaluation on Timeline reorder task

We provide four metrics: LSD (location square deviation), LMD (location mean deviation), SD (swap deviation), and SDD (swap distance deviation) to measure the similarity of numeric sequences for time reorder tasks with regularized outputs. Details of the implementations can be seen in our paper.

For LLM in long dependency timeline reorder task:

python Reorder/automatic_eval.py --model_name chatglm2-6b-32k

📝 Citation

If you would like to use our data or find our work interesting, please cite:

@article{li2023loogle,
  title={LooGLE: Can Long-Context Language Models Understand Long Contexts?},
  author={Li, Jiaqi and Wang, Mengmeng and Zheng, Zilong and Zhang, Muhan},
  journal={arXiv preprint arXiv:2311.04939},
  year={2023}
}

📣 Contacts

We sincerely appreciate human annotators for their valuable contributions on creating high-quality long-dependency QA tasks. We are very pleased to answer any questions about LooGLE: [email protected]

loogle's People

Contributors

eltociear avatar lijiaqijane avatar mengmengwang90 avatar zilongzheng avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar

loogle's Issues

Prompt format for different models

Hi! I have read the codes for open source model evaluation. I noticed that, different from some existing benchmarks such as LongBench or L-Eval, there is not prompt customization part for different models (e.g. the prompt format of vicuna series is different from the original LlaMa-2). For fair comparison, do you think such customization should be added to the codes?

Question about model selection

我看论文里选了llama拓展到32k长度的做摘要评估,然后其他的一些longllama,gpt之类的可能多少都有指令微调过,已经有了对相应任务的理解,不确定你们选的这个llama32k是不是以language model的形式拓展长度的,如果是这样,怎么确定比较公平性哇?
或者有没有考虑引入llama-chat版本还有一些其他的指令微调且长度拓展的llama模型做评估哦

groundtruth逻辑是否有问题

你好,在pred_gpt_models.py中get_pre()方法是否有bug?

def get_pred(model, data_instance, tokenizer, max_length, max_gen, prompt_format, device):

ans, groundtruth = [], []
preds = {}
raw_inputs = data_instance['input']
if data_instance['qa_pairs'] == 'none':
    preds['qa_pairs'] = data_instance['qa_pairs']
    json_obj = {'input': raw_inputs}

    prompt = prompt_format.format(**json_obj)
    tokenized_prompt = tokenizer(prompt, truncation=False, return_tensors="pt").input_ids[0]
    if len(tokenized_prompt) > max_length:
        half = int(max_length/2)
        prompt = tokenizer.decode(tokenized_prompt[:half], skip_special_tokens=True)+tokenizer.decode(tokenized_prompt[-half:], skip_special_tokens=True)
    
    
    input_ids = tokenizer(prompt, truncation=True, return_tensors="pt").input_ids.to(device)
    context_length = input_ids.shape[-1]
    with torch.no_grad():
        output = model.generate(input_ids,max_new_tokens=max_gen,temperature=1.0,num_beams=1,do_sample=False,repetition_penalty=float(2))[0]
    pred = tokenizer.decode(output[context_length:], skip_special_tokens=True)

    ans.append(pred)
    groundtruth.append(raw_inputs)

这里的groundtruth怎么是raw_inputs?

Insufficient A100 memory for overly long context.

Thank you for your outstanding work, but I encountered the following problem during testing.
The single A100 (80GB) card has insufficient memory when predicting with overly long context. I am very curious how you solve this tricky problem.
I saw in your code:

if len(tokenized_prompt) > max_length:
    half = int(max_length/2)
    prompt = tokenizer.decode(tokenized_prompt[:half], skip_special_tokens=True) + tokenizer.decode(tokenized_prompt[-half:], skip_special_tokens=True)

Does this approach affect the accuracy of the evaluation?
Thank you again.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.