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