Commit
·
288784f
1
Parent(s):
5d594aa
Upload all datasets to hub
Browse filesCommit from https://github.com/huggingface/datasets/pie/commit/44e2b49f756ae55906addbd4cbcb339698ea0e7c
- conll2002.py +56 -0
- dummy/es/1.0.0/dummy_data.zip +3 -0
- dummy/nl/1.0.0/dummy_data.zip +3 -0
conll2002.py
ADDED
|
@@ -0,0 +1,56 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 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 Conll2002Config(datasets.BuilderConfig):
|
| 12 |
+
"""BuilderConfig for CoNLL2002"""
|
| 13 |
+
|
| 14 |
+
def __init__(self, **kwargs):
|
| 15 |
+
"""BuilderConfig for CoNLL2002.
|
| 16 |
+
Args:
|
| 17 |
+
**kwargs: keyword arguments forwarded to super.
|
| 18 |
+
"""
|
| 19 |
+
super().__init__(**kwargs)
|
| 20 |
+
|
| 21 |
+
|
| 22 |
+
@dataclass
|
| 23 |
+
class CoNLL2002Document(TextDocument):
|
| 24 |
+
entities: AnnotationList[LabeledSpan] = annotation_field(target="text")
|
| 25 |
+
|
| 26 |
+
|
| 27 |
+
class Conll2003(pytorch_ie.data.builder.GeneratorBasedBuilder):
|
| 28 |
+
DOCUMENT_TYPE = CoNLL2002Document
|
| 29 |
+
|
| 30 |
+
BASE_DATASET_PATH = "conll2002"
|
| 31 |
+
|
| 32 |
+
BUILDER_CONFIGS = [
|
| 33 |
+
Conll2002Config(
|
| 34 |
+
name="es", version=datasets.Version("1.0.0"), description="CoNLL2002 Spanish dataset"
|
| 35 |
+
),
|
| 36 |
+
Conll2002Config(
|
| 37 |
+
name="nl", version=datasets.Version("1.0.0"), description="CoNLL2002 Dutch dataset"
|
| 38 |
+
),
|
| 39 |
+
]
|
| 40 |
+
|
| 41 |
+
def _generate_document_kwargs(self, dataset):
|
| 42 |
+
return {"int_to_str": dataset.features["ner_tags"].feature.int2str}
|
| 43 |
+
|
| 44 |
+
def _generate_document(self, example, int_to_str):
|
| 45 |
+
doc_id = example["id"]
|
| 46 |
+
tokens = example["tokens"]
|
| 47 |
+
ner_tags = [int_to_str(tag) for tag in example["ner_tags"]]
|
| 48 |
+
|
| 49 |
+
text, ner_spans = tokens_and_tags_to_text_and_labeled_spans(tokens=tokens, tags=ner_tags)
|
| 50 |
+
|
| 51 |
+
document = CoNLL2002Document(text=text, id=doc_id)
|
| 52 |
+
|
| 53 |
+
for span in sorted(ner_spans, key=lambda span: span.start):
|
| 54 |
+
document.entities.append(span)
|
| 55 |
+
|
| 56 |
+
return document
|
dummy/es/1.0.0/dummy_data.zip
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
version https://git-lfs.github.com/spec/v1
|
| 2 |
+
oid sha256:a8a354fa86d8514a792bd995048fa04302e868efbe27711c3c691ab47d7f8b6f
|
| 3 |
+
size 1089
|
dummy/nl/1.0.0/dummy_data.zip
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
version https://git-lfs.github.com/spec/v1
|
| 2 |
+
oid sha256:26a0a51bc3f4db1f5e342f2084a0c446d8541408e7ec3bda4c9340f5cc3321f8
|
| 3 |
+
size 1094
|