fvillena commited on
Commit
37b3a2c
1 Parent(s): 1484a50

initial commit

Browse files
Files changed (1) hide show
  1. cantemist.py +102 -0
cantemist.py ADDED
@@ -0,0 +1,102 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import datasets
2
+
3
+
4
+ logger = datasets.logging.get_logger(__name__)
5
+
6
+
7
+ _CITATION = """\
8
+
9
+ """
10
+
11
+ _DESCRIPTION = """\
12
+
13
+
14
+ """
15
+
16
+ _URL = "https://huggingface.co/datasets/fvillena/cantemist/resolve/main/data/"
17
+ _TRAINING_FILE = "cantemist_ner_train.conll"
18
+ _DEV_FILE = "cantemist_ner_dev.conll"
19
+ _TEST_FILE = "cantemist_ner_test.conll"
20
+
21
+
22
+ class CantemistConfig(datasets.BuilderConfig):
23
+ """BuilderConfig for Cantemist"""
24
+
25
+ def __init__(self, **kwargs):
26
+ """BuilderConfig for Cantemist.
27
+ Args:
28
+ **kwargs: keyword arguments forwarded to super.
29
+ """
30
+ super(CantemistConfig, self).__init__(**kwargs)
31
+
32
+
33
+ class Cantemist(datasets.GeneratorBasedBuilder):
34
+ """Cantemist dataset."""
35
+
36
+ BUILDER_CONFIGS = [
37
+ CantemistConfig(name="cantemist", version=datasets.Version("1.0.0"), description="Cantemist dataset"),
38
+ ]
39
+
40
+ def _info(self):
41
+ return datasets.DatasetInfo(
42
+ description=_DESCRIPTION,
43
+ features=datasets.Features(
44
+ {
45
+ "tokens": datasets.Sequence(datasets.Value("string")),
46
+ "ner_tags": datasets.Sequence(
47
+ datasets.features.ClassLabel(
48
+ names=[
49
+ "O",
50
+ "B-MORFOLOGIA_NEOPLASIA",
51
+ "I-MORFOLOGIA_NEOPLASIA",
52
+ ]
53
+ )
54
+ ),
55
+ }
56
+ ),
57
+ supervised_keys=None,
58
+ homepage="",
59
+ citation=_CITATION,
60
+ )
61
+
62
+ def _split_generators(self, dl_manager):
63
+ """Returns SplitGenerators."""
64
+ urls_to_download = {
65
+ "train": f"{_URL}{_TRAINING_FILE}",
66
+ "dev": f"{_URL}{_DEV_FILE}",
67
+ "test": f"{_URL}{_TEST_FILE}",
68
+ }
69
+ downloaded_files = dl_manager.download_and_extract(urls_to_download)
70
+
71
+ return [
72
+ datasets.SplitGenerator(name=datasets.Split.TRAIN, gen_kwargs={"filepath": downloaded_files["train"]}),
73
+ datasets.SplitGenerator(name=datasets.Split.VALIDATION, gen_kwargs={"filepath": downloaded_files["dev"]}),
74
+ datasets.SplitGenerator(name=datasets.Split.TEST, gen_kwargs={"filepath": downloaded_files["test"]}),
75
+ ]
76
+
77
+ def _generate_examples(self, filepath):
78
+ logger.info("⏳ Generating examples from = %s", filepath)
79
+ with open(filepath, encoding="utf-8") as f:
80
+ id_ = 0
81
+ tokens = []
82
+ ner_tags = []
83
+ for line in f:
84
+ if line == "" or line == "\n":
85
+ if tokens:
86
+ yield id_, {
87
+ "tokens": tokens,
88
+ "ner_tags": ner_tags,
89
+ }
90
+ id_ += 1
91
+ tokens = []
92
+ ner_tags = []
93
+ else:
94
+ # conll2003 tokens are space separated
95
+ splits = line.split(" ")
96
+ tokens.append(splits[0])
97
+ ner_tags.append(splits[1].rstrip())
98
+ # last example
99
+ yield id_, {
100
+ "tokens": tokens,
101
+ "ner_tags": ner_tags,
102
+ }