jamescalam commited on
Commit
540d5d2
1 Parent(s): e336848

added loading script

Browse files
Files changed (1) hide show
  1. load_script.py +124 -0
load_script.py ADDED
@@ -0,0 +1,124 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import csv
2
+ import json
3
+ import os
4
+ import datasets
5
+
6
+
7
+ # TODO: Add BibTeX citation
8
+ # Find for instance the citation on arxiv or on the dataset repo/website
9
+ _CITATION = """\
10
+ @InProceedings{huggingface:dataset,
11
+ title = {A great new dataset},
12
+ author={huggingface, Inc.
13
+ },
14
+ year={2020}
15
+ }
16
+ """
17
+
18
+ # TODO: Add description of the dataset here
19
+ # You can copy an official description
20
+ _DESCRIPTION = """\
21
+ This dataset is an similarity annotated set of claim-evidence pairs from the Climate-FEVER dataset.
22
+ """
23
+
24
+ # TODO: Add a link to an official homepage for the dataset here
25
+ _HOMEPAGE = ""
26
+
27
+ # TODO: Add the licence for the dataset here if you can find it
28
+ _LICENSE = ""
29
+
30
+ # TODO: Add link to the official dataset URLs here
31
+ # The HuggingFace dataset library don't host the datasets but only point to the original files
32
+ # This can be an arbitrary nested dict/list of URLs (see below in `_split_generators` method)
33
+ _URLs = {
34
+ 'validation': "https://raw.githubusercontent.com/jamescalam/datasets/main/climate-fever-similarity/gold_dev.tsv",
35
+ }
36
+
37
+
38
+ # TODO: Name of the dataset usually match the script name with CamelCase instead of snake_case
39
+ class NewDataset(datasets.GeneratorBasedBuilder):
40
+ """TODO: Short description of my dataset."""
41
+
42
+ VERSION = datasets.Version("1.1.0")
43
+
44
+ # This is an example of a dataset with multiple configurations.
45
+ # If you don't want/need to define several sub-sets in your dataset,
46
+ # just remove the BUILDER_CONFIG_CLASS and the BUILDER_CONFIGS attributes.
47
+
48
+ # If you need to make complex sub-parts in the datasets with configurable options
49
+ # You can create your own builder configuration class to store attribute, inheriting from datasets.BuilderConfig
50
+ # BUILDER_CONFIG_CLASS = MyBuilderConfig
51
+
52
+ # You will be able to load one or the other configurations in the following list with
53
+ # data = datasets.load_dataset('my_dataset', 'first_domain')
54
+ # data = datasets.load_dataset('my_dataset', 'second_domain')
55
+ BUILDER_CONFIGS = [
56
+ datasets.BuilderConfig(name="validation", version=VERSION, description="validation"),
57
+ ]
58
+
59
+ DEFAULT_CONFIG_NAME = "validation" # It's not mandatory to have a default configuration. Just use one if it make sense.
60
+
61
+ def _info(self):
62
+ # datasets.DatasetInfo object which contains informations and typings for the dataset
63
+ features = datasets.Features(
64
+ {
65
+ "sentence_a": datasets.Value("string"),
66
+ "sentence_b": datasets.Value("string"),
67
+ "label": datasets.Value("int"),
68
+ "score": datasets.Value("float"),
69
+ "annotated": datasets.Value("int")
70
+ }
71
+ )
72
+ return datasets.DatasetInfo(
73
+ # This is the description that will appear on the datasets page.
74
+ description=_DESCRIPTION,
75
+ # This defines the different columns of the dataset and their types
76
+ features=features, # Here we define them above because they are different between the two configurations
77
+ # common (input, target) tuple from the features to use if as_supervised=True
78
+ supervised_keys=(('sentence_a', 'sentence_b'), 'score'),
79
+ # Homepage of the dataset for documentation
80
+ homepage=_HOMEPAGE,
81
+ # License for the dataset if available
82
+ license=_LICENSE,
83
+ # Citation for the dataset
84
+ citation=_CITATION,
85
+ )
86
+
87
+ def _split_generators(self, dl_manager):
88
+ """Returns SplitGenerators."""
89
+ # TODO: This method is tasked with downloading/extracting the data and defining the splits depending on the configuration
90
+ # If several configurations are possible (listed in BUILDER_CONFIGS), the configuration selected by the user is in self.config.name
91
+
92
+ # dl_manager is a datasets.download.DownloadManager that can be used to download and extract URLs
93
+ # 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.
94
+ # By default the archives will be extracted and a path to a cached folder where they are extracted is returned instead of the archive
95
+ my_urls = _URLs[self.config.name]
96
+ data_dir = dl_manager.download_and_extract(my_urls)
97
+ return [
98
+ datasets.SplitGenerator(
99
+ name=datasets.Split.VALIDATION,
100
+ # These kwargs will be passed to _generate_examples
101
+ gen_kwargs={
102
+ "filepath": os.path.join(data_dir, "train.jsonl"),
103
+ "split": "validation",
104
+ },
105
+ )
106
+ ]
107
+
108
+ def _generate_examples(
109
+ self, filepath, split # method parameters are unpacked from `gen_kwargs` as given in `_split_generators`
110
+ ):
111
+ """ Yields examples as (key, example) tuples. """
112
+ # This method handles input defined in _split_generators to yield (key, example) tuples from the dataset.
113
+ # The `key` is here for legacy reason (tfds) and is not important in itself.
114
+
115
+ with open(filepath, encoding="utf-8") as f:
116
+ for id_, row in enumerate(f):
117
+ data = json.loads(row)
118
+ yield id_, {
119
+ "sentence_a": data["sentence_a"],
120
+ "sentence_b": data["sentence_b"],
121
+ "label": data["label"],
122
+ "score": data["score"],
123
+ "annotated": data["annotated"]
124
+ }