ArneBinder commited on
Commit
f4ff05c
1 Parent(s): e9b98ed

Upload 3 files

Browse files
Files changed (3) hide show
  1. README.md +25 -0
  2. requirements.txt +1 -0
  3. sciarg.py +69 -0
README.md ADDED
@@ -0,0 +1,25 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # PIE Dataset Card for "sciarg"
2
+
3
+ This is a [PyTorch-IE](https://github.com/ChristophAlt/pytorch-ie) wrapper for the SciArg dataset.
4
+
5
+ TODO: Since there is no respective HF dataset card for SciArg, we should all respective information here.
6
+
7
+ TODO: Shortly reference the PIE-Brat dataset card.
8
+
9
+ ## Data Schema
10
+
11
+ TODO
12
+
13
+ See [here](https://github.com/ChristophAlt/pytorch-ie/blob/main/src/pytorch_ie/annotations.py) for the remaining annotation type definitions.
14
+
15
+ ## Document Converters
16
+
17
+ The dataset provides document converters for the following target document types:
18
+
19
+ - `pytorch_ie.documents.TextDocumentWithLabeledSpansAndBinaryRelations`
20
+ - TODO
21
+ - `pytorch_ie.documents.TextDocumentWithLabeledSpansBinaryRelationsAndLabeledPartitions`
22
+ - TODO (may reference the above)
23
+
24
+ See [here](https://github.com/ChristophAlt/pytorch-ie/blob/main/src/pytorch_ie/documents.py) for the document type
25
+ definitions.
requirements.txt ADDED
@@ -0,0 +1 @@
 
 
1
+ pie-datasets>=0.4.0,<0.5.0
sciarg.py ADDED
@@ -0,0 +1,69 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ from pytorch_ie.core import Document
2
+ from pytorch_ie.documents import (
3
+ TextDocumentWithLabeledSpansAndBinaryRelations,
4
+ TextDocumentWithLabeledSpansBinaryRelationsAndLabeledPartitions,
5
+ )
6
+
7
+ from pie_datasets.builders import BratBuilder
8
+ from pie_datasets.core.dataset import DocumentConvertersType
9
+ from pie_datasets.document.processing import (
10
+ Caster,
11
+ Pipeline,
12
+ RegexPartitioner,
13
+ RelationArgumentSorter,
14
+ TextSpanTrimmer,
15
+ )
16
+
17
+ URL = "http://data.dws.informatik.uni-mannheim.de/sci-arg/compiled_corpus.zip"
18
+ SPLIT_PATHS = {"train": "compiled_corpus"}
19
+
20
+
21
+ def get_common_pipeline_steps(target_document_type: type[Document]) -> dict:
22
+ return dict(
23
+ cast=Caster(
24
+ document_type=target_document_type,
25
+ field_mapping={"spans": "labeled_spans", "relations": "binary_relations"},
26
+ ),
27
+ trim_adus=TextSpanTrimmer(layer="labeled_spans"),
28
+ sort_symmetric_relation_arguments=RelationArgumentSorter(
29
+ relation_layer="binary_relations",
30
+ label_whitelist=["parts_of_same", "semantically_same"],
31
+ ),
32
+ )
33
+
34
+
35
+ class SciArg(BratBuilder):
36
+ BASE_DATASET_PATH = "DFKI-SLT/brat"
37
+ BASE_DATASET_REVISION = "052163d34b4429d81003981bc10674cef54aa0b8"
38
+
39
+ # we need to add None to the list of dataset variants to support the default dataset variant
40
+ BASE_BUILDER_KWARGS_DICT = {
41
+ dataset_variant: {"url": URL, "split_paths": SPLIT_PATHS}
42
+ for dataset_variant in ["default", "merge_fragmented_spans", None]
43
+ }
44
+
45
+ @property
46
+ def document_converters(self) -> DocumentConvertersType:
47
+ if self.config.name == "default":
48
+ return {}
49
+ elif self.config.name == "merge_fragmented_spans":
50
+ return {
51
+ TextDocumentWithLabeledSpansAndBinaryRelations: Pipeline(
52
+ **get_common_pipeline_steps(TextDocumentWithLabeledSpansAndBinaryRelations)
53
+ ),
54
+ TextDocumentWithLabeledSpansBinaryRelationsAndLabeledPartitions: Pipeline(
55
+ **get_common_pipeline_steps(
56
+ TextDocumentWithLabeledSpansBinaryRelationsAndLabeledPartitions
57
+ ),
58
+ add_partitions=RegexPartitioner(
59
+ partition_layer_name="labeled_partitions",
60
+ pattern="<([^>/]+)>.*</\\1>",
61
+ label_group_id=1,
62
+ label_whitelist=["Title", "Abstract", "H1"],
63
+ skip_initial_partition=True,
64
+ strip_whitespace=True,
65
+ ),
66
+ ),
67
+ }
68
+ else:
69
+ raise ValueError(f"Unknown dataset variant: {self.config.name}")