christophalt commited on
Commit
1f1f883
·
1 Parent(s): 5d594aa

Upload all datasets to hub

Browse files

Commit from https://github.com/huggingface/datasets/pie/commit/44e2b49f756ae55906addbd4cbcb339698ea0e7c

Files changed (2) hide show
  1. dummy/0.9.1/dummy_data.zip +3 -0
  2. germaner.py +38 -0
dummy/0.9.1/dummy_data.zip ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:5b4e88c313ed53a4120b0a0481819f9ea6981c4e580f7a1d5a8474209c4ed056
3
+ size 295
germaner.py ADDED
@@ -0,0 +1,38 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ from dataclasses import dataclass
2
+
3
+ import datasets
4
+ import pytorch_ie.data.builder
5
+ from pytorch_ie.annotations import LabeledSpan
6
+ from pytorch_ie.core import AnnotationList, annotation_field
7
+ from pytorch_ie.documents import TextDocument
8
+ from pytorch_ie.utils.span import tokens_and_tags_to_text_and_labeled_spans
9
+
10
+
11
+ @dataclass
12
+ class GermaNERDocument(TextDocument):
13
+ entities: AnnotationList[LabeledSpan] = annotation_field(target="text")
14
+
15
+
16
+ class GermaNER(pytorch_ie.data.builder.GeneratorBasedBuilder):
17
+ DOCUMENT_TYPE = GermaNERDocument
18
+
19
+ BASE_DATASET_PATH = "germaner"
20
+
21
+ VERSION = datasets.Version("0.9.1")
22
+
23
+ def _generate_document_kwargs(self, dataset):
24
+ return {"int_to_str": dataset.features["ner_tags"].feature.int2str}
25
+
26
+ def _generate_document(self, example, int_to_str):
27
+ doc_id = example["id"]
28
+ tokens = example["tokens"]
29
+ ner_tags = [int_to_str(tag) for tag in example["ner_tags"]]
30
+
31
+ text, ner_spans = tokens_and_tags_to_text_and_labeled_spans(tokens=tokens, tags=ner_tags)
32
+
33
+ document = GermaNERDocument(text=text, id=doc_id)
34
+
35
+ for span in sorted(ner_spans, key=lambda span: span.start):
36
+ document.entities.append(span)
37
+
38
+ return document