File size: 6,473 Bytes
b20f326
51f604c
 
 
 
ed41cbe
 
 
 
 
 
 
51f604c
 
 
ed41cbe
bc07c01
51f604c
ed41cbe
51f604c
ed41cbe
 
51f604c
 
 
 
 
c399f07
51f604c
 
 
 
 
900a98b
51f604c
 
f2caa84
51f604c
 
bc07c01
 
 
 
 
51f604c
 
bc07c01
51f604c
 
bc07c01
51f604c
 
1dc0337
51f604c
900a98b
 
51f604c
ae7ce03
bc07c01
51f604c
 
1dc0337
51f604c
 
900a98b
 
51f604c
 
 
 
 
1dc0337
51f604c
c399f07
51f604c
 
 
 
 
bc07c01
51f604c
 
900a98b
51f604c
 
 
 
 
 
bc07c01
51f604c
 
 
 
 
 
 
 
bc07c01
51f604c
 
c399f07
 
 
 
 
 
 
 
51f604c
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
b20f326
 
 
51f604c
 
 
c399f07
51f604c
900a98b
51f604c
bc07c01
51f604c
5ad03aa
51f604c
900a98b
 
51f604c
 
 
5ad03aa
51f604c
f2fb736
900a98b
 
 
51f604c
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
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
import json
import datasets

# _SPLIT = ['train', 'test', 'valid']
_CITATION = """\
@inproceedings{hulth2003improved,
  title={Improved automatic keyword extraction given more linguistic knowledge},
  author={Hulth, Anette},
  booktitle={Proceedings of the 2003 conference on Empirical methods in natural language processing},
  pages={216--223},
  year={2003}
}
"""

_DESCRIPTION = """\
Benchmark dataset for automatic identification of keyphrases from text published with the work - Improved automatic keyword extraction given more linguistic knowledge. Anette Hulth. In Proceedings of EMNLP 2003. p. 216-223.
"""

_HOMEPAGE = "https://aclanthology.org/W03-1028.pdf"

# The license information was obtained from https://github.com/boudinfl/ake-datasets as the dataset shared over here is taken from here
_LICENSE = "Apache 2.0 License"

# TODO: Add link to the official dataset URLs here

_URLS = {
    "test": "test.jsonl",
    "train": "train.jsonl",
    "valid": "valid.jsonl"
}


# TODO: Name of the dataset usually match the script name with CamelCase instead of snake_case
class Inspec(datasets.GeneratorBasedBuilder):
    """TODO: Short description of my dataset."""

    VERSION = datasets.Version("0.0.1")

    BUILDER_CONFIGS = [
        datasets.BuilderConfig(name="extraction", version=VERSION,
                               description="This part of my dataset covers extraction"),
        datasets.BuilderConfig(name="generation", version=VERSION,
                               description="This part of my dataset covers generation"),
        datasets.BuilderConfig(name="raw", version=VERSION, description="This part of my dataset covers the raw data"),
    ]

    DEFAULT_CONFIG_NAME = "extraction"

    def _info(self):
        if self.config.name == "extraction":  # This is the name of the configuration selected in BUILDER_CONFIGS above
            features = datasets.Features(
                {
                    "id": datasets.Value("int64"),
                    "document": datasets.features.Sequence(datasets.Value("string")),
                    "doc_bio_tags": datasets.features.Sequence(datasets.Value("string"))

                }
            )
        elif self.config.name == "generation":
            features = datasets.Features(
                {
                    "id": datasets.Value("int64"),
                    "document": datasets.features.Sequence(datasets.Value("string")),
                    "extractive_keyphrases": datasets.features.Sequence(datasets.Value("string")),
                    "abstractive_keyphrases": datasets.features.Sequence(datasets.Value("string"))

                }
            )
        else:
            features = datasets.Features(
                {
                    "id": datasets.Value("int64"),
                    "document": datasets.features.Sequence(datasets.Value("string")),
                    "doc_bio_tags": datasets.features.Sequence(datasets.Value("string")),
                    "extractive_keyphrases": datasets.features.Sequence(datasets.Value("string")),
                    "abstractive_keyphrases": datasets.features.Sequence(datasets.Value("string")),
                    "other_metadata": datasets.features.Sequence(
                        {
                            "text": datasets.features.Sequence(datasets.Value("string")),
                            "bio_tags": datasets.features.Sequence(datasets.Value("string"))
                        }
                    )

                }
            )
        return datasets.DatasetInfo(
            # This is the description that will appear on the datasets page.
            description=_DESCRIPTION,
            # This defines the different columns of the dataset and their types
            features=features,
            homepage=_HOMEPAGE,
            # License for the dataset if available
            license=_LICENSE,
            # Citation for the dataset
            citation=_CITATION,
        )

    def _split_generators(self, dl_manager):

        data_dir = dl_manager.download_and_extract(_URLS)
        return [
            datasets.SplitGenerator(
                name=datasets.Split.TRAIN,
                # These kwargs will be passed to _generate_examples
                gen_kwargs={
                    "filepath": data_dir['train'],
                    "split": "train",
                },
            ),
            datasets.SplitGenerator(
                name=datasets.Split.TEST,
                # These kwargs will be passed to _generate_examples
                gen_kwargs={
                    "filepath": data_dir['test'],
                    "split": "test"
                },
            ),
            datasets.SplitGenerator(
                name=datasets.Split.VALIDATION,
                # These kwargs will be passed to _generate_examples
                gen_kwargs={
                    "filepath": data_dir['valid'],
                    "split": "valid",
                },
            ),
        ]

    # method parameters are unpacked from `gen_kwargs` as given in `_split_generators`
    def _generate_examples(self, filepath, split):
        with open(filepath, encoding="utf-8") as f:
            for key, row in enumerate(f):
                data = json.loads(row)
                if self.config.name == "extraction":
                    # Yields examples as (key, example) tuples
                    yield key, {
                        "id": data['paper_id'],
                        "document": data["document"],
                        "doc_bio_tags": data.get("doc_bio_tags")
                    }
                elif self.config.name == "generation":
                    yield key, {
                        "id": data['paper_id'],
                        "document": data["document"],
                        "extractive_keyphrases": data.get("extractive_keyphrases"),
                        "abstractive_keyphrases": data.get("abstractive_keyphrases")
                    }
                else:
                    yield key, {
                        "id": data['paper_id'],
                        "document": data["document"],
                        "doc_bio_tags": data.get("doc_bio_tags"),
                        "extractive_keyphrases": data.get("extractive_keyphrases"),
                        "abstractive_keyphrases": data.get("abstractive_keyphrases"),
                        "other_metadata": data["other_metadata"]
                    }