Datasets:

Modalities:
Text
Size:
< 1K
Libraries:
Datasets
rajivratn commited on
Commit
189449b
·
1 Parent(s): dff3725

Upload test_ldkp.py

Browse files
Files changed (1) hide show
  1. test_ldkp.py +150 -0
test_ldkp.py ADDED
@@ -0,0 +1,150 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import csv
2
+ import json
3
+ import os
4
+
5
+ import datasets
6
+
7
+
8
+ # TODO: Add BibTeX citation
9
+ # Find for instance the citation on arxiv or on the dataset repo/website
10
+ _CITATION = """\
11
+ author: amardeep
12
+ """
13
+
14
+ # TODO: Add description of the dataset here
15
+ # You can copy an official description
16
+ _DESCRIPTION = """\
17
+ This new dataset is designed to solve kp NLP task and is crafted with a lot of care.
18
+ """
19
+
20
+ # TODO: Add a link to an official homepage for the dataset here
21
+ _HOMEPAGE = ""
22
+
23
+ # TODO: Add the licence for the dataset here if you can find it
24
+ _LICENSE = ""
25
+
26
+ # TODO: Add link to the official dataset URLs here
27
+ # The HuggingFace Datasets library doesn't host the datasets but only points to the original files.
28
+ # This can be an arbitrary nested dict/list of URLs (see below in `_split_generators` method)
29
+ _URLS = {
30
+ "ldkp": "",
31
+ "normal": "",
32
+ }
33
+
34
+
35
+ # TODO: Name of the dataset usually match the script name with CamelCase instead of snake_case
36
+ class TestLDKP(datasets.GeneratorBasedBuilder):
37
+ """TODO: Short description of my dataset."""
38
+
39
+ VERSION = datasets.Version("1.1.0")
40
+
41
+ # This is an example of a dataset with multiple configurations.
42
+ # If you don't want/need to define several sub-sets in your dataset,
43
+ # just remove the BUILDER_CONFIG_CLASS and the BUILDER_CONFIGS attributes.
44
+
45
+ # If you need to make complex sub-parts in the datasets with configurable options
46
+ # You can create your own builder configuration class to store attribute, inheriting from datasets.BuilderConfig
47
+ # BUILDER_CONFIG_CLASS = MyBuilderConfig
48
+
49
+ # You will be able to load one or the other configurations in the following list with
50
+ # data = datasets.load_dataset('my_dataset', 'first_domain')
51
+ # data = datasets.load_dataset('my_dataset', 'second_domain')
52
+ BUILDER_CONFIGS = [
53
+ datasets.BuilderConfig(name="ldkp", version=VERSION, description="This part of my dataset covers long document"),
54
+ datasets.BuilderConfig(name="normal", version=VERSION, description="This part of my dataset covers abstract only"),
55
+ ]
56
+
57
+ DEFAULT_CONFIG_NAME = "normal" # It's not mandatory to have a default configuration. Just use one if it make sense.
58
+
59
+ def _info(self):
60
+ # TODO: This method specifies the datasets.DatasetInfo object which contains informations and typings for the dataset
61
+ if self.config.name == "ldkp": # This is the name of the configuration selected in BUILDER_CONFIGS above
62
+ features = datasets.Features(
63
+ {
64
+ "text": datasets.Value("list"),
65
+ "BIO_tags": datasets.Value("list")
66
+ # "answer": datasets.Value("string")
67
+ # These are the features of your dataset like images, labels ...
68
+ }
69
+ )
70
+ else: # This is an example to show how to have different features for "first_domain" and "second_domain"
71
+ features = datasets.Features(
72
+ {
73
+ "text": datasets.Value("list"),
74
+ "BIO_tags": datasets.Value("list")
75
+ # "second_domain_answer": datasets.Value("string")
76
+ # These are the features of your dataset like images, labels ...
77
+ }
78
+ )
79
+ return datasets.DatasetInfo(
80
+ # This is the description that will appear on the datasets page.
81
+ description=_DESCRIPTION,
82
+ # This defines the different columns of the dataset and their types
83
+ features=features, # Here we define them above because they are different between the two configurations
84
+ # If there's a common (input, target) tuple from the features, uncomment supervised_keys line below and
85
+ # specify them. They'll be used if as_supervised=True in builder.as_dataset.
86
+ # supervised_keys=("sentence", "label"),
87
+ # Homepage of the dataset for documentation
88
+ homepage=_HOMEPAGE,
89
+ # License for the dataset if available
90
+ license=_LICENSE,
91
+ # Citation for the dataset
92
+ citation=_CITATION,
93
+ )
94
+
95
+ def _split_generators(self, dl_manager):
96
+ # TODO: This method is tasked with downloading/extracting the data and defining the splits depending on the configuration
97
+ # If several configurations are possible (listed in BUILDER_CONFIGS), the configuration selected by the user is in self.config.name
98
+
99
+ # dl_manager is a datasets.download.DownloadManager that can be used to download and extract URLS
100
+ # It can accept any type or nested list/dict and will give back the same structure with the url replaced with path to local files.
101
+ # By default the archives will be extracted and a path to a cached folder where they are extracted is returned instead of the archive
102
+ urls = _URLS[self.config.name]
103
+ data_dir = dl_manager.download_and_extract(urls)
104
+ return [
105
+ datasets.SplitGenerator(
106
+ name=datasets.Split.TRAIN,
107
+ # These kwargs will be passed to _generate_examples
108
+ gen_kwargs={
109
+ "filepath": os.path.join(data_dir, "train.jsonl"),
110
+ "split": "train",
111
+ },
112
+ ),
113
+ datasets.SplitGenerator(
114
+ name=datasets.Split.TEST,
115
+ # These kwargs will be passed to _generate_examples
116
+ gen_kwargs={
117
+ "filepath": os.path.join(data_dir, "test.jsonl"),
118
+ "split": "test"
119
+ },
120
+ ),
121
+ datasets.SplitGenerator(
122
+ name=datasets.Split.VALIDATION,
123
+ # These kwargs will be passed to _generate_examples
124
+ gen_kwargs={
125
+ "filepath": os.path.join(data_dir, "valid.jsonl"),
126
+ "split": "valid",
127
+ },
128
+ ),
129
+ ]
130
+
131
+ # method parameters are unpacked from `gen_kwargs` as given in `_split_generators`
132
+ def _generate_examples(self, filepath, split):
133
+ # TODO: This method handles input defined in _split_generators to yield (key, example) tuples from the dataset.
134
+ # The `key` is for legacy reasons (tfds) and is not important in itself, but must be unique for each example.
135
+ with open(filepath, encoding="utf-8") as f:
136
+ for key, row in enumerate(f):
137
+ data = json.loads(row)
138
+ if self.config.name == "ldkp":
139
+ # Yields examples as (key, example) tuples
140
+ yield key, {
141
+ "text": data["abstract"]+data["other_sec"],
142
+ "BIO_tags": data["abstract_tags"] + data["other_sec_tags"]
143
+ # "answer": "" if split == "test" else data["answer"],
144
+ }
145
+ else:
146
+ yield key, {
147
+ "text": data["abstract"],
148
+ "BIO_tags": data["abstract_tags"]
149
+ # "second_domain_answer": "" if split == "test" else data["second_domain_answer"],
150
+ }