from https://github.com/ArneBinder/pie-datasets/pull/103
#3
by
ArneBinder
- opened
- README.md +69 -38
- img/leaannof3.png +3 -0
- img/sciarg-sam.png +3 -0
- requirements.txt +2 -1
- sciarg.py +100 -24
README.md
CHANGED
@@ -22,13 +22,18 @@ The language in the dataset is English (scientific academic publications on comp
|
|
22 |
|
23 |
### Dataset Variants
|
24 |
|
25 |
-
The `sciarg` dataset comes in
|
26 |
-
|
27 |
-
|
|
|
|
|
28 |
to be because of the annotation tool used. In the `sciarg` dataset, we merge these fragments, so that the document type
|
29 |
-
can be `BratDocumentWithMergedSpans` (this is easier to handle for most of the task modules).
|
30 |
-
spans
|
31 |
-
|
|
|
|
|
|
|
32 |
|
33 |
### Data Schema
|
34 |
|
@@ -42,41 +47,28 @@ from pie_datasets import load_dataset, builders
|
|
42 |
# load default version
|
43 |
datasets = load_dataset("pie/sciarg")
|
44 |
doc = datasets["train"][0]
|
45 |
-
assert isinstance(doc, builders.brat.
|
46 |
|
47 |
-
# load version with
|
48 |
-
|
49 |
-
|
50 |
-
assert isinstance(
|
51 |
```
|
52 |
|
53 |
-
### Document Converters
|
54 |
-
|
55 |
-
The dataset provides document converters for the following target document types:
|
56 |
-
|
57 |
-
- `pytorch_ie.documents.TextDocumentWithLabeledSpansAndBinaryRelations`
|
58 |
-
- `LabeledSpans`, converted from `BratDocument`'s `spans`
|
59 |
-
- labels: `background_claim`, `own_claim`, `data`
|
60 |
-
- if `spans` contain whitespace at the beginning and/or the end, the whitespace are trimmed out.
|
61 |
-
- `BinraryRelations`, converted from `BratDocument`'s `relations`
|
62 |
-
- labels: `supports`, `contradicts`, `semantically_same`, `parts_of_same`
|
63 |
-
- if the `relations` label is `semantically_same` or `parts_of_same`, they are merged if they are the same arguments after sorting.
|
64 |
-
- `pytorch_ie.documents.TextDocumentWithLabeledSpansBinaryRelationsAndLabeledPartitions`
|
65 |
-
- `LabeledSpans`, as above
|
66 |
-
- `BinaryRelations`, as above
|
67 |
-
- `LabeledPartitions`, partitioned `BratDocument`'s `text`, according to the paragraph, using regex.
|
68 |
-
- labels: `title`, `abstract`, `H1`
|
69 |
-
|
70 |
-
See [here](https://github.com/ChristophAlt/pytorch-ie/blob/main/src/pytorch_ie/documents.py) for the document type
|
71 |
-
definitions.
|
72 |
-
|
73 |
### Data Splits
|
74 |
|
75 |
The dataset consists of a single `train` split that has 40 documents.
|
76 |
|
77 |
For detailed statistics on the corpus, see Lauscher et al. ([2018](<(https://aclanthology.org/W18-5206/)>), p. 43), and the author's [resource analysis](https://github.com/anlausch/sciarg_resource_analysis).
|
78 |
|
79 |
-
### Label Descriptions
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
80 |
|
81 |
#### Components
|
82 |
|
@@ -113,18 +105,57 @@ For detailed statistics on the corpus, see Lauscher et al. ([2018](<(https://acl
|
|
113 |
|
114 |
- `semantically_same`: between two mentions of effectively the same claim or data component. Can be seen as *argument coreference*, analogous to entity, and *event coreference*. This relation is considered symmetric (i.e., **bidirectional**) and non-argumentative.
|
115 |
(Lauscher et al. 2018, p.41; following [Dung, 1995](https://www.sciencedirect.com/science/article/pii/000437029400041X?via%3Dihub))
|
116 |
-
- `parts_of_same
|
117 |
|
118 |
(*Annotation Guidelines*, pp. 4-6)
|
119 |
|
120 |
-
|
121 |
|
122 |
-
|
123 |
|
124 |
-
|
125 |
-
- current report above here (labels counted in `BratDocument`'s);
|
126 |
|
127 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
128 |
|
129 |
## Dataset Creation
|
130 |
|
|
|
22 |
|
23 |
### Dataset Variants
|
24 |
|
25 |
+
The `sciarg` dataset comes in two versions: `default` and `resolve_parts_of_same`.
|
26 |
+
|
27 |
+
First, the `default` version with `BratDocumentWithMergedSpans` as document type.
|
28 |
+
In contrast to the base `brat` dataset, where the document type for the `default` variant is `BratDocument`,
|
29 |
+
the SciArg dataset was published with spans that are just fragmented by whitespace which seems
|
30 |
to be because of the annotation tool used. In the `sciarg` dataset, we merge these fragments, so that the document type
|
31 |
+
can be `BratDocumentWithMergedSpans` (this is easier to handle for most of the task modules).
|
32 |
+
Fragmented spans, which belong to the same argumentative unit, are marked with `parts_of_same` relations.
|
33 |
+
|
34 |
+
Second, the `resolve_parts_of_same` version with `BratDocument` as document type.
|
35 |
+
In this version, all fragmented spans which were separated by other argumentative or non-argumentative spans and
|
36 |
+
are connected via the `parts_of_same` relations are converted to `LabeledMultiSpans`.
|
37 |
|
38 |
### Data Schema
|
39 |
|
|
|
47 |
# load default version
|
48 |
datasets = load_dataset("pie/sciarg")
|
49 |
doc = datasets["train"][0]
|
50 |
+
assert isinstance(doc, builders.brat.BratDocumentWithMergedSpans)
|
51 |
|
52 |
+
# load version with resolved parts_of_same relations
|
53 |
+
datasets = load_dataset("pie/sciarg", name='resolve_parts_of_same')
|
54 |
+
doc = datasets["train"][0]
|
55 |
+
assert isinstance(doc, builders.brat.BratDocument)
|
56 |
```
|
57 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
58 |
### Data Splits
|
59 |
|
60 |
The dataset consists of a single `train` split that has 40 documents.
|
61 |
|
62 |
For detailed statistics on the corpus, see Lauscher et al. ([2018](<(https://aclanthology.org/W18-5206/)>), p. 43), and the author's [resource analysis](https://github.com/anlausch/sciarg_resource_analysis).
|
63 |
|
64 |
+
### Label Descriptions and Statistics
|
65 |
+
|
66 |
+
In this section, we report our own corpus' statistics; however, there are currently discrepancies in label counts between our report and:
|
67 |
+
|
68 |
+
- previous report in [Lauscher et al., 2018](https://aclanthology.org/W18-5206/), p. 43),
|
69 |
+
- current report above here (labels counted in `BratDocumentWithMergedSpans`'s);
|
70 |
+
|
71 |
+
possibly since [Lauscher et al., 2018](https://aclanthology.org/W18-5206/) presents the numbers of the real argumentative components, whereas here discontinuous components are still split (marked with the `parts_of_same` helper relation) and, thus, count per fragment.
|
72 |
|
73 |
#### Components
|
74 |
|
|
|
105 |
|
106 |
- `semantically_same`: between two mentions of effectively the same claim or data component. Can be seen as *argument coreference*, analogous to entity, and *event coreference*. This relation is considered symmetric (i.e., **bidirectional**) and non-argumentative.
|
107 |
(Lauscher et al. 2018, p.41; following [Dung, 1995](https://www.sciencedirect.com/science/article/pii/000437029400041X?via%3Dihub))
|
108 |
+
- `parts_of_same` (only in the `default` dataset variant): when a single component is split up in several parts. It is **non-argumentative**, **bidirectional**, but also **intra-component**
|
109 |
|
110 |
(*Annotation Guidelines*, pp. 4-6)
|
111 |
|
112 |
+
#### Examples
|
113 |
|
114 |
+
![sample1](img/leaannof3.png)
|
115 |
|
116 |
+
Above: Diagram from *Annotation Guildelines* (p.6)
|
|
|
117 |
|
118 |
+
Below: Subset of relations in `A01`
|
119 |
+
|
120 |
+
![sample2](img/sciarg-sam.png)
|
121 |
+
|
122 |
+
### Document Converters
|
123 |
+
|
124 |
+
The dataset provides document converters for the following target document types:
|
125 |
+
|
126 |
+
From `default` version:
|
127 |
+
|
128 |
+
- `pie_modules.documents.TextDocumentWithLabeledSpansAndBinaryRelations`
|
129 |
+
- `labeled_spans`: `LabeledSpan` annotations, converted from `BratDocumentWithMergedSpans`'s `spans`
|
130 |
+
- labels: `background_claim`, `own_claim`, `data`
|
131 |
+
- if `spans` contain whitespace at the beginning and/or the end, that whitespace is trimmed out.
|
132 |
+
- `binary_relations`: `BinaryRelation` annotations, converted from `BratDocumentWithMergedSpans`'s `relations`
|
133 |
+
- labels: `supports`, `contradicts`, `semantically_same`, `parts_of_same`
|
134 |
+
- if the `relations` label is `semantically_same` or `parts_of_same` (i.e. it is a symmetric relation), their arguments are sorted by their start and end indices.
|
135 |
+
- `pie_modules.documents.TextDocumentWithLabeledSpansBinaryRelationsAndLabeledPartitions`
|
136 |
+
- `labeled_spans`, as above
|
137 |
+
- `binary_relations`, as above
|
138 |
+
- `labeled_partitions`, `LabeledSpan` annotations, created from splitting `BratDocumentWithMergedSpans`'s `text` at new paragraph in `xml` format.
|
139 |
+
- labels: `title`, `abstract`, `H1`
|
140 |
+
|
141 |
+
From `resolve_parts_of_same` version:
|
142 |
+
|
143 |
+
- `pie_modules.documents.TextDocumentWithLabeledMultiSpansAndBinaryRelations`:
|
144 |
+
- `labeled_multi_spans`: `LabeledMultiSpan` annotations, converted from `BratDocument`'s `spans`
|
145 |
+
- labels: as above
|
146 |
+
- if spans contain whitespace at the beginning and/or the end, that whitespace is trimmed out.
|
147 |
+
- `binary_relations`: `BinaryRelation` annotations, converted from `BratDocument`'s `relations`
|
148 |
+
- labels: `supports`, `contradicts`, `semantically_same`
|
149 |
+
- in contrast to the `default` version, spans connected with `parts_of_same` relation are stored as one labeled multi-span
|
150 |
+
- if the `relations` label is `semantically_same` (i.e. it is a symmetric relation), their arguments are sorted by their start and end indices.
|
151 |
+
- `pie_modules.documents.TextDocumentWithLabeledMultiSpansBinaryRelationsAndLabeledPartitions`:
|
152 |
+
- `labeled_multi_spans`, as above
|
153 |
+
- `binary_relations`, as above
|
154 |
+
- `labeled_partitions`, `LabeledSpan` annotations, created from splitting `BratDocument`'s `text` at new paragraph in `xml` format.
|
155 |
+
- labels: `title`, `abstract`, `H1`
|
156 |
+
|
157 |
+
See [here](https://github.com/ArneBinder/pie-modules/blob/main/src/pie_modules/documents.py) for the document type
|
158 |
+
definitions.
|
159 |
|
160 |
## Dataset Creation
|
161 |
|
img/leaannof3.png
ADDED
Git LFS Details
|
img/sciarg-sam.png
ADDED
Git LFS Details
|
requirements.txt
CHANGED
@@ -1,2 +1,3 @@
|
|
1 |
pie-datasets>=0.6.0,<0.9.0
|
2 |
-
pie-modules>=0.8
|
|
|
|
1 |
pie-datasets>=0.6.0,<0.9.0
|
2 |
+
pie-modules>=0.10.8,<0.11.0
|
3 |
+
networkx>=3.0.0,<4.0.0
|
sciarg.py
CHANGED
@@ -1,23 +1,27 @@
|
|
1 |
from pie_modules.document.processing import (
|
2 |
RegexPartitioner,
|
3 |
RelationArgumentSorter,
|
|
|
4 |
TextSpanTrimmer,
|
5 |
)
|
6 |
-
from
|
7 |
-
|
|
|
8 |
TextDocumentWithLabeledSpansAndBinaryRelations,
|
9 |
TextDocumentWithLabeledSpansBinaryRelationsAndLabeledPartitions,
|
10 |
)
|
|
|
11 |
|
12 |
from pie_datasets.builders import BratBuilder, BratConfig
|
13 |
-
from pie_datasets.builders.brat import BratDocumentWithMergedSpans
|
|
|
14 |
from pie_datasets.document.processing import Caster, Pipeline
|
15 |
|
16 |
URL = "http://data.dws.informatik.uni-mannheim.de/sci-arg/compiled_corpus.zip"
|
17 |
SPLIT_PATHS = {"train": "compiled_corpus"}
|
18 |
|
19 |
|
20 |
-
def
|
21 |
return dict(
|
22 |
cast=Caster(
|
23 |
document_type=target_document_type,
|
@@ -31,6 +35,33 @@ def get_common_pipeline_steps(target_document_type: type[Document]) -> dict:
|
|
31 |
)
|
32 |
|
33 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
34 |
class SciArg(BratBuilder):
|
35 |
BASE_DATASET_PATH = "DFKI-SLT/brat"
|
36 |
BASE_DATASET_REVISION = "844de61e8a00dc6a93fc29dc185f6e617131fbf1"
|
@@ -39,33 +70,78 @@ class SciArg(BratBuilder):
|
|
39 |
# The span fragments in SciArg come just from the new line splits, so we can merge them.
|
40 |
# Actual span fragments are annotated via "parts_of_same" relations.
|
41 |
BUILDER_CONFIGS = [
|
42 |
-
|
|
|
43 |
]
|
44 |
DOCUMENT_TYPES = {
|
45 |
BratBuilder.DEFAULT_CONFIG_NAME: BratDocumentWithMergedSpans,
|
|
|
46 |
}
|
47 |
|
48 |
# we need to add None to the list of dataset variants to support the default dataset variant
|
49 |
BASE_BUILDER_KWARGS_DICT = {
|
50 |
dataset_variant: {"url": URL, "split_paths": SPLIT_PATHS}
|
51 |
-
for dataset_variant in ["default", "
|
52 |
}
|
53 |
|
54 |
-
|
55 |
-
|
56 |
-
|
57 |
-
|
58 |
-
|
59 |
-
|
60 |
-
|
61 |
-
|
62 |
-
|
63 |
-
|
64 |
-
|
65 |
-
|
66 |
-
|
67 |
-
|
68 |
-
|
69 |
-
|
70 |
-
|
71 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
from pie_modules.document.processing import (
|
2 |
RegexPartitioner,
|
3 |
RelationArgumentSorter,
|
4 |
+
SpansViaRelationMerger,
|
5 |
TextSpanTrimmer,
|
6 |
)
|
7 |
+
from pie_modules.documents import (
|
8 |
+
TextDocumentWithLabeledMultiSpansAndBinaryRelations,
|
9 |
+
TextDocumentWithLabeledMultiSpansBinaryRelationsAndLabeledPartitions,
|
10 |
TextDocumentWithLabeledSpansAndBinaryRelations,
|
11 |
TextDocumentWithLabeledSpansBinaryRelationsAndLabeledPartitions,
|
12 |
)
|
13 |
+
from pytorch_ie.core import Document
|
14 |
|
15 |
from pie_datasets.builders import BratBuilder, BratConfig
|
16 |
+
from pie_datasets.builders.brat import BratDocument, BratDocumentWithMergedSpans
|
17 |
+
from pie_datasets.core.dataset import DocumentConvertersType
|
18 |
from pie_datasets.document.processing import Caster, Pipeline
|
19 |
|
20 |
URL = "http://data.dws.informatik.uni-mannheim.de/sci-arg/compiled_corpus.zip"
|
21 |
SPLIT_PATHS = {"train": "compiled_corpus"}
|
22 |
|
23 |
|
24 |
+
def get_common_converter_pipeline_steps(target_document_type: type[Document]) -> dict:
|
25 |
return dict(
|
26 |
cast=Caster(
|
27 |
document_type=target_document_type,
|
|
|
35 |
)
|
36 |
|
37 |
|
38 |
+
def get_common_converter_pipeline_steps_with_resolve_parts_of_same(
|
39 |
+
target_document_type: type[Document],
|
40 |
+
) -> dict:
|
41 |
+
return dict(
|
42 |
+
cast=Caster(
|
43 |
+
document_type=target_document_type,
|
44 |
+
field_mapping={"spans": "labeled_multi_spans", "relations": "binary_relations"},
|
45 |
+
),
|
46 |
+
trim_adus=TextSpanTrimmer(layer="labeled_multi_spans"),
|
47 |
+
sort_symmetric_relation_arguments=RelationArgumentSorter(
|
48 |
+
relation_layer="binary_relations",
|
49 |
+
label_whitelist=["semantically_same"],
|
50 |
+
),
|
51 |
+
)
|
52 |
+
|
53 |
+
|
54 |
+
class SciArgConfig(BratConfig):
|
55 |
+
def __init__(
|
56 |
+
self,
|
57 |
+
name: str,
|
58 |
+
resolve_parts_of_same: bool = False,
|
59 |
+
**kwargs,
|
60 |
+
):
|
61 |
+
super().__init__(name=name, merge_fragmented_spans=True, **kwargs)
|
62 |
+
self.resolve_parts_of_same = resolve_parts_of_same
|
63 |
+
|
64 |
+
|
65 |
class SciArg(BratBuilder):
|
66 |
BASE_DATASET_PATH = "DFKI-SLT/brat"
|
67 |
BASE_DATASET_REVISION = "844de61e8a00dc6a93fc29dc185f6e617131fbf1"
|
|
|
70 |
# The span fragments in SciArg come just from the new line splits, so we can merge them.
|
71 |
# Actual span fragments are annotated via "parts_of_same" relations.
|
72 |
BUILDER_CONFIGS = [
|
73 |
+
SciArgConfig(name=BratBuilder.DEFAULT_CONFIG_NAME),
|
74 |
+
SciArgConfig(name="resolve_parts_of_same", resolve_parts_of_same=True),
|
75 |
]
|
76 |
DOCUMENT_TYPES = {
|
77 |
BratBuilder.DEFAULT_CONFIG_NAME: BratDocumentWithMergedSpans,
|
78 |
+
"resolve_parts_of_same": BratDocument,
|
79 |
}
|
80 |
|
81 |
# we need to add None to the list of dataset variants to support the default dataset variant
|
82 |
BASE_BUILDER_KWARGS_DICT = {
|
83 |
dataset_variant: {"url": URL, "split_paths": SPLIT_PATHS}
|
84 |
+
for dataset_variant in ["default", "resolve_parts_of_same", None]
|
85 |
}
|
86 |
|
87 |
+
def _generate_document(self, example, **kwargs):
|
88 |
+
document = super()._generate_document(example, **kwargs)
|
89 |
+
if self.config.resolve_parts_of_same:
|
90 |
+
document = SpansViaRelationMerger(
|
91 |
+
relation_layer="relations",
|
92 |
+
link_relation_label="parts_of_same",
|
93 |
+
create_multi_spans=True,
|
94 |
+
result_document_type=BratDocument,
|
95 |
+
result_field_mapping={"spans": "spans", "relations": "relations"},
|
96 |
+
)(document)
|
97 |
+
return document
|
98 |
+
|
99 |
+
@property
|
100 |
+
def document_converters(self) -> DocumentConvertersType:
|
101 |
+
regex_partitioner = RegexPartitioner(
|
102 |
+
partition_layer_name="labeled_partitions",
|
103 |
+
pattern="<([^>/]+)>.*</\\1>",
|
104 |
+
label_group_id=1,
|
105 |
+
label_whitelist=["Title", "Abstract", "H1"],
|
106 |
+
skip_initial_partition=True,
|
107 |
+
strip_whitespace=True,
|
108 |
+
)
|
109 |
+
if not self.config.resolve_parts_of_same:
|
110 |
+
return {
|
111 |
+
TextDocumentWithLabeledSpansAndBinaryRelations: Pipeline(
|
112 |
+
**get_common_converter_pipeline_steps(
|
113 |
+
TextDocumentWithLabeledSpansAndBinaryRelations
|
114 |
+
)
|
115 |
+
),
|
116 |
+
TextDocumentWithLabeledSpansBinaryRelationsAndLabeledPartitions: Pipeline(
|
117 |
+
**get_common_converter_pipeline_steps(
|
118 |
+
TextDocumentWithLabeledSpansBinaryRelationsAndLabeledPartitions
|
119 |
+
),
|
120 |
+
add_partitions=regex_partitioner,
|
121 |
+
),
|
122 |
+
}
|
123 |
+
else:
|
124 |
+
return {
|
125 |
+
# TextDocumentWithLabeledSpansAndBinaryRelations: Pipeline(
|
126 |
+
# **get_common_converter_pipeline_steps_with_resolve_parts_of_same(
|
127 |
+
# TextDocumentWithLabeledSpansAndBinaryRelations
|
128 |
+
# )
|
129 |
+
# ),
|
130 |
+
# TextDocumentWithLabeledSpansBinaryRelationsAndLabeledPartitions: Pipeline(
|
131 |
+
# **get_common_converter_pipeline_steps_with_resolve_parts_of_same(
|
132 |
+
# TextDocumentWithLabeledSpansBinaryRelationsAndLabeledPartitions
|
133 |
+
# ),
|
134 |
+
# add_partitions=regex_partitioner,
|
135 |
+
# ),
|
136 |
+
TextDocumentWithLabeledMultiSpansAndBinaryRelations: Pipeline(
|
137 |
+
**get_common_converter_pipeline_steps_with_resolve_parts_of_same(
|
138 |
+
TextDocumentWithLabeledMultiSpansAndBinaryRelations
|
139 |
+
)
|
140 |
+
),
|
141 |
+
TextDocumentWithLabeledMultiSpansBinaryRelationsAndLabeledPartitions: Pipeline(
|
142 |
+
**get_common_converter_pipeline_steps_with_resolve_parts_of_same(
|
143 |
+
TextDocumentWithLabeledMultiSpansBinaryRelationsAndLabeledPartitions
|
144 |
+
),
|
145 |
+
add_partitions=regex_partitioner,
|
146 |
+
),
|
147 |
+
}
|