Datasets:
Tasks:
Text Classification
Modalities:
Text
Sub-tasks:
multi-label-classification
Languages:
Portuguese
Size:
1K - 10K
License:
Create ptparl.py
Browse files
ptparl.py
ADDED
@@ -0,0 +1,117 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
"""ptparl dataset."""
|
2 |
+
|
3 |
+
|
4 |
+
import xml.etree.ElementTree as ET
|
5 |
+
|
6 |
+
import datasets
|
7 |
+
import csv
|
8 |
+
|
9 |
+
_DESCRIPTION = """
|
10 |
+
The PTPARL dataset is a dataset containing 5713 interventions in the Portuguese parliament.
|
11 |
+
"""
|
12 |
+
|
13 |
+
_HOMEPAGE = "MIT"
|
14 |
+
|
15 |
+
_LICENSE = ""
|
16 |
+
|
17 |
+
_URL = "https://gist.githubusercontent.com/luist18/e3730636962a117ef0eb9e0659f1cba8/raw/5e55a95aaec8261c7690c7132037121d99c39279/pt_parl.csv"
|
18 |
+
|
19 |
+
|
20 |
+
group_map = {
|
21 |
+
"PS": 0,
|
22 |
+
"CDS-PP": 1,
|
23 |
+
"PCP": 2,
|
24 |
+
"BE": 3,
|
25 |
+
"PSD": 4,
|
26 |
+
"PEV": 5,
|
27 |
+
"PAN": 6,
|
28 |
+
"CH": 7,
|
29 |
+
"IL": 8,
|
30 |
+
"L": 9,
|
31 |
+
}
|
32 |
+
|
33 |
+
wing_map = {
|
34 |
+
"LEFT": 0,
|
35 |
+
"LEAN_LEFT": 1,
|
36 |
+
"CENTER": 2,
|
37 |
+
"LEAN_RIGHT": 3,
|
38 |
+
"RIGHT": 4,
|
39 |
+
}
|
40 |
+
|
41 |
+
|
42 |
+
class PTPARL(datasets.GeneratorBasedBuilder):
|
43 |
+
"""PTPARL dataset."""
|
44 |
+
|
45 |
+
VERSION = datasets.Version("1.0.0")
|
46 |
+
|
47 |
+
BUILDER_CONFIGS = [
|
48 |
+
datasets.BuilderConfig(
|
49 |
+
name="full",
|
50 |
+
version=VERSION,
|
51 |
+
description="Full dataset",
|
52 |
+
),
|
53 |
+
]
|
54 |
+
|
55 |
+
DEFAULT_CONFIG_NAME = "full"
|
56 |
+
|
57 |
+
def _info(self):
|
58 |
+
features = datasets.Features(
|
59 |
+
{
|
60 |
+
"text": datasets.Value("string"),
|
61 |
+
"group": datasets.features.ClassLabel(
|
62 |
+
names=[
|
63 |
+
"PS",
|
64 |
+
"CDS-PP",
|
65 |
+
"PCP",
|
66 |
+
"BE",
|
67 |
+
"PSD",
|
68 |
+
"PEV",
|
69 |
+
"PAN",
|
70 |
+
"CH",
|
71 |
+
"IL",
|
72 |
+
"L",
|
73 |
+
]
|
74 |
+
),
|
75 |
+
"wing": datasets.features.ClassLabel(
|
76 |
+
names=[["CENTER", "LEAN_RIGHT", "LEFT", "LEAN_LEFT", "RIGHT"]]
|
77 |
+
),
|
78 |
+
}
|
79 |
+
)
|
80 |
+
return datasets.DatasetInfo(
|
81 |
+
description=_DESCRIPTION,
|
82 |
+
features=features,
|
83 |
+
supervised_keys=None,
|
84 |
+
homepage=_HOMEPAGE,
|
85 |
+
license=_LICENSE,
|
86 |
+
citation=None,
|
87 |
+
)
|
88 |
+
|
89 |
+
def _split_generators(self, dl_manager):
|
90 |
+
"""Returns SplitGenerators."""
|
91 |
+
|
92 |
+
data_file = dl_manager.download_and_extract(_URL)
|
93 |
+
return [
|
94 |
+
datasets.SplitGenerator(
|
95 |
+
name=datasets.Split.TRAIN,
|
96 |
+
gen_kwargs={
|
97 |
+
"filepath": data_file,
|
98 |
+
},
|
99 |
+
),
|
100 |
+
]
|
101 |
+
|
102 |
+
def _generate_examples(self, filepath):
|
103 |
+
"""Yields examples."""
|
104 |
+
|
105 |
+
id_ = 0
|
106 |
+
|
107 |
+
with open(filepath, encoding="utf-8") as tsv_file:
|
108 |
+
reader = csv.reader(tsv_file, delimiter="\t")
|
109 |
+
for id_, row in enumerate(reader):
|
110 |
+
if id_ == 0:
|
111 |
+
continue
|
112 |
+
|
113 |
+
yield id_, {
|
114 |
+
"text": row[0],
|
115 |
+
"group": group_map[row[1]],
|
116 |
+
"wing": wing_map[row[2]],
|
117 |
+
}
|