Datasets:

Modalities:
Text
Formats:
parquet
Libraries:
Datasets
pandas
License:
File size: 3,104 Bytes
ec6ae40
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
import os
import json
import datasets
from datasets import BuilderConfig, Features, Value, Sequence


_DESCRIPTION = """
# ํ•œ๊ตญ์–ด ์ง€์‹œํ•™์Šต ๋ฐ์ดํ„ฐ์…‹
- nq_open ๋ฐ์ดํ„ฐ์…‹์„ ํ•œ๊ตญ์–ด๋กœ ๋ณ€์—ญํ•œ ๋ฐ์ดํ„ฐ์…‹
"""

_CITATION = """
@inproceedings{KITD,
  title={์–ธ์–ด ๋ฒˆ์—ญ ๋ชจ๋ธ์„ ํ†ตํ•œ ํ•œ๊ตญ์–ด ์ง€์‹œ ํ•™์Šต ๋ฐ์ดํ„ฐ ์„ธํŠธ ๊ตฌ์ถ•},
  author={์ž„์˜์„œ, ์ถ”ํ˜„์ฐฝ, ๊น€์‚ฐ, ์žฅ์ง„์˜ˆ, ์ •๋ฏผ์˜, ์‹ ์‚ฌ์ž„},
  booktitle={์ œ 35ํšŒ ํ•œ๊ธ€ ๋ฐ ํ•œ๊ตญ์–ด ์ •๋ณด์ฒ˜๋ฆฌ ํ•™์ˆ ๋Œ€ํšŒ},
  pages={591--595},
  month=oct,
  year={2023}
}
"""

def _list(data_list):
    result = list()
    for data in data_list:
        result.append(data)
    return result

# nq_open
_NQ_OPEN_FEATURES = Features({
    "data_index_by_user": Value(dtype="int32"),
    "question": Value(dtype="string"),
    "answer": Sequence(Value(dtype="string"))
})

def _parsing_nq_open(file_path):
    with open(file_path, mode="r") as f:
        dataset = json.load(f)
    for _i, data in enumerate(dataset):
        _data_index_by_user = data["data_index_by_user"]
        _question = data["question"]
        _answer = _list(data["answer"])
        
        yield _i, {
            "data_index_by_user": _data_index_by_user,
            "question": _question,
            "answer": _answer
        }

class Nq_openConfig(BuilderConfig):
    def __init__(self, name, feature, reading_fn, parsing_fn, citation, **kwargs):
        super(Nq_openConfig, self).__init__(
            name = name,
            version=datasets.Version("1.0.0"),
            **kwargs)
        self.feature = feature
        self.reading_fn = reading_fn
        self.parsing_fn = parsing_fn
        self.citation = citation

class NQ_OPEN(datasets.GeneratorBasedBuilder):
    BUILDER_CONFIGS = [
        Nq_openConfig(
            name = "base",
            data_dir = "./nq_open",
            feature = _NQ_OPEN_FEATURES,
            reading_fn = _parsing_nq_open,
            parsing_fn = lambda x:x,
            citation = _CITATION,
        ),
    ]
    
    def _info(self) -> datasets.DatasetInfo:
        """Returns the dataset metadata."""
        return datasets.DatasetInfo(
            description=_DESCRIPTION,
            features=_NQ_OPEN_FEATURES,
            citation=_CITATION,
        )
    
    def _split_generators(self, dl_manager: datasets.DownloadManager):
        """Returns SplitGenerators"""
        path_kv = {
            datasets.Split.TRAIN:[
                os.path.join(dl_manager.manual_dir, f"train.json")
            ],
            datasets.Split.VALIDATION:[
                os.path.join(dl_manager.manual_dir, f"validation.json")
            ],
        }
        return [
            datasets.SplitGenerator(name=k, gen_kwargs={"path_list": v})
            for k, v in path_kv.items()
        ]
    
    def _generate_examples(self, path_list):
        """Yields examples."""
        for path in path_list:
            try:
                for example in iter(self.config.reading_fn(path)):
                    yield self.config.parsing_fn(example)
            except Exception as e:
                print(e)