|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
import os |
|
|
|
import datasets |
|
import json |
|
|
|
|
|
_DESCRIPTION = ( |
|
"M4LE is a systematic and comprehensive long-context benchmark. It aims to" |
|
" evaluate LM performances in five long-context understanding abilities," |
|
" across multiple domains, languages and task types." |
|
) |
|
_HOMEPAGE = "https://github.com/KwanWaiChung/M4LE" |
|
_LICENSE = """MIT License |
|
Copyright (c) 2023 Wai-Chung Kwan |
|
|
|
Permission is hereby granted, free of charge, to any person obtaining a copy |
|
of this software and associated documentation files (the "Software"), to deal |
|
in the Software without restriction, including without limitation the rights |
|
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell |
|
copies of the Software, and to permit persons to whom the Software is |
|
furnished to do so, subject to the following conditions: |
|
|
|
The above copyright notice and this permission notice shall be included in all |
|
copies or substantial portions of the Software. |
|
|
|
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR |
|
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, |
|
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE |
|
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER |
|
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, |
|
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE |
|
SOFTWARE.""" |
|
URL = r"https://huggingface.co/datasets/wckwan/M4LE/resolve/main/data.zip" |
|
|
|
|
|
tasks = [ |
|
"arxiv", |
|
"bigpatent_global_cls", |
|
"bigpatent_global_sum", |
|
"booksum", |
|
"c3", |
|
"cepsum", |
|
"clts+", |
|
"cnewsum", |
|
"cnnnews", |
|
"drcd_explicit-single", |
|
"drcd_semantic-single", |
|
"duorc", |
|
"dureader", |
|
"hotpotqa", |
|
"lcsts", |
|
"marc", |
|
"mnds-news_explicit-single", |
|
"mnds-news_explicit-multiple", |
|
"mnds-news_semantic-multiple", |
|
"ncls", |
|
"news-commentary-en2zh", |
|
"news-commentary-zh2en", |
|
"news2016", |
|
"newsqa", |
|
"nq-open", |
|
"online-shopping", |
|
"open-subtitles-en2zh", |
|
"open-subtitles-zh2en", |
|
"pubmed", |
|
"tedtalks-en2zh", |
|
"tedtalks-zh2en", |
|
"thucnews_explicit-single", |
|
"thucnews_explicit-multiple", |
|
"thucnews_semantic-multiple", |
|
"triviaqa", |
|
"wiki2019zh", |
|
"wikihow", |
|
"wikitext-103", |
|
"wow", |
|
] |
|
|
|
|
|
class M4LEConfig(datasets.BuilderConfig): |
|
def __init__(self, **kwargs): |
|
super().__init__(version=datasets.Version("1.0.0"), **kwargs) |
|
|
|
|
|
class LongBench(datasets.GeneratorBasedBuilder): |
|
BUILDER_CONFIGS = [ |
|
M4LEConfig( |
|
name=task, |
|
) |
|
for task in tasks |
|
] |
|
|
|
def _info(self): |
|
features = datasets.Features( |
|
{ |
|
"instruction": datasets.Value("string"), |
|
"input": datasets.Value("string"), |
|
"answers": [datasets.Value("string")], |
|
"input_length": datasets.Value("int32"), |
|
"total_length": datasets.Value("int32"), |
|
"length_bucket": datasets.Value("int32"), |
|
} |
|
) |
|
return datasets.DatasetInfo( |
|
description=_DESCRIPTION, |
|
features=features, |
|
homepage=_HOMEPAGE, |
|
license=_LICENSE, |
|
) |
|
|
|
def _split_generators(self, dl_manager): |
|
data_dir = dl_manager.download_and_extract(URL) |
|
task_name = self.config.name |
|
return [ |
|
datasets.SplitGenerator( |
|
name=datasets.Split.TEST, |
|
gen_kwargs={ |
|
"filepath": os.path.join( |
|
data_dir, "data", f"{task_name}.jsonl" |
|
), |
|
}, |
|
) |
|
] |
|
|
|
def _generate_examples(self, filepath): |
|
with open(filepath, encoding="utf-8") as f: |
|
for idx, line in enumerate(f): |
|
key = f"{self.config.name}-{idx}" |
|
item = json.loads(line) |
|
yield key, { |
|
"instruction": item["instruction"], |
|
"input": item["input"], |
|
"answers": item["answers"], |
|
"input_length": item["input_length"], |
|
"total_length": item["total_length"], |
|
"length_bucket": item["length_bucket"], |
|
} |
|
|