ArneBinder commited on
Commit
8d20d7e
1 Parent(s): a411eb7

Upload 3 files

Browse files
Files changed (3) hide show
  1. README.md +15 -0
  2. requirements.txt +2 -0
  3. scientific_papers.py +106 -0
README.md ADDED
@@ -0,0 +1,15 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # PIE Dataset Card for "scientific_papers"
2
+
3
+ This is a [PyTorch-IE](https://github.com/ChristophAlt/pytorch-ie) wrapper for the
4
+ [scientific_papers Huggingface dataset loading script](https://huggingface.co/datasets/scientific_papers).
5
+
6
+ ## Data Schema
7
+
8
+ The document type for this dataset is `ScientificPapersDocument` which defines the following data fields:
9
+
10
+ - `text` (str)
11
+
12
+ and the following annotation layers:
13
+
14
+ - `abstract` (annotation type: `AbstractiveSummary`, target: `None`)
15
+ - `section_names` (annotation type: `SectionName`, targets: `None`)
requirements.txt ADDED
@@ -0,0 +1,2 @@
 
 
 
1
+ pie-datasets>=0.8.0,<0.9.0
2
+ pie-modules>=0.8.2,<0.9.0
scientific_papers.py ADDED
@@ -0,0 +1,106 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import dataclasses
2
+ from typing import Any, Dict, List
3
+
4
+ import datasets
5
+ from pytorch_ie.core import (
6
+ Annotation,
7
+ AnnotationLayer,
8
+ AnnotationList,
9
+ annotation_field,
10
+ )
11
+ from pytorch_ie.documents import TextBasedDocument
12
+
13
+ from pie_datasets import GeneratorBasedBuilder
14
+
15
+
16
+ @dataclasses.dataclass(eq=True, frozen=True)
17
+ class AbstractiveSummary(Annotation):
18
+ """A question about a context."""
19
+
20
+ text: str
21
+
22
+ def __str__(self) -> str:
23
+ return self.text
24
+
25
+
26
+ @dataclasses.dataclass(eq=True, frozen=True)
27
+ class SectionName(Annotation):
28
+ """A question about a context."""
29
+
30
+ text: str
31
+
32
+ def __str__(self) -> str:
33
+ return self.text
34
+
35
+
36
+ @dataclasses.dataclass
37
+ class ScientificPapersDocument(TextBasedDocument):
38
+ """A PIE document for scientific papers dataset."""
39
+
40
+ abstract: AnnotationLayer[AbstractiveSummary] = annotation_field()
41
+ section_names: AnnotationList[SectionName] = annotation_field()
42
+
43
+
44
+ def example_to_document(
45
+ example: Dict[str, Any],
46
+ ) -> ScientificPapersDocument:
47
+ """Convert a Huggingface Scientific Papers example to a PIE document."""
48
+ document = ScientificPapersDocument(
49
+ text=example["article"],
50
+ )
51
+ document.abstract.append(AbstractiveSummary(text=example["abstract"]))
52
+ document.section_names.extend(
53
+ [SectionName(text=section_name) for section_name in example["section_names"].split("\n")]
54
+ )
55
+
56
+ return document
57
+
58
+
59
+ def document_to_example(doc: ScientificPapersDocument) -> Dict[str, Any]:
60
+ """Convert a PIE document to a Huggingface Scientific Papers example."""
61
+ example = {
62
+ "article": doc.text,
63
+ "abstract": doc.abstract[0].text,
64
+ "section_names": "\n".join([section_name.text for section_name in doc.section_names]),
65
+ }
66
+ return example
67
+
68
+
69
+ class ScientificPapersConfig(datasets.BuilderConfig):
70
+ """BuilderConfig for Scientific Papers."""
71
+
72
+ def __init__(self, **kwargs):
73
+ """BuilderConfig for Scientific Papers.
74
+
75
+ Args:
76
+ **kwargs: keyword arguments forwarded to super.
77
+ """
78
+ super().__init__(**kwargs)
79
+
80
+
81
+ class ScientificPapers(GeneratorBasedBuilder):
82
+ DOCUMENT_TYPE = ScientificPapersDocument
83
+
84
+ BASE_DATASET_PATH = "scientific_papers"
85
+ BASE_DATASET_REVISION = "14c5296f2d707630f5835c9da59dcaddeea19b20"
86
+
87
+ BUILDER_CONFIGS = [
88
+ ScientificPapersConfig(
89
+ name="arxiv",
90
+ version=datasets.Version("1.1.1"),
91
+ description="Scientific Papers dataset - ArXiv variant",
92
+ ),
93
+ ScientificPapersConfig(
94
+ name="pubmed",
95
+ version=datasets.Version("1.1.1"),
96
+ description="Scientific Papers dataset - PubMed variant",
97
+ ),
98
+ ]
99
+
100
+ DEFAULT_CONFIG_NAME = "arxiv"
101
+
102
+ def _generate_document(self, example, **kwargs):
103
+ return example_to_document(example)
104
+
105
+ def _generate_example(self, document, **kwargs):
106
+ return document_to_example(document)