leondz commited on
Commit
26a2ef3
1 Parent(s): 5bc986d

add reader

Browse files
Files changed (1) hide show
  1. bornholmsk_parallel.py +138 -0
bornholmsk_parallel.py ADDED
@@ -0,0 +1,138 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # coding=utf-8
2
+ # Copyright 2020 HuggingFace Datasets Authors.
3
+ #
4
+ # Licensed under the Apache License, Version 2.0 (the "License");
5
+ # you may not use this file except in compliance with the License.
6
+ # You may obtain a copy of the License at
7
+ #
8
+ # http://www.apache.org/licenses/LICENSE-2.0
9
+ #
10
+ # Unless required by applicable law or agreed to in writing, software
11
+ # distributed under the License is distributed on an "AS IS" BASIS,
12
+ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13
+ # See the License for the specific language governing permissions and
14
+ # limitations under the License.
15
+
16
+ # Lint as: python3
17
+ """Introduction to the CoNLL-2003 Shared Task: Language-Independent Named Entity Recognition"""
18
+
19
+ import os
20
+
21
+ import datasets
22
+
23
+
24
+ logger = datasets.logging.get_logger(__name__)
25
+
26
+
27
+ _CITATION = """\
28
+ @inproceedings{derczynski-kjeldsen-2019-bornholmsk,
29
+ title = "Bornholmsk Natural Language Processing: Resources and Tools",
30
+ author = "Derczynski, Leon and
31
+ Kjeldsen, Alex Speed",
32
+ booktitle = "Proceedings of the 22nd Nordic Conference on Computational Linguistics",
33
+ month = sep # "{--}" # oct,
34
+ year = "2019",
35
+ address = "Turku, Finland",
36
+ publisher = {Link{\"o}ping University Electronic Press},
37
+ url = "https://aclanthology.org/W19-6138",
38
+ pages = "338--344",
39
+ abstract = {This paper introduces language processing resources and tools for Bornholmsk, a language spoken on the island of Bornholm, with roots in Danish and closely related to Scanian. This presents an overview of the language and available data, and the first NLP models for this living, minority Nordic language. Sammenfattnijng p{\aa} borrijnholmst: D{\ae}jnna artikkelijn introduserer naturspr{\aa}gsresurser {\aa} varktoi for borrijnholmst, ed spr{\aa}g a d{\ae}r snakkes p{\aa} {\"o}n Borrijnholm me r{\o}dder i danst {\aa} i n{\ae}r familia me sk{\aa}nst. Artikkelijn gjer ed {\^a}uersyn {\^a}uer spr{\aa}ged {\aa} di datan som fijnnes, {\aa} di fosste NLP mod{\ae}llarna for d{\ae}tta l{\ae}wenes nordiska minnret{\^a}lsspr{\aa}ged.},
40
+ }
41
+
42
+ """
43
+
44
+ _DESCRIPTION = """\
45
+ This corpus introduces language processing resources and tools for Bornholmsk, a language spoken on the island of Bornholm, with roots in Danish and closely related to Scanian.
46
+
47
+ Sammenfattnijng på borrijnholmst: Dæjnna artikkelijn introduserer natursprågsresurser å varktoi for borrijnholmst, ed språg a dær snakkes på ön Borrijnholm me rødder i danst å i nær familia me skånst.
48
+ """
49
+
50
+ _URL_BASE = "https://github.com/StrombergNLP/bornholmsk/blob/0bdb51bf7522c1d154bcc9c54f6ffd4c5125a121/parallel."
51
+
52
+
53
+ class BornholmskConfig(datasets.BuilderConfig):
54
+ """BuilderConfig for Bornholmsk"""
55
+
56
+ def __init__(self, **kwargs):
57
+ """BuilderConfig Bornholmsk.
58
+
59
+ Args:
60
+ **kwargs: keyword arguments forwarded to super.
61
+ """
62
+ super(BornholmskConfig, self).__init__(**kwargs)
63
+
64
+
65
+ class Bornholmsk(datasets.GeneratorBasedBuilder):
66
+ """Bornholmsk dataset."""
67
+
68
+ BUILDER_CONFIGS = [
69
+ BornholmskConfig(name="Bornholmsk", version=datasets.Version("1.0.0"), description="Bornholmsk text"),
70
+ ]
71
+
72
+ def _info(self):
73
+ return datasets.DatasetInfo(
74
+ description=_DESCRIPTION,
75
+ features=datasets.Features(
76
+ {
77
+ "id": datasets.Value("string"),
78
+ "da_bornholm": datasets.Value("string"),
79
+ "da": datasets.Value("string"),
80
+ }
81
+ ),
82
+ supervised_keys=None,
83
+ homepage="https://github.com/StrombergNLP/bornholmsk",
84
+ citation=_CITATION,
85
+ )
86
+
87
+ def _split_generators(self, dl_manager):
88
+ """Returns SplitGenerators."""
89
+ downloaded_files = {}
90
+ for lang in ('da', 'da-bornholm'):
91
+ for partition in ('train', 'val', 'test'):
92
+ part = f"{lang}.{partition}"
93
+ downloaded_files[part] = dl_manager.download_and_extract(_URL_BASE + part)
94
+
95
+ return [
96
+ datasets.SplitGenerator(
97
+ name=datasets.Split.TRAIN,
98
+ gen_kwargs={"filepath":
99
+ {
100
+ 'da': downloaded_files['da.train'],
101
+ 'da-bornholm':downloaded_files['da-bornholm.train']
102
+ }
103
+ }
104
+ ),
105
+ datasets.SplitGenerator(
106
+ name=datasets.Split.VALIDATION,
107
+ gen_kwargs={"filepath":
108
+ {
109
+ 'da': downloaded_files['da.val'],
110
+ 'da-bornholm':downloaded_files['da-bornholm.val']
111
+ }
112
+ }
113
+ ),
114
+ datasets.SplitGenerator(
115
+ name=datasets.Split.TEST,
116
+ gen_kwargs={"filepath":
117
+ {
118
+ 'da': downloaded_files['da.test'],
119
+ 'da-bornholm':downloaded_files['da-bornholm.test']
120
+ }
121
+ }
122
+ ),
123
+ ]
124
+
125
+ def _generate_examples(self, filepath):
126
+ logger.info("⏳ Generating examples from = %s and %s", (filepath['da'], filepath['da-bornholm']))
127
+ guid = 0
128
+ with open(filepath['da-bornholm'], encoding="utf-8") as f_da:
129
+ with open(filepath['da'], encoding="utf-8") as f_bo:
130
+ bo = f_bo.readlines()
131
+ da = f_da.readlines()
132
+ for instance in zip(bo, da):
133
+ yield guid, {
134
+ "id": str(guid),
135
+ "da_bornholm": instance[0],
136
+ "da": instance[1],
137
+ }
138
+ guid += 1