|
from __future__ import annotations |
|
|
|
import json |
|
from typing import Any, Generator |
|
|
|
import datasets |
|
|
|
_CITATION = "" |
|
_DESCRIPTION = "These are datasets including the benchmark 'ja-vicuna-qa-benchmark.'" |
|
_HOMEPAGE = "https://raw.githubusercontent.com/ku-nlp/ja-vicuna-qa-benchmark/main/data/jp_bench/question.jsonl" |
|
_LICENSE = "This work is license under Apache-2.0 license" |
|
_URL = "https://raw.githubusercontent.com/ku-nlp/ja-vicuna-qa-benchmark/main/data/jp_bench/question.jsonl" |
|
_VERSION = "1.1.0" |
|
|
|
|
|
class JaVicunaQaBenchmarkConfig(datasets.BuilderConfig): |
|
def __init__( |
|
self, |
|
name: str = "default", |
|
version: datasets.Version | str | None = datasets.Version(_VERSION), |
|
data_dir: str | None = None, |
|
data_files: datasets.data_files.DataFilesDict | None = None, |
|
description: str | None = _DESCRIPTION, |
|
) -> None: |
|
super().__init__( |
|
name=name, |
|
version=version, |
|
data_dir=data_dir, |
|
data_files=data_files, |
|
description=description, |
|
) |
|
|
|
|
|
class JaVicunaQaBenchmark(datasets.GeneratorBasedBuilder): |
|
BUILDER_CONFIG_CLASS = JaVicunaQaBenchmarkConfig |
|
|
|
def _info(self) -> datasets.DatasetInfo: |
|
return datasets.DatasetInfo( |
|
description=_DESCRIPTION, |
|
citation=_CITATION, |
|
homepage=_HOMEPAGE, |
|
license=_LICENSE, |
|
features=datasets.Features( |
|
{ |
|
"question_id": datasets.Value("int64"), |
|
"category": datasets.Value("string"), |
|
"turns": [datasets.Value("string")], |
|
} |
|
), |
|
) |
|
|
|
def _split_generators( |
|
self, dl_manager: datasets.DownloadManager |
|
) -> list[datasets.SplitGenerator]: |
|
dataset_file = dl_manager.download_and_extract(_URL) |
|
with open(dataset_file, "r", encoding="utf-8") as f: |
|
data = [json.loads(line) for line in f] |
|
|
|
return [ |
|
datasets.SplitGenerator( |
|
name=datasets.Split.TEST, gen_kwargs={"data": data} |
|
), |
|
] |
|
|
|
def _generate_examples(self, data: list[dict[str, Any]]) -> Generator: |
|
for i, d in enumerate(data): |
|
yield i, d |
|
|