integrate https://github.com/ArneBinder/pie-datasets/pull/103
Browse files- README.md +95 -40
- img/leaannof3.png +3 -0
- img/sciarg-sam.png +3 -0
- requirements.txt +2 -1
- sciarg.py +123 -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,49 +47,48 @@ 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 |
|
|
|
|
|
|
|
| 83 |
| Components | Count | Percentage |
|
| 84 |
| ------------------ | ----: | ---------: |
|
| 85 |
| `background_claim` | 3291 | 24.2 % |
|
| 86 |
| `own_claim` | 6004 | 44.2 % |
|
| 87 |
| `data` | 4297 | 31.6 % |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 88 |
|
| 89 |
- `own_claim` is an argumentative statement that closely relates to the authors’ own work.
|
| 90 |
- `background_claim` an argumentative statement relating to the background of authors’ work, e.g., about related work or common practices.
|
|
@@ -93,12 +97,24 @@ For detailed statistics on the corpus, see Lauscher et al. ([2018](<(https://acl
|
|
| 93 |
|
| 94 |
#### Relations
|
| 95 |
|
|
|
|
|
|
|
| 96 |
| Relations | Count | Percentage |
|
| 97 |
| -------------------------- | ----: | ---------: |
|
| 98 |
-
| support: `support` |
|
| 99 |
-
| attack: `contradict` |
|
| 100 |
| other: `semantically_same` | 44 | 0.6 % |
|
| 101 |
| other: `parts_of_same` | 1298 | 16.6 % |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 102 |
|
| 103 |
##### Argumentative relations
|
| 104 |
|
|
@@ -113,18 +129,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 |
|
| 75 |
+
`default` version:
|
| 76 |
+
|
| 77 |
| Components | Count | Percentage |
|
| 78 |
| ------------------ | ----: | ---------: |
|
| 79 |
| `background_claim` | 3291 | 24.2 % |
|
| 80 |
| `own_claim` | 6004 | 44.2 % |
|
| 81 |
| `data` | 4297 | 31.6 % |
|
| 82 |
+
| total | 13592 | 100.0 % |
|
| 83 |
+
|
| 84 |
+
`resolve_parts_of_same` version:
|
| 85 |
+
|
| 86 |
+
| Components | Count | Percentage |
|
| 87 |
+
| ------------------ | ----: | ---------: |
|
| 88 |
+
| `background_claim` | 2752 | 22.4 % |
|
| 89 |
+
| `own_claim` | 5450 | 44.3 % |
|
| 90 |
+
| `data` | 4093 | 33.3 % |
|
| 91 |
+
| total | 12295 | 100.0 % |
|
| 92 |
|
| 93 |
- `own_claim` is an argumentative statement that closely relates to the authors’ own work.
|
| 94 |
- `background_claim` an argumentative statement relating to the background of authors’ work, e.g., about related work or common practices.
|
|
|
|
| 97 |
|
| 98 |
#### Relations
|
| 99 |
|
| 100 |
+
`default` version:
|
| 101 |
+
|
| 102 |
| Relations | Count | Percentage |
|
| 103 |
| -------------------------- | ----: | ---------: |
|
| 104 |
+
| support: `support` | 5789 | 74.0 % |
|
| 105 |
+
| attack: `contradict` | 696 | 8.9 % |
|
| 106 |
| other: `semantically_same` | 44 | 0.6 % |
|
| 107 |
| other: `parts_of_same` | 1298 | 16.6 % |
|
| 108 |
+
| total | 7827 | 100.0 % |
|
| 109 |
+
|
| 110 |
+
`resolve_parts_of_same` version:
|
| 111 |
+
|
| 112 |
+
| Relations | Count | Percentage |
|
| 113 |
+
| -------------------------- | ----: | ---------: |
|
| 114 |
+
| support: `support` | 5788 | 88.7 % |
|
| 115 |
+
| attack: `contradict` | 696 | 10.7 % |
|
| 116 |
+
| other: `semantically_same` | 44 | 0.7 % |
|
| 117 |
+
| total | 6528 | 100.0 % |
|
| 118 |
|
| 119 |
##### Argumentative relations
|
| 120 |
|
|
|
|
| 129 |
|
| 130 |
- `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.
|
| 131 |
(Lauscher et al. 2018, p.41; following [Dung, 1995](https://www.sciencedirect.com/science/article/pii/000437029400041X?via%3Dihub))
|
| 132 |
+
- `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**
|
| 133 |
|
| 134 |
(*Annotation Guidelines*, pp. 4-6)
|
| 135 |
|
| 136 |
+
#### Examples
|
| 137 |
|
| 138 |
+

|
| 139 |
|
| 140 |
+
Above: Diagram from *Annotation Guildelines* (p.6)
|
|
|
|
| 141 |
|
| 142 |
+
Below: Subset of relations in `A01`
|
| 143 |
+
|
| 144 |
+

|
| 145 |
+
|
| 146 |
+
### Document Converters
|
| 147 |
+
|
| 148 |
+
The dataset provides document converters for the following target document types:
|
| 149 |
+
|
| 150 |
+
From `default` version:
|
| 151 |
+
|
| 152 |
+
- `pie_modules.documents.TextDocumentWithLabeledSpansAndBinaryRelations`
|
| 153 |
+
- `labeled_spans`: `LabeledSpan` annotations, converted from `BratDocumentWithMergedSpans`'s `spans`
|
| 154 |
+
- labels: `background_claim`, `own_claim`, `data`
|
| 155 |
+
- if `spans` contain whitespace at the beginning and/or the end, that whitespace is trimmed out.
|
| 156 |
+
- `binary_relations`: `BinaryRelation` annotations, converted from `BratDocumentWithMergedSpans`'s `relations`
|
| 157 |
+
- labels: `supports`, `contradicts`, `semantically_same`, `parts_of_same`
|
| 158 |
+
- 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.
|
| 159 |
+
- `pie_modules.documents.TextDocumentWithLabeledSpansBinaryRelationsAndLabeledPartitions`
|
| 160 |
+
- `labeled_spans`, as above
|
| 161 |
+
- `binary_relations`, as above
|
| 162 |
+
- `labeled_partitions`, `LabeledSpan` annotations, created from splitting `BratDocumentWithMergedSpans`'s `text` at new paragraph in `xml` format.
|
| 163 |
+
- labels: `title`, `abstract`, `H1`
|
| 164 |
+
|
| 165 |
+
From `resolve_parts_of_same` version:
|
| 166 |
+
|
| 167 |
+
- `pie_modules.documents.TextDocumentWithLabeledMultiSpansAndBinaryRelations`:
|
| 168 |
+
- `labeled_multi_spans`: `LabeledMultiSpan` annotations, converted from `BratDocument`'s `spans`
|
| 169 |
+
- labels: as above
|
| 170 |
+
- if spans contain whitespace at the beginning and/or the end, that whitespace is trimmed out.
|
| 171 |
+
- `binary_relations`: `BinaryRelation` annotations, converted from `BratDocument`'s `relations`
|
| 172 |
+
- labels: `supports`, `contradicts`, `semantically_same`
|
| 173 |
+
- in contrast to the `default` version, spans connected with `parts_of_same` relation are stored as one labeled multi-span
|
| 174 |
+
- if the `relations` label is `semantically_same` (i.e. it is a symmetric relation), their arguments are sorted by their start and end indices.
|
| 175 |
+
- `pie_modules.documents.TextDocumentWithLabeledMultiSpansBinaryRelationsAndLabeledPartitions`:
|
| 176 |
+
- `labeled_multi_spans`, as above
|
| 177 |
+
- `binary_relations`, as above
|
| 178 |
+
- `labeled_partitions`, `LabeledSpan` annotations, created from splitting `BratDocument`'s `text` at new paragraph in `xml` format.
|
| 179 |
+
- labels: `title`, `abstract`, `H1`
|
| 180 |
+
|
| 181 |
+
See [here](https://github.com/ArneBinder/pie-modules/blob/main/src/pie_modules/documents.py) for the document type
|
| 182 |
+
definitions.
|
| 183 |
|
| 184 |
## Dataset Creation
|
| 185 |
|
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,32 @@
|
|
|
|
|
|
|
|
|
|
|
| 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 +40,47 @@ 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 +89,82 @@ 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 |
+
import logging
|
| 2 |
+
from typing import Union
|
| 3 |
+
|
| 4 |
from pie_modules.document.processing import (
|
| 5 |
RegexPartitioner,
|
| 6 |
RelationArgumentSorter,
|
| 7 |
+
SpansViaRelationMerger,
|
| 8 |
TextSpanTrimmer,
|
| 9 |
)
|
| 10 |
+
from pie_modules.documents import (
|
| 11 |
+
TextDocumentWithLabeledMultiSpansAndBinaryRelations,
|
| 12 |
+
TextDocumentWithLabeledMultiSpansBinaryRelationsAndLabeledPartitions,
|
| 13 |
TextDocumentWithLabeledSpansAndBinaryRelations,
|
| 14 |
TextDocumentWithLabeledSpansBinaryRelationsAndLabeledPartitions,
|
| 15 |
)
|
| 16 |
+
from pytorch_ie.core import Document
|
| 17 |
|
| 18 |
from pie_datasets.builders import BratBuilder, BratConfig
|
| 19 |
+
from pie_datasets.builders.brat import BratDocument, BratDocumentWithMergedSpans
|
| 20 |
+
from pie_datasets.core.dataset import DocumentConvertersType
|
| 21 |
from pie_datasets.document.processing import Caster, Pipeline
|
| 22 |
|
| 23 |
+
logger = logging.getLogger(__name__)
|
| 24 |
+
|
| 25 |
URL = "http://data.dws.informatik.uni-mannheim.de/sci-arg/compiled_corpus.zip"
|
| 26 |
SPLIT_PATHS = {"train": "compiled_corpus"}
|
| 27 |
|
| 28 |
|
| 29 |
+
def get_common_converter_pipeline_steps(target_document_type: type[Document]) -> dict:
|
| 30 |
return dict(
|
| 31 |
cast=Caster(
|
| 32 |
document_type=target_document_type,
|
|
|
|
| 40 |
)
|
| 41 |
|
| 42 |
|
| 43 |
+
def get_common_converter_pipeline_steps_with_resolve_parts_of_same(
|
| 44 |
+
target_document_type: type[Document],
|
| 45 |
+
) -> dict:
|
| 46 |
+
return dict(
|
| 47 |
+
cast=Caster(
|
| 48 |
+
document_type=target_document_type,
|
| 49 |
+
field_mapping={"spans": "labeled_multi_spans", "relations": "binary_relations"},
|
| 50 |
+
),
|
| 51 |
+
trim_adus=TextSpanTrimmer(layer="labeled_multi_spans"),
|
| 52 |
+
sort_symmetric_relation_arguments=RelationArgumentSorter(
|
| 53 |
+
relation_layer="binary_relations",
|
| 54 |
+
label_whitelist=["semantically_same"],
|
| 55 |
+
),
|
| 56 |
+
)
|
| 57 |
+
|
| 58 |
+
|
| 59 |
+
def remove_duplicate_relations(document: Union[BratDocument, BratDocumentWithMergedSpans]) -> None:
|
| 60 |
+
if len(document.relations) > len(set(document.relations)):
|
| 61 |
+
added = set()
|
| 62 |
+
i = 0
|
| 63 |
+
while i < len(document.relations):
|
| 64 |
+
relation = document.relations[i]
|
| 65 |
+
if relation in added:
|
| 66 |
+
logger.warning(f"doc_id={document.id}: Removing duplicate relation: {relation}")
|
| 67 |
+
document.relations.pop(i)
|
| 68 |
+
else:
|
| 69 |
+
added.add(relation)
|
| 70 |
+
i += 1
|
| 71 |
+
|
| 72 |
+
|
| 73 |
+
class SciArgConfig(BratConfig):
|
| 74 |
+
def __init__(
|
| 75 |
+
self,
|
| 76 |
+
name: str,
|
| 77 |
+
resolve_parts_of_same: bool = False,
|
| 78 |
+
**kwargs,
|
| 79 |
+
):
|
| 80 |
+
super().__init__(name=name, merge_fragmented_spans=True, **kwargs)
|
| 81 |
+
self.resolve_parts_of_same = resolve_parts_of_same
|
| 82 |
+
|
| 83 |
+
|
| 84 |
class SciArg(BratBuilder):
|
| 85 |
BASE_DATASET_PATH = "DFKI-SLT/brat"
|
| 86 |
BASE_DATASET_REVISION = "844de61e8a00dc6a93fc29dc185f6e617131fbf1"
|
|
|
|
| 89 |
# The span fragments in SciArg come just from the new line splits, so we can merge them.
|
| 90 |
# Actual span fragments are annotated via "parts_of_same" relations.
|
| 91 |
BUILDER_CONFIGS = [
|
| 92 |
+
SciArgConfig(name=BratBuilder.DEFAULT_CONFIG_NAME),
|
| 93 |
+
SciArgConfig(name="resolve_parts_of_same", resolve_parts_of_same=True),
|
| 94 |
]
|
| 95 |
DOCUMENT_TYPES = {
|
| 96 |
BratBuilder.DEFAULT_CONFIG_NAME: BratDocumentWithMergedSpans,
|
| 97 |
+
"resolve_parts_of_same": BratDocument,
|
| 98 |
}
|
| 99 |
|
| 100 |
# we need to add None to the list of dataset variants to support the default dataset variant
|
| 101 |
BASE_BUILDER_KWARGS_DICT = {
|
| 102 |
dataset_variant: {"url": URL, "split_paths": SPLIT_PATHS}
|
| 103 |
+
for dataset_variant in ["default", "resolve_parts_of_same", None]
|
| 104 |
}
|
| 105 |
|
| 106 |
+
def _generate_document(self, example, **kwargs):
|
| 107 |
+
document = super()._generate_document(example, **kwargs)
|
| 108 |
+
if self.config.resolve_parts_of_same:
|
| 109 |
+
document = SpansViaRelationMerger(
|
| 110 |
+
relation_layer="relations",
|
| 111 |
+
link_relation_label="parts_of_same",
|
| 112 |
+
create_multi_spans=True,
|
| 113 |
+
result_document_type=BratDocument,
|
| 114 |
+
result_field_mapping={"spans": "spans", "relations": "relations"},
|
| 115 |
+
)(document)
|
| 116 |
+
else:
|
| 117 |
+
# some documents have duplicate relations, remove them
|
| 118 |
+
remove_duplicate_relations(document)
|
| 119 |
+
|
| 120 |
+
return document
|
| 121 |
+
|
| 122 |
+
@property
|
| 123 |
+
def document_converters(self) -> DocumentConvertersType:
|
| 124 |
+
regex_partitioner = RegexPartitioner(
|
| 125 |
+
partition_layer_name="labeled_partitions",
|
| 126 |
+
pattern="<([^>/]+)>.*</\\1>",
|
| 127 |
+
label_group_id=1,
|
| 128 |
+
label_whitelist=["Title", "Abstract", "H1"],
|
| 129 |
+
skip_initial_partition=True,
|
| 130 |
+
strip_whitespace=True,
|
| 131 |
+
)
|
| 132 |
+
if not self.config.resolve_parts_of_same:
|
| 133 |
+
return {
|
| 134 |
+
TextDocumentWithLabeledSpansAndBinaryRelations: Pipeline(
|
| 135 |
+
**get_common_converter_pipeline_steps(
|
| 136 |
+
TextDocumentWithLabeledSpansAndBinaryRelations
|
| 137 |
+
)
|
| 138 |
+
),
|
| 139 |
+
TextDocumentWithLabeledSpansBinaryRelationsAndLabeledPartitions: Pipeline(
|
| 140 |
+
**get_common_converter_pipeline_steps(
|
| 141 |
+
TextDocumentWithLabeledSpansBinaryRelationsAndLabeledPartitions
|
| 142 |
+
),
|
| 143 |
+
add_partitions=regex_partitioner,
|
| 144 |
+
),
|
| 145 |
+
}
|
| 146 |
+
else:
|
| 147 |
+
return {
|
| 148 |
+
# TextDocumentWithLabeledSpansAndBinaryRelations: Pipeline(
|
| 149 |
+
# **get_common_converter_pipeline_steps_with_resolve_parts_of_same(
|
| 150 |
+
# TextDocumentWithLabeledSpansAndBinaryRelations
|
| 151 |
+
# )
|
| 152 |
+
# ),
|
| 153 |
+
# TextDocumentWithLabeledSpansBinaryRelationsAndLabeledPartitions: Pipeline(
|
| 154 |
+
# **get_common_converter_pipeline_steps_with_resolve_parts_of_same(
|
| 155 |
+
# TextDocumentWithLabeledSpansBinaryRelationsAndLabeledPartitions
|
| 156 |
+
# ),
|
| 157 |
+
# add_partitions=regex_partitioner,
|
| 158 |
+
# ),
|
| 159 |
+
TextDocumentWithLabeledMultiSpansAndBinaryRelations: Pipeline(
|
| 160 |
+
**get_common_converter_pipeline_steps_with_resolve_parts_of_same(
|
| 161 |
+
TextDocumentWithLabeledMultiSpansAndBinaryRelations
|
| 162 |
+
)
|
| 163 |
+
),
|
| 164 |
+
TextDocumentWithLabeledMultiSpansBinaryRelationsAndLabeledPartitions: Pipeline(
|
| 165 |
+
**get_common_converter_pipeline_steps_with_resolve_parts_of_same(
|
| 166 |
+
TextDocumentWithLabeledMultiSpansBinaryRelationsAndLabeledPartitions
|
| 167 |
+
),
|
| 168 |
+
add_partitions=regex_partitioner,
|
| 169 |
+
),
|
| 170 |
+
}
|