Datasets:

Modalities:
Text
Formats:
parquet
Libraries:
Datasets
pandas
License:
yslim0726 commited on
Commit
ec6ae40
โ€ข
1 Parent(s): 9ec42e5

Upload nq_open.py

Browse files
Files changed (1) hide show
  1. nq_open.py +103 -0
nq_open.py ADDED
@@ -0,0 +1,103 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import os
2
+ import json
3
+ import datasets
4
+ from datasets import BuilderConfig, Features, Value, Sequence
5
+
6
+
7
+ _DESCRIPTION = """
8
+ # ํ•œ๊ตญ์–ด ์ง€์‹œํ•™์Šต ๋ฐ์ดํ„ฐ์…‹
9
+ - nq_open ๋ฐ์ดํ„ฐ์…‹์„ ํ•œ๊ตญ์–ด๋กœ ๋ณ€์—ญํ•œ ๋ฐ์ดํ„ฐ์…‹
10
+ """
11
+
12
+ _CITATION = """
13
+ @inproceedings{KITD,
14
+ title={์–ธ์–ด ๋ฒˆ์—ญ ๋ชจ๋ธ์„ ํ†ตํ•œ ํ•œ๊ตญ์–ด ์ง€์‹œ ํ•™์Šต ๋ฐ์ดํ„ฐ ์„ธํŠธ ๊ตฌ์ถ•},
15
+ author={์ž„์˜์„œ, ์ถ”ํ˜„์ฐฝ, ๊น€์‚ฐ, ์žฅ์ง„์˜ˆ, ์ •๋ฏผ์˜, ์‹ ์‚ฌ์ž„},
16
+ booktitle={์ œ 35ํšŒ ํ•œ๊ธ€ ๋ฐ ํ•œ๊ตญ์–ด ์ •๋ณด์ฒ˜๋ฆฌ ํ•™์ˆ ๋Œ€ํšŒ},
17
+ pages={591--595},
18
+ month=oct,
19
+ year={2023}
20
+ }
21
+ """
22
+
23
+ def _list(data_list):
24
+ result = list()
25
+ for data in data_list:
26
+ result.append(data)
27
+ return result
28
+
29
+ # nq_open
30
+ _NQ_OPEN_FEATURES = Features({
31
+ "data_index_by_user": Value(dtype="int32"),
32
+ "question": Value(dtype="string"),
33
+ "answer": Sequence(Value(dtype="string"))
34
+ })
35
+
36
+ def _parsing_nq_open(file_path):
37
+ with open(file_path, mode="r") as f:
38
+ dataset = json.load(f)
39
+ for _i, data in enumerate(dataset):
40
+ _data_index_by_user = data["data_index_by_user"]
41
+ _question = data["question"]
42
+ _answer = _list(data["answer"])
43
+
44
+ yield _i, {
45
+ "data_index_by_user": _data_index_by_user,
46
+ "question": _question,
47
+ "answer": _answer
48
+ }
49
+
50
+ class Nq_openConfig(BuilderConfig):
51
+ def __init__(self, name, feature, reading_fn, parsing_fn, citation, **kwargs):
52
+ super(Nq_openConfig, self).__init__(
53
+ name = name,
54
+ version=datasets.Version("1.0.0"),
55
+ **kwargs)
56
+ self.feature = feature
57
+ self.reading_fn = reading_fn
58
+ self.parsing_fn = parsing_fn
59
+ self.citation = citation
60
+
61
+ class NQ_OPEN(datasets.GeneratorBasedBuilder):
62
+ BUILDER_CONFIGS = [
63
+ Nq_openConfig(
64
+ name = "base",
65
+ data_dir = "./nq_open",
66
+ feature = _NQ_OPEN_FEATURES,
67
+ reading_fn = _parsing_nq_open,
68
+ parsing_fn = lambda x:x,
69
+ citation = _CITATION,
70
+ ),
71
+ ]
72
+
73
+ def _info(self) -> datasets.DatasetInfo:
74
+ """Returns the dataset metadata."""
75
+ return datasets.DatasetInfo(
76
+ description=_DESCRIPTION,
77
+ features=_NQ_OPEN_FEATURES,
78
+ citation=_CITATION,
79
+ )
80
+
81
+ def _split_generators(self, dl_manager: datasets.DownloadManager):
82
+ """Returns SplitGenerators"""
83
+ path_kv = {
84
+ datasets.Split.TRAIN:[
85
+ os.path.join(dl_manager.manual_dir, f"train.json")
86
+ ],
87
+ datasets.Split.VALIDATION:[
88
+ os.path.join(dl_manager.manual_dir, f"validation.json")
89
+ ],
90
+ }
91
+ return [
92
+ datasets.SplitGenerator(name=k, gen_kwargs={"path_list": v})
93
+ for k, v in path_kv.items()
94
+ ]
95
+
96
+ def _generate_examples(self, path_list):
97
+ """Yields examples."""
98
+ for path in path_list:
99
+ try:
100
+ for example in iter(self.config.reading_fn(path)):
101
+ yield self.config.parsing_fn(example)
102
+ except Exception as e:
103
+ print(e)