rosimeirecosta commited on
Commit
f149f68
·
1 Parent(s): a2d0dce

Upload c_corpus.py

Browse files
Files changed (1) hide show
  1. c_corpus.py +119 -0
c_corpus.py ADDED
@@ -0,0 +1,119 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import datasets
2
+
3
+
4
+ logger = datasets.logging.get_logger(__name__)
5
+
6
+
7
+ _CITATION = """ """
8
+
9
+ _DESCRIPTION = """ """
10
+
11
+ _HOMEPAGE = ""
12
+
13
+ _URL = "https://raw.githubusercontent.com/rosi-pc/c_corpus/main/c_corpus/"
14
+ _TRAINING_FILE = "train.txt"
15
+ _DEV_FILE = "valid.txt"
16
+ _TEST_FILE = "test.txt"
17
+
18
+
19
+ class CCorpus(datasets.GeneratorBasedBuilder):
20
+ """c-corpus dataset"""
21
+
22
+ VERSION = datasets.Version("1.0.0")
23
+
24
+ BUILDER_CONFIGS = [
25
+ datasets.BuilderConfig(name="c_corpus", version=VERSION, description="c_corpus dataset"),
26
+ ]
27
+
28
+ def _info(self):
29
+ return datasets.DatasetInfo(
30
+ description=_DESCRIPTION,
31
+ features=datasets.Features(
32
+ {
33
+ "id": datasets.Value("string"),
34
+ "tokens": datasets.Sequence(datasets.Value("string")),
35
+ "ner_tags": datasets.Sequence(
36
+ datasets.features.ClassLabel(
37
+ names=[
38
+ "O",
39
+ "B-DATA",
40
+ "I-DATA",
41
+ "B-EVENTO",
42
+ "I-EVENTO",
43
+ "B-FUNDAMENTO",
44
+ "I-FUNDAMENTO",
45
+ "B-LOCAL",
46
+ "I-LOCAL",
47
+ "B-ORGANIZACAO",
48
+ "I-ORGANIZACAO",
49
+ "B-PESSOA",
50
+ "I-PESSOA",
51
+ "B-PRODUTODELEI",
52
+ "I-PRODUTODELEI",
53
+ ]
54
+ )
55
+ ),
56
+ }
57
+ ),
58
+ supervised_keys=None,
59
+ homepage=" ",
60
+ citation=_CITATION,
61
+ )
62
+
63
+ def _split_generators(self, dl_manager):
64
+ """Returns SplitGenerators."""
65
+ urls_to_download = {
66
+ "train": f"{_URL}{_TRAINING_FILE}",
67
+ "dev": f"{_URL}{_DEV_FILE}",
68
+ "test": f"{_URL}{_TEST_FILE}",
69
+ }
70
+ downloaded_files = dl_manager.download_and_extract(urls_to_download)
71
+
72
+ return [
73
+ datasets.SplitGenerator(
74
+ name=datasets.Split.TRAIN,
75
+ gen_kwargs={"filepath": downloaded_files["train"], "split": "train"},
76
+ ),
77
+ datasets.SplitGenerator(
78
+ name=datasets.Split.VALIDATION,
79
+ gen_kwargs={"filepath": downloaded_files["dev"], "split": "validation"},
80
+ ),
81
+ datasets.SplitGenerator(
82
+ name=datasets.Split.TEST,
83
+ gen_kwargs={"filepath": downloaded_files["test"], "split": "test"},
84
+ ),
85
+ ]
86
+
87
+ def _generate_examples(self, filepath, split):
88
+ """Yields examples."""
89
+
90
+ logger.info("⏳ Generating examples from = %s", filepath)
91
+
92
+ with open(filepath, encoding="utf-8") as f:
93
+
94
+ guid = 0
95
+ tokens = []
96
+ ner_tags = []
97
+
98
+ for line in f:
99
+ if line == "" or line == "\n":
100
+ if tokens:
101
+ yield guid, {
102
+ "id": str(guid),
103
+ "tokens": tokens,
104
+ "ner_tags": ner_tags,
105
+ }
106
+ guid += 1
107
+ tokens = []
108
+ ner_tags = []
109
+ else:
110
+ splits = line.split(" ")
111
+ tokens.append(splits[0])
112
+ ner_tags.append(splits[1].rstrip())
113
+
114
+ # last example
115
+ yield guid, {
116
+ "id": str(guid),
117
+ "tokens": tokens,
118
+ "ner_tags": ner_tags,
119
+ }