Create new file
Browse files
ornl20.py
ADDED
@@ -0,0 +1,73 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
# coding=utf-8
|
2 |
+
# Copyright 2020 The TensorFlow Datasets Authors and the HuggingFace NLP 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 |
+
"""Open Data Rechtspraak dutch topic classification dataset."""
|
18 |
+
|
19 |
+
from __future__ import absolute_import, division, print_function
|
20 |
+
|
21 |
+
import csv
|
22 |
+
|
23 |
+
# import nlp # old loader
|
24 |
+
import datasets
|
25 |
+
from datasets.tasks import TextClassification
|
26 |
+
|
27 |
+
|
28 |
+
_DESCRIPTION = """\
|
29 |
+
still a WIP, Dataset originally comes from Open Data van de Rechtspraak"
|
30 |
+
"""
|
31 |
+
|
32 |
+
_TRAIN_DOWNLOAD_URL = "https://huggingface.co/datasets/Rodekool/ornl20/resolve/main/train.csv"
|
33 |
+
_TEST_DOWNLOAD_URL = "https://huggingface.co/datasets/Rodekool/ornl20/resolve/main/test.csv"
|
34 |
+
|
35 |
+
|
36 |
+
class ORnl(datasets.GeneratorBasedBuilder):
|
37 |
+
"""Open Data van de Rechtspraak dutch topic classification dataset."""
|
38 |
+
|
39 |
+
def _info(self):
|
40 |
+
return datasets.DatasetInfo(
|
41 |
+
description=_DESCRIPTION,
|
42 |
+
features=datasets.Features(
|
43 |
+
{
|
44 |
+
"text": datasets.Value("string"),
|
45 |
+
"label": datasets.features.ClassLabel(names=['Ambtenarenrecht', 'Arbeidsrecht', 'Belastingrecht', 'Omgevingsrecht', 'Personen- en familierecht', 'Socialezekerheidsrecht', 'Verbintenissenrecht', 'Vreemdelingenrecht']),
|
46 |
+
}
|
47 |
+
),
|
48 |
+
homepage="https://www.rechtspraak.nl/Uitspraken/paginas/open-data.aspx",
|
49 |
+
)
|
50 |
+
|
51 |
+
def _split_generators(self, dl_manager):
|
52 |
+
train_path = dl_manager.download_and_extract(_TRAIN_DOWNLOAD_URL)
|
53 |
+
test_path = dl_manager.download_and_extract(_TEST_DOWNLOAD_URL)
|
54 |
+
return [
|
55 |
+
datasets.SplitGenerator(name=datasets.Split.TRAIN, gen_kwargs={"filepath": train_path}),
|
56 |
+
datasets.SplitGenerator(name=datasets.Split.TEST, gen_kwargs={"filepath": test_path}),
|
57 |
+
]
|
58 |
+
|
59 |
+
def _generate_examples(self, filepath):
|
60 |
+
"""Generate Rechtspraak examples."""
|
61 |
+
with open(filepath, encoding="utf-8") as csv_file:
|
62 |
+
csv_reader = csv.reader(
|
63 |
+
csv_file, quotechar='"', delimiter=",", quoting=csv.QUOTE_ALL, skipinitialspace=True
|
64 |
+
)
|
65 |
+
for id_, row in enumerate(csv_reader):
|
66 |
+
label, title, description = row
|
67 |
+
|
68 |
+
# Original labels are [1, 2, ... 25, 26] ->
|
69 |
+
# Re-map to [0, 1, ... 24, 25].
|
70 |
+
|
71 |
+
label = int(label) - 1
|
72 |
+
text = " ".join((title, description))
|
73 |
+
yield id_, {"text": text, "label": label}
|