matirojasg commited on
Commit
16151de
1 Parent(s): 6cc6324

files uploaded

Browse files
Files changed (5) hide show
  1. .DS_Store +0 -0
  2. dev.conll +0 -0
  3. test.conll +0 -0
  4. train.conll +0 -0
  5. wl-body-part.py +96 -0
.DS_Store ADDED
Binary file (6.15 kB). View file
 
dev.conll ADDED
The diff for this file is too large to render. See raw diff
 
test.conll ADDED
The diff for this file is too large to render. See raw diff
 
train.conll ADDED
The diff for this file is too large to render. See raw diff
 
wl-body-part.py ADDED
@@ -0,0 +1,96 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+
2
+ import datasets
3
+
4
+
5
+ logger = datasets.logging.get_logger(__name__)
6
+
7
+
8
+ _LICENSE = "Creative Commons Attribution 4.0 International"
9
+
10
+ _VERSION = "1.1.0"
11
+
12
+ _URL = "https://huggingface.co/datasets/plncmm/wl-body-part/resolve/main/"
13
+ _TRAINING_FILE = "train.conll"
14
+ _DEV_FILE = "dev.conll"
15
+ _TEST_FILE = "test.conll"
16
+
17
+ class BodyPartConfig(datasets.BuilderConfig):
18
+ """BuilderConfig for Disease dataset."""
19
+
20
+ def __init__(self, **kwargs):
21
+ super(BodyPartConfig, self).__init__(**kwargs)
22
+
23
+
24
+ class BodyPart(datasets.GeneratorBasedBuilder):
25
+ """BodyPart dataset."""
26
+
27
+ BUILDER_CONFIGS = [
28
+ BodyPartConfig(
29
+ name="BodyPart",
30
+ version=datasets.Version(_VERSION),
31
+ description="BodyPart dataset"),
32
+ ]
33
+
34
+ def _info(self):
35
+ return datasets.DatasetInfo(
36
+ features=datasets.Features(
37
+ {
38
+ "id": datasets.Value("string"),
39
+ "tokens": datasets.Sequence(datasets.Value("string")),
40
+ "ner_tags": datasets.Sequence(
41
+ datasets.features.ClassLabel(
42
+ names=[
43
+ "O",
44
+ "B-Body_Part",
45
+ "I-Body_Part",
46
+ ]
47
+ )
48
+ ),
49
+ }
50
+ ),
51
+ supervised_keys=None,
52
+ )
53
+
54
+ def _split_generators(self, dl_manager):
55
+ """Returns SplitGenerators."""
56
+ urls_to_download = {
57
+ "train": f"{_URL}{_TRAINING_FILE}",
58
+ "dev": f"{_URL}{_DEV_FILE}",
59
+ "test": f"{_URL}{_TEST_FILE}",
60
+ }
61
+ downloaded_files = dl_manager.download_and_extract(urls_to_download)
62
+
63
+ return [
64
+ datasets.SplitGenerator(name=datasets.Split.TRAIN, gen_kwargs={"filepath": downloaded_files["train"]}),
65
+ datasets.SplitGenerator(name=datasets.Split.VALIDATION, gen_kwargs={"filepath": downloaded_files["dev"]}),
66
+ datasets.SplitGenerator(name=datasets.Split.TEST, gen_kwargs={"filepath": downloaded_files["test"]}),
67
+ ]
68
+
69
+ def _generate_examples(self, filepath):
70
+ logger.info("⏳ Generating examples from = %s", filepath)
71
+ with open(filepath, encoding="utf-8") as f:
72
+ guid = 0
73
+ tokens = []
74
+ pos_tags = []
75
+ ner_tags = []
76
+ for line in f:
77
+ if line == "\n":
78
+ if tokens:
79
+ yield guid, {
80
+ "id": str(guid),
81
+ "tokens": tokens,
82
+ "ner_tags": ner_tags,
83
+ }
84
+ guid += 1
85
+ tokens = []
86
+ ner_tags = []
87
+ else:
88
+ splits = line.split(" ")
89
+ tokens.append(splits[0])
90
+ ner_tags.append(splits[-1].rstrip())
91
+ # last example
92
+ yield guid, {
93
+ "id": str(guid),
94
+ "tokens": tokens,
95
+ "ner_tags": ner_tags,
96
+ }