ArneBinder commited on
Commit
6ab4446
1 Parent(s): 4e85fc1

update pie-datasets to 0.7.0

Browse files
Files changed (3) hide show
  1. README.md +16 -48
  2. brat.py +2 -1
  3. requirements.txt +1 -1
README.md CHANGED
@@ -1,8 +1,16 @@
1
- # PIE Dataset Card for "conll2003"
2
 
3
  This is a [PyTorch-IE](https://github.com/ChristophAlt/pytorch-ie) wrapper for the
4
  [BRAT Huggingface dataset loading script](https://huggingface.co/datasets/DFKI-SLT/brat).
5
 
 
 
 
 
 
 
 
 
6
  ## Data Schema
7
 
8
  The document type for this dataset is `BratDocument` or `BratDocumentWithMergedSpans`, depending on if the
@@ -19,6 +27,12 @@ and the following annotation layers:
19
  - `span_attributes` (annotation type: `Attribute`, target: `spans`)
20
  - `relation_attributes` (annotation type: `Attribute`, target: `relations`)
21
 
 
 
 
 
 
 
22
  The `Attribute` annotation type is defined as follows:
23
 
24
  - `annotation` (type: `Annotation`): the annotation to which the attribute is attached
@@ -31,50 +45,4 @@ See [here](https://github.com/ChristophAlt/pytorch-ie/blob/main/src/pytorch_ie/a
31
  ## Document Converters
32
 
33
  The dataset provides no predefined document converters because the BRAT format is very flexible and can be used
34
- for many different tasks. You can add your own document converter by doing the following:
35
-
36
- ```python
37
- import dataclasses
38
- from typing import Optional
39
-
40
- from pytorch_ie.core import AnnotationList, annotation_field
41
- from pytorch_ie.documents import TextBasedDocument
42
- from pytorch_ie.annotations import LabeledSpan
43
-
44
- from pie_datasets import DatasetDict
45
-
46
- # define your document class
47
- @dataclasses.dataclass
48
- class MyDocument(TextBasedDocument):
49
- my_field: Optional[str] = None
50
- my_span_annotations: AnnotationList[LabeledSpan] = annotation_field(target="text")
51
-
52
- # define your document converter
53
- def my_converter(document: BratDocumentWithMergedSpans) -> MyDocument:
54
- # create your document with the data from the original document.
55
- # The fields "text", "id" and "metadata" are derived from the TextBasedDocument.
56
- my_document = MyDocument(id=document.id, text=document.text, metadata=document.metadata, my_field="my_value")
57
-
58
- # create a new span annotation
59
- new_span = LabeledSpan(label="my_label", start=2, end=10)
60
- # add the new span annotation to your document
61
- my_document.my_span_annotations.append(new_span)
62
-
63
- # add annotations from the document to your document
64
- for span in document.spans:
65
- # we need to copy the span because an annotation can only be attached to one document
66
- my_document.my_span_annotations.append(span.copy())
67
-
68
- return my_document
69
-
70
-
71
- # load the dataset. We use the "merge_fragmented_spans" dataset variant here
72
- # because it provides documents of type BratDocumentWithMergedSpans.
73
- dataset = DatasetDict.load_dataset("pie/brat", name="merge_fragmented_spans", data_dir="path/to/brat/data")
74
-
75
- # attach your document converter to the dataset
76
- dataset.register_document_converter(my_converter)
77
-
78
- # convert the dataset
79
- converted_dataset = dataset.to_document_type(MyDocument)
80
- ```
 
1
+ # PIE Dataset Card for "brat"
2
 
3
  This is a [PyTorch-IE](https://github.com/ChristophAlt/pytorch-ie) wrapper for the
4
  [BRAT Huggingface dataset loading script](https://huggingface.co/datasets/DFKI-SLT/brat).
5
 
6
+ ## Dataset Variants
7
+
8
+ The dataset provides the following variants:
9
+
10
+ - `default`: The original dataset. Documents are of type `BratDocument` (with `LabeledMultiSpan` annotations, see below).
11
+ - `merge_fragmented_spans`: Documents are of type `BratDocumentWithMergedSpans` (this variant merges spans that are
12
+ fragmented into simple `LabeledSpans`, see below).
13
+
14
  ## Data Schema
15
 
16
  The document type for this dataset is `BratDocument` or `BratDocumentWithMergedSpans`, depending on if the
 
27
  - `span_attributes` (annotation type: `Attribute`, target: `spans`)
28
  - `relation_attributes` (annotation type: `Attribute`, target: `relations`)
29
 
30
+ The `LabeledMultiSpan` annotation type is defined as follows:
31
+
32
+ - `slices` (type: `Tuple[Tuple[int, int], ...]`): the slices consisting if start (including) and end (excluding) indices of the spans
33
+ - `label` (type: `str`)
34
+ - `score` (type: `float`, optional, not included in comparison)
35
+
36
  The `Attribute` annotation type is defined as follows:
37
 
38
  - `annotation` (type: `Annotation`): the annotation to which the attribute is attached
 
45
  ## Document Converters
46
 
47
  The dataset provides no predefined document converters because the BRAT format is very flexible and can be used
48
+ for many different tasks.
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
brat.py CHANGED
@@ -2,4 +2,5 @@ from pie_datasets.builders import BratBuilder
2
 
3
 
4
  class Brat(BratBuilder):
5
- pass
 
 
2
 
3
 
4
  class Brat(BratBuilder):
5
+ BASE_DATASET_PATH = "DFKI-SLT/brat"
6
+ BASE_DATASET_REVISION = "052163d34b4429d81003981bc10674cef54aa0b8"
requirements.txt CHANGED
@@ -1 +1 @@
1
- pie-datasets>=0.4.0,<0.7.0
 
1
+ pie-datasets>=0.4.0,<0.8.0