File size: 6,262 Bytes
12cd1e9
 
 
 
b3f68bd
fd85304
 
12cd1e9
 
 
 
 
 
 
 
 
7204bfa
12cd1e9
 
 
7204bfa
12cd1e9
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
7204bfa
12cd1e9
 
 
 
 
 
7204bfa
12cd1e9
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
7204bfa
12cd1e9
 
 
 
7204bfa
12cd1e9
 
 
 
 
 
72aed7c
 
 
 
 
 
 
 
 
12cd1e9
72aed7c
 
 
 
 
 
 
 
 
12cd1e9
 
72aed7c
 
 
 
fd85304
72aed7c
fd85304
 
38504c2
 
 
 
7204bfa
38504c2
 
 
 
e8c1fe3
 
fd85304
 
 
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
157
158
159
160
161
162
163
164
165
166
167
168
"""SciLay Dataset."""

import gzip
import json
import os
import random
import string

import datasets

_HOMEPAGE = ""

_CITATION = """
"""

_DESCRIPTION = """
SCILAY comprises 43,790 instances, each representing a scientific article in the biomedical domain. 
Each instance in the dataset includes the following components:
    - plain_text: Containing a plain language summary of the scientific article. This section is written in a simple and accessible language, and is intended to be understandable by a wide audience.
    - technical_text: This section contains the abstract of the scientific article. It provides a detailed and technical description of the research conducted in the article.
    - full_text: This section contains the complete article of the scientific research
In addition to the textual content, each instance is associated with the following metadata:
    - Keywords: Keywords that capture the main topics and themes addressed in the article.
    - Journal: The journal in which the article is published, providing context about the source of the research.
    - DOI (Digital Object Identifier): A unique identifier for the article, facilitating easy referencing.
The main objective of the SCILAY dataset is to support the development and evaluation of text summarization models that can effectively simplify complex scientific language while retaining the essential information. 
"""

_LICENSE = "Creative Commons Attribution 4.0 International"

_SPLIT_NAMES = {datasets.Split.TRAIN: "train", datasets.Split.VALIDATION: "validation", datasets.Split.TEST: "test"}
_URL = "data/{version}/{split_name}.zip"

_DOI = "doi"
_PMCID = "pmcid"
_SUMMARY = "plain_text"
_ABSTRACT = "technical_text"
_FULL_TEXT = "full_text"
_JOURNAL = "journal"
_TOPICS = "topics"
_KEYWORDS = "keywords"

_JOURNALS = {
    "NC": "Nature Communications",
    "A": "Animals : an Open Access Journal from MDPI",
    "PLGEN": "PLoS Genetics",
    "PLPAT": "PLoS Pathogens",
    "PLCB": "PLoS Computational Biology",
    "PLNTD": "PLoS Neglected Tropical Diseases",
    "B": "Biology",
    "I": "Insects",
    "EL": "eLife",
    "PLB": "PLoS Biology",
    "CB": "Communications Biology",
    "SD": "Scientific Data",
    "MBIO": "mBio",
    "C": "Cancers",
    "OTHER": "Others"
}

# Available versions:
# 1.0.0 cased raw strings.

_VERSION = "1.0.0"

class SciLayConfig(datasets.BuilderConfig):
    """BuilderConfig for SciLay."""

    def __init__(self, journals="all", version=_VERSION, **kwargs):
        """BuilderConfig for SciLay.
        Args:
            journals (str or list, default 'all'): List of journal names. Either 'all' or a combination
                of {'NC', 'A', 'NIHR', 'PLGEN', 'PLPAT', 'PLCB', 'PLNTD', 'B', 'I', 'EL', 'PLB', 'CB', 'SD', 'MBIO', 'C', 'OTHER'}.
            **kwargs: keyword arguments forwarded to super.
        """
        if isinstance(journals, str):
            journals = [journals]
        name = "+".join(journals)
        if name == "all":
            journals = list(_JOURNALS) 
        if version != _VERSION:
            name = f"{name}-{version}"
        super().__init__(name=name, version=version, **kwargs)
        self.journals = journals

class SciLay(datasets.GeneratorBasedBuilder):
    """SciLay datasets."""

    BUILDER_CONFIG_CLASS = SciLayConfig
    BUILDER_CONFIGS = [
        SciLayConfig(
            journals="all",
            description="Articles from all journals.",
        ),
    ] + [
        SciLayConfig(
            journals=k,
            description=f"Articles from journals {k}: {v}",
        )
        for k, v in sorted(_JOURNALS.items())
    ]
    DEFAULT_CONFIG_NAME = "all"
    VERSION = _VERSION

    def _info(self):
        return datasets.DatasetInfo(
            description=_DESCRIPTION,
            features=datasets.Features({
                _DOI: datasets.Value("string"),
                _PMCID: datasets.Value("string"),
                _SUMMARY: datasets.Value("string"),
                _ABSTRACT: datasets.Value("string"),
                _FULL_TEXT: datasets.Value("string"),
                _JOURNAL: datasets.Value("string"),
                _TOPICS: datasets.Sequence(datasets.Value("string")),
                _KEYWORDS: datasets.Sequence(datasets.Value("string"))
            }),
            supervised_keys=(_FULL_TEXT, _SUMMARY),
            homepage=_HOMEPAGE,
            license=_LICENSE,
            citation=_CITATION,
        )

    def _split_generators(self, dl_manager):
        """Returns SplitGenerators."""
        urls = {
            split: _URL.format(version=self.config.version, split_name=split_name)
            for split, split_name in _SPLIT_NAMES.items()
        }
        dl_paths = dl_manager.download_and_extract(urls)
        paths = {
            split: [
                dl_manager.iter_files(os.path.join(dl_paths[split], split_name, code)) for code in self.config.journals
            ]
            for split, split_name in _SPLIT_NAMES.items()
        }
        return [
            datasets.SplitGenerator(
                name=split,
                gen_kwargs={"paths": paths[split]},
            )
            for split in _SPLIT_NAMES
        ]

    def _generate_examples(self, paths=None):
        """Yields examples."""
        for paths_per_journal in paths:
            for path in paths_per_journal:
                with open(path, "rb") as fin:
                    for row in fin:
                        json_obj = json.loads(row)
                        unique_key = f"{json_obj[_DOI]}_{generate_random_string()}"
                        yield unique_key, {
                            _DOI: json_obj[_DOI],
                            _PMCID: json_obj[_PMCID],
                            _SUMMARY: json_obj[_SUMMARY],
                            _ABSTRACT: json_obj[_ABSTRACT],
                            _FULL_TEXT: json_obj[_FULL_TEXT],
                            _JOURNAL: json_obj[_JOURNAL],
                            _TOPICS: json_obj[_TOPICS],
                            _KEYWORDS: json_obj[_KEYWORDS]
                        }


def generate_random_string(length=10):
    letters = string.ascii_lowercase + string.ascii_uppercase
    return ''.join(random.choice(letters) for _ in range(length))