christophalt commited on
Commit
de5dd48
·
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. conllpp.py +53 -0
  2. dummy/conllpp/1.0.0/dummy_data.zip +3 -0
conllpp.py ADDED
@@ -0,0 +1,53 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
+ class CoNLLppConfig(datasets.BuilderConfig):
12
+ """BuilderConfig for CoNLLpp"""
13
+
14
+ def __init__(self, **kwargs):
15
+ """BuilderConfig for CoNLLpp.
16
+ Args:
17
+ **kwargs: keyword arguments forwarded to super.
18
+ """
19
+ super().__init__(**kwargs)
20
+
21
+
22
+ @dataclass
23
+ class CoNLLppDocument(TextDocument):
24
+ entities: AnnotationList[LabeledSpan] = annotation_field(target="text")
25
+
26
+
27
+ class CoNLLpp(pytorch_ie.data.builder.GeneratorBasedBuilder):
28
+ DOCUMENT_TYPE = CoNLLppDocument
29
+
30
+ BASE_DATASET_PATH = "conllpp"
31
+
32
+ BUILDER_CONFIGS = [
33
+ CoNLLppConfig(
34
+ name="conllpp", version=datasets.Version("1.0.0"), description="CoNLLpp dataset"
35
+ ),
36
+ ]
37
+
38
+ def _generate_document_kwargs(self, dataset):
39
+ return {"int_to_str": dataset.features["ner_tags"].feature.int2str}
40
+
41
+ def _generate_document(self, example, int_to_str):
42
+ doc_id = example["id"]
43
+ tokens = example["tokens"]
44
+ ner_tags = [int_to_str(tag) for tag in example["ner_tags"]]
45
+
46
+ text, ner_spans = tokens_and_tags_to_text_and_labeled_spans(tokens=tokens, tags=ner_tags)
47
+
48
+ document = CoNLLppDocument(text=text, id=doc_id)
49
+
50
+ for span in sorted(ner_spans, key=lambda span: span.start):
51
+ document.entities.append(span)
52
+
53
+ return document
dummy/conllpp/1.0.0/dummy_data.zip ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:b53f19f1b8d133350c8ec695e940e6846814ec64e3896b1cb886b78c25509246
3
+ size 696