pere commited on
Commit
4491bf8
1 Parent(s): 3a99adb

moved folders

Browse files
Files changed (1) hide show
  1. norwegian_parliament.py +85 -0
norwegian_parliament.py ADDED
@@ -0,0 +1,85 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # coding=utf-8
2
+ # Copyright 2020 The HuggingFace Datasets Authors and the current dataset script contributor.
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
+ """Norwegian Parliament Speeches (1998, 2016)"""
16
+ import csv
17
+
18
+ import datasets
19
+
20
+
21
+ _CITATION = """
22
+ @InProceedings{--,
23
+ author = {---},
24
+ title = {---},
25
+ booktitle = {---},
26
+ year = 2021,
27
+ address = "---"
28
+ }
29
+ """
30
+
31
+ _DESCRIPTION = """\
32
+ The Norwegian Parliament Speeches is a collection of text passages from
33
+ 1998 to 2016 and pronounced at the Norwegian Parliament (Storting) by members
34
+ of the two major parties: Fremskrittspartiet and Sosialistisk Venstreparti.
35
+ """
36
+
37
+
38
+ _HOMEPAGE = "https://github.com/NBAiLab/notram/"
39
+
40
+ _BASE_URL = "https://huggingface.co/datasets/NbAiLab/norwegian_parliament/tree/main/data/1.0.0"
41
+ _URLS = {
42
+ "train": f"{_BASE_URL}/train.csv",
43
+ "dev": f"{_BASE_URL}/dev.csv",
44
+ "test": f"{_BASE_URL}/test.csv",
45
+ }
46
+
47
+
48
+ class NorwegianParliament(datasets.GeneratorBasedBuilder):
49
+ """Norwegian Parliament Speeches (1998, 2016)"""
50
+
51
+ VERSION = datasets.Version("1.0.0")
52
+
53
+ def _info(self):
54
+ return datasets.DatasetInfo(
55
+ description=_DESCRIPTION,
56
+ features=datasets.Features(
57
+ {
58
+ "text": datasets.Value("string"),
59
+ "label": datasets.ClassLabel(names=["Fremskrittspartiet", "Sosialistisk Venstreparti"]),
60
+ "date": datasets.Value("string"),
61
+ }
62
+ ),
63
+ supervised_keys=None,
64
+ homepage=_HOMEPAGE,
65
+ citation=_CITATION,
66
+ )
67
+
68
+ def _split_generators(self, dl_manager):
69
+ downloaded_files = dl_manager.download(_URLS)
70
+ return [
71
+ datasets.SplitGenerator(name=datasets.Split.TRAIN, gen_kwargs={"filepath": downloaded_files["train"]}),
72
+ datasets.SplitGenerator(name=datasets.Split.VALIDATION, gen_kwargs={"filepath": downloaded_files["dev"]}),
73
+ datasets.SplitGenerator(name=datasets.Split.TEST, gen_kwargs={"filepath": downloaded_files["test"]}),
74
+ ]
75
+
76
+ def _generate_examples(self, filepath):
77
+ with open(filepath, encoding="utf-8") as csv_file:
78
+ csv_reader = csv.reader(csv_file, delimiter=",")
79
+ for idx, (label, text, _, date) in enumerate(csv_reader):
80
+ label = int(label)
81
+ yield int(idx), {
82
+ "text": text,
83
+ "label": label,
84
+ "date": date,
85
+ }