File size: 2,783 Bytes
2d9edd3 cc9f1ec f4ff05c 982d568 cc9f1ec f4ff05c 982d568 f4ff05c 982d568 |
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 |
from pie_modules.document.processing import (
RegexPartitioner,
RelationArgumentSorter,
TextSpanTrimmer,
)
from pytorch_ie.core import Document
from pytorch_ie.documents import (
TextDocumentWithLabeledSpansAndBinaryRelations,
TextDocumentWithLabeledSpansBinaryRelationsAndLabeledPartitions,
)
from pie_datasets.builders import BratBuilder, BratConfig
from pie_datasets.builders.brat import BratDocumentWithMergedSpans
from pie_datasets.document.processing import Caster, Pipeline
URL = "http://data.dws.informatik.uni-mannheim.de/sci-arg/compiled_corpus.zip"
SPLIT_PATHS = {"train": "compiled_corpus"}
def get_common_pipeline_steps(target_document_type: type[Document]) -> dict:
return dict(
cast=Caster(
document_type=target_document_type,
field_mapping={"spans": "labeled_spans", "relations": "binary_relations"},
),
trim_adus=TextSpanTrimmer(layer="labeled_spans"),
sort_symmetric_relation_arguments=RelationArgumentSorter(
relation_layer="binary_relations",
label_whitelist=["parts_of_same", "semantically_same"],
),
)
class SciArg(BratBuilder):
BASE_DATASET_PATH = "DFKI-SLT/brat"
BASE_DATASET_REVISION = "844de61e8a00dc6a93fc29dc185f6e617131fbf1"
# Overwrite the default config to merge the span fragments.
# The span fragments in SciArg come just from the new line splits, so we can merge them.
# Actual span fragments are annotated via "parts_of_same" relations.
BUILDER_CONFIGS = [
BratConfig(name=BratBuilder.DEFAULT_CONFIG_NAME, merge_fragmented_spans=True),
]
DOCUMENT_TYPES = {
BratBuilder.DEFAULT_CONFIG_NAME: BratDocumentWithMergedSpans,
}
# we need to add None to the list of dataset variants to support the default dataset variant
BASE_BUILDER_KWARGS_DICT = {
dataset_variant: {"url": URL, "split_paths": SPLIT_PATHS}
for dataset_variant in ["default", "merge_fragmented_spans", None]
}
DOCUMENT_CONVERTERS = {
TextDocumentWithLabeledSpansAndBinaryRelations: Pipeline(
**get_common_pipeline_steps(TextDocumentWithLabeledSpansAndBinaryRelations)
),
TextDocumentWithLabeledSpansBinaryRelationsAndLabeledPartitions: Pipeline(
**get_common_pipeline_steps(
TextDocumentWithLabeledSpansBinaryRelationsAndLabeledPartitions
),
add_partitions=RegexPartitioner(
partition_layer_name="labeled_partitions",
pattern="<([^>/]+)>.*</\\1>",
label_group_id=1,
label_whitelist=["Title", "Abstract", "H1"],
skip_initial_partition=True,
strip_whitespace=True,
),
),
}
|