MHoubre commited on
Commit
87941da
1 Parent(s): 122366d

first commit

Browse files
Files changed (2) hide show
  1. data.jsonl +3 -0
  2. pubmed.py +123 -0
data.jsonl ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:a03b0b004ab77c9ada8e4fcc6912d023ef85905cf80b2415a1bc032fdcfdf888
3
+ size 40569656
pubmed.py ADDED
@@ -0,0 +1,123 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ """Inspec benchmark dataset for keyphrase extraction an generation."""
2
+
3
+
4
+ import csv
5
+ import json
6
+ import os
7
+
8
+ import datasets
9
+
10
+
11
+
12
+
13
+ # You can copy an official description
14
+ _DESCRIPTION = """\
15
+ PubMed benchmark dataset for keyphrase extraction and generation.
16
+ """
17
+
18
+ # TODO: Add a link to an official homepage for the dataset here
19
+ _HOMEPAGE = "[schutz-2008]: https://github.com/snkim/AutomaticKeyphraseExtraction/blob/master/Schutz2008.tar.gz"
20
+
21
+ _LICENSE = ""
22
+
23
+ _CITATION = """@MasterThesis{Schutz:2008,
24
+ author = {Alexander Thorsten Schutz},
25
+ title = {Keyphrase Extraction from Single Documents in the Open Domain Exploiting Linguistic and Statistical Methods},
26
+ booktitle = {National University of Ireland},
27
+ year = {2008}
28
+ }"""
29
+
30
+ # TODO: Add link to the official dataset URLs here
31
+ # The HuggingFace Datasets library doesn't host the datasets but only points to the original files.
32
+ # This can be an arbitrary nested dict/list of URLs (see below in `_split_generators` method)
33
+ _URLS = {
34
+ "test": "data.jsonl",
35
+ }
36
+
37
+ # TODO: Name of the dataset usually match the script name with CamelCase instead of snake_case
38
+ class Pubmed(datasets.GeneratorBasedBuilder):
39
+ """TODO: Short description of my dataset."""
40
+
41
+ VERSION = datasets.Version("1.0.0")
42
+
43
+ # This is an example of a dataset with multiple configurations.
44
+ # If you don't want/need to define several sub-sets in your dataset,
45
+ # just remove the BUILDER_CONFIG_CLASS and the BUILDER_CONFIGS attributes.
46
+
47
+ # If you need to make complex sub-parts in the datasets with configurable options
48
+ # You can create your own builder configuration class to store attribute, inheriting from datasets.BuilderConfig
49
+ # BUILDER_CONFIG_CLASS = MyBuilderConfig
50
+
51
+ # You will be able to load one or the other configurations in the following list with
52
+ # data = datasets.load_dataset('my_dataset', 'first_domain')
53
+ # data = datasets.load_dataset('my_dataset', 'second_domain')
54
+ BUILDER_CONFIGS = [
55
+ datasets.BuilderConfig(name="raw", version=VERSION, description="This part of my dataset covers the raw data."),
56
+ ]
57
+
58
+ DEFAULT_CONFIG_NAME = "raw" # It's not mandatory to have a default configuration. Just use one if it make sense.
59
+
60
+ def _info(self):
61
+ # TODO: This method specifies the datasets.DatasetInfo object which contains informations and typings for the dataset
62
+ if self.config.name == "raw": # This is the name of the configuration selected in BUILDER_CONFIGS above
63
+ features = datasets.Features(
64
+ {
65
+ "id": datasets.Value("string"),
66
+ "text": datasets.Value("string"),
67
+ "keyphrases": datasets.features.Sequence(datasets.Value("string")),
68
+ "stemmed_keyphrases": datasets.features.Sequence(datasets.Value("string"))
69
+ }
70
+ )
71
+ return datasets.DatasetInfo(
72
+ # This is the description that will appear on the datasets page.
73
+ description=_DESCRIPTION,
74
+ # This defines the different columns of the dataset and their types
75
+ features=features, # Here we define them above because they are different between the two configurations
76
+ # If there's a common (input, target) tuple from the features, uncomment supervised_keys line below and
77
+ # specify them. They'll be used if as_supervised=True in builder.as_dataset.
78
+ # supervised_keys=("sentence", "label"),
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
+ # TODO: This method is tasked with downloading/extracting the data and defining the splits depending on the configuration
89
+ # If several configurations are possible (listed in BUILDER_CONFIGS), the configuration selected by the user is in self.config.name
90
+
91
+ # dl_manager is a datasets.download.DownloadManager that can be used to download and extract URLS
92
+ # 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.
93
+ # By default the archives will be extracted and a path to a cached folder where they are extracted is returned instead of the archive
94
+ urls = _URLS
95
+ data_dir = dl_manager.download_and_extract(urls)
96
+ return [
97
+
98
+ datasets.SplitGenerator(
99
+ name=datasets.Split.TEST,
100
+ # These kwargs will be passed to _generate_examples
101
+ gen_kwargs={
102
+ "filepath": os.path.join(data_dir["test"]),
103
+ "split": "test"
104
+ },
105
+ )
106
+
107
+ ]
108
+
109
+ # method parameters are unpacked from `gen_kwargs` as given in `_split_generators`
110
+ def _generate_examples(self, filepath, split):
111
+ # TODO: This method handles input defined in _split_generators to yield (key, example) tuples from the dataset.
112
+ # The `key` is for legacy reasons (tfds) and is not important in itself, but must be unique for each example.
113
+ with open(filepath, encoding="utf-8") as f:
114
+ for key, row in enumerate(f):
115
+ data = json.loads(row)
116
+ # Yields examples as (key, example) tuples
117
+ yield key, {
118
+ "id": data["id"],
119
+ "text": data["text"],
120
+ "keyphrases": data["keyphrases"],
121
+ "stemmed_keyphrases": data["stemmed_keyphrases"]
122
+ }
123
+