leondz commited on
Commit
02997e8
1 Parent(s): 5469d0a

basic reader

Browse files
nordic_dsl_10000test.csv ADDED
@@ -0,0 +1,3 @@
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:59bcbe09179b6b6007710291750d258b586e53ddf0b3dd16df521bb6b25c7d4a
3
+ size 301970
nordic_dsl_10000train.csv ADDED
@@ -0,0 +1,3 @@
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:85aa0e96ad94f1eb02a341e03db0e0c8ed986d6faedbddf8538d969719e109df
3
+ size 5753499
nordic_dsl_50000test.csv ADDED
@@ -0,0 +1,3 @@
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:e2e06503670905fdc5324e23c70d4bb3a77c59aaf43eb071fdc8f4c28fccc9fa
3
+ size 1958240
nordic_dsl_50000train.csv ADDED
@@ -0,0 +1,3 @@
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:5b3e31ace17411a501eb0138c33c1d811a233cd09e918badec4abd81486e556c
3
+ size 37159623
nordic_langid.py ADDED
@@ -0,0 +1,152 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
+ """NordicDSL: A language identification datasets for Nordic languages"""
18
+
19
+ import csv
20
+ import os
21
+
22
+ import datasets
23
+
24
+
25
+ logger = datasets.logging.get_logger(__name__)
26
+
27
+
28
+ _CITATION = """\
29
+ @inproceedings{haas-derczynski-2021-discriminating,
30
+ title = "Discriminating Between Similar Nordic Languages",
31
+ author = "Haas, Ren{\'e} and
32
+ Derczynski, Leon",
33
+ booktitle = "Proceedings of the Eighth Workshop on NLP for Similar Languages, Varieties and Dialects",
34
+ month = apr,
35
+ year = "2021",
36
+ address = "Kiyv, Ukraine",
37
+ publisher = "Association for Computational Linguistics",
38
+ url = "https://aclanthology.org/2021.vardial-1.8",
39
+ pages = "67--75",
40
+ }
41
+
42
+ """
43
+
44
+ _DESCRIPTION = """\
45
+ Automatic language identification is a challenging problem. Discriminating
46
+ between closely related languages is especially difficult. This paper presents
47
+ a machine learning approach for automatic language identification for the
48
+ Nordic languages, which often suffer miscategorisation by existing
49
+ state-of-the-art tools. Concretely we will focus on discrimination between six
50
+ Nordic languages: Danish, Swedish, Norwegian (Nynorsk), Norwegian (Bokmål),
51
+ Faroese and Icelandic.
52
+
53
+ This is the data for the tasks. Two variants are provided: 10K and 50K, with
54
+ holding 10,000 and 50,000 examples for each language respectively.
55
+
56
+ """
57
+
58
+ _URLS = {
59
+ "10K": "nordic_dsl_10000",
60
+ "50K": "nordic_dsl_50000",
61
+ }
62
+
63
+
64
+ class NordicLangIdConfig(datasets.BuilderConfig):
65
+ """BuilderConfig for NordicLangId"""
66
+
67
+ def __init__(self, **kwargs):
68
+ """BuilderConfig NordicLangId.
69
+
70
+ Args:
71
+ **kwargs: keyword arguments forwarded to super.
72
+ """
73
+ super(NordicLangIdConfig, self).__init__(**kwargs)
74
+
75
+
76
+ class NordicLangId(datasets.GeneratorBasedBuilder):
77
+ """NordicLangId dataset."""
78
+
79
+ VERSION = datasets.Version("1.0.0")
80
+
81
+ BUILDER_CONFIGS = [
82
+ NordicLangIdConfig(
83
+ name="10k",
84
+ description="Data for distinguishing between similar Nordic languages: 10k examples per class",
85
+ version=VERSION,
86
+ ),
87
+ NordicLangIdConfig(
88
+ name="50k",
89
+ description="Data for distinguishing between similar Nordic languages: 50k examples per class",
90
+ version=VERSION,
91
+ ),
92
+ ]
93
+
94
+ def _info(self):
95
+ return datasets.DatasetInfo(
96
+ description=_DESCRIPTION,
97
+ features=datasets.Features(
98
+ {
99
+ "id": datasets.Value("string"),
100
+ "sentence": datasets.Value("string"),
101
+ "language": datasets.features.ClassLabel(
102
+ names=[
103
+ "dk",
104
+ "sv",
105
+ "nb",
106
+ "nn",
107
+ "fo",
108
+ "is",
109
+ ]
110
+ ),
111
+ }
112
+ ),
113
+ supervised_keys=None,
114
+ homepage="https://aclanthology.org/2021.vardial-1.8/",
115
+ citation=_CITATION,
116
+ )
117
+
118
+ def _split_generators(self, dl_manager):
119
+ """Returns SplitGenerators."""
120
+ if self.config.name == "10k":
121
+ downloaded_train = dl_manager.download(_URLS["10K"] + 'train.csv')
122
+ downloaded_test = dl_manager.download(_URLS["10K"] + 'test.csv')
123
+ elif self.config.name == "50k":
124
+ downloaded_train = dl_manager.download(_URLS["50K"] + 'train.csv')
125
+ downloaded_test = dl_manager.download(_URLS["50K"] + 'test.csv')
126
+
127
+ return [
128
+ datasets.SplitGenerator(name=datasets.Split.TRAIN, gen_kwargs={"filepath": downloaded_train}),
129
+ datasets.SplitGenerator(name=datasets.Split.TEST, gen_kwargs={"filepath": downloaded_test}),
130
+ ]
131
+
132
+ def _generate_examples(self, filepath):
133
+ logger.info("⏳ Generating examples from = %s", filepath)
134
+ with open(filepath, encoding="utf-8") as f:
135
+ guid = 0
136
+ for line in f:
137
+ line = line.strip()
138
+ if not line:
139
+ continue
140
+ if self.config.name == "10k":
141
+ line = line.replace('dataset10000, ', '')
142
+ if self.config.name == "50k":
143
+ line = line.replace('dataset50000, ', '')
144
+
145
+ instance = {
146
+ "id": str(guid),
147
+ "language": line[-2:],
148
+ "sentence": line[:-3],
149
+ }
150
+
151
+ yield guid, instance
152
+ guid += 1