Datasets:

Languages:
Hebrew
ArXiv:
Libraries:
Datasets
pandas
License:
GiliGold commited on
Commit
d329c13
1 Parent(s): 57f257d

dataset loader

Browse files
Files changed (1) hide show
  1. knessetCorpus.py +283 -0
knessetCorpus.py ADDED
@@ -0,0 +1,283 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import json
2
+ import os
3
+ from typing import List
4
+
5
+ import datasets
6
+
7
+
8
+ _KnessetCorpus_CITATION = """\
9
+ @article{
10
+ }
11
+ """
12
+
13
+ _KnessetCorpus_DESCRIPTION = """
14
+ An annotated corpus of Hebrew parliamentary proceedings containing over 32 million sentences from all the (plenary and committee) protocols held in the Israeli parliament from 1998 to 2022.
15
+ Sentences are annotated with various levels of linguistic information, including part-of-speech tags, morphological features, dependency structures, and named entities.
16
+ They are also associated with detailed meta-information reflecting demographic and political properties of the speakers, based on a large database of parliament members and factions that we compiled.
17
+ """
18
+ _AllFeaturesSentences_DESCRIPTION = """\
19
+ AllFeaturesSentences consists of samples of all the sentences in the corpus (plenary and committee) together with all the features available in the dataset:\
20
+ The features are consistent with the Sentence model features, the Protocol model features of the protocol the sentence belongs to,
21
+ the Person model features of the speaker and the Faction model features \
22
+ of the faction of the speaker at that time.
23
+ This is roughly equivalent to a join between all models in dataset (Protocol, Faction, Person, Sentence)
24
+ """
25
+
26
+ _CommitteeAllFeaturesSentences_DESCRIPTION = """\
27
+ CommitteeAllFeaturesSentences consists of samples of all the sentences in the committee sessions in the corpus together with all the features available in the dataset:\
28
+ The features are consistent with the Sentence model features, the Protocol model features of the protocol the sentence belongs to,
29
+ the Person model features of the speaker and the Faction model features \
30
+ of the faction of the speaker at that time.
31
+ This is roughly equivalent to a join between all models in dataset (Protocol, Faction, Person, Sentence)
32
+ """
33
+
34
+ _PlenaryAllFeaturesSentences_DESCRIPTION = """\
35
+ PlenaryAllFeaturesSentences consists of samples of all the sentences in the plenary sessions in the corpus together with all the features available in the dataset:\
36
+ The features are consistent with the Sentence model features, the Protocol model features of the protocol the sentence belongs to,
37
+ the Person model features of the speaker and the Faction model features \
38
+ of the faction of the speaker at that time.
39
+ This is roughly equivalent to a join between all models in dataset (Protocol, Faction, Person, Sentence)
40
+ """
41
+
42
+ _KnessetMembers_DESCRIPTION = """\
43
+ KnessetMembers consists of samples of the knesset members in the dataset and their meta-data information such as name, gender and factions affiliations.
44
+ The features are consistent with the Person model features
45
+ """
46
+
47
+ _Factions_DESCRIPTION = """\
48
+ Factions consists of samples of the factions in the dataset and their meta-data information such as name, political orientation and active periods.
49
+ The features are consistent with the Faction model features
50
+ """
51
+
52
+ _Protocols_DESCRIPTION = """\
53
+ Protocols consists of samples of the protocols in the dataset and their meta-data information such as date, knesset number, session name and a list of its sentences.
54
+ The features are consistent with the Protocol model features and the features for each sentence are consistent with the Sentence model
55
+ """
56
+ class KnessetCorpusConfig(datasets.BuilderConfig):
57
+ """BuilderConfig for KnessetCorpus."""
58
+
59
+ def __init__(self, features, data_urls, citation, **kwargs):
60
+ """BuilderConfig for KnessetCorpus.
61
+
62
+ Args:
63
+ features: *list[string]*, list of the features that will appear in the
64
+ feature dict. Should not include "label".
65
+ data_urls: *list[string]*, urls to download the files from.
66
+ citation: *string*, citation for the data set.
67
+ **kwargs: keyword arguments forwarded to super.
68
+ """
69
+
70
+ super().__init__(version=datasets.Version("1.0.1"), **kwargs)
71
+ self.features = features
72
+ self.data_urls = data_urls
73
+ self.citation = citation
74
+
75
+
76
+
77
+
78
+
79
+ class KnessetCorpus(datasets.GeneratorBasedBuilder):
80
+
81
+ BUILDER_CONFIG_CLASS = KnessetCorpusConfig
82
+ BUILDER_CONFIGS = [
83
+ KnessetCorpusConfig(
84
+ name="knessetMembers",
85
+ description=_KnessetMembers_DESCRIPTION,
86
+ features=["person_id", "first_name", "last_name", "full_name", "is_knesset_member", "gender", "email", "is_current", "last_updated_date", "date_of_birth", "place_of_birth", "year_of_aliya", "date_of_death", "mother_tongue", "religion", "nationality", "religious_orientation", "residence", "factions_memberships", "languages","allSources", "wikiLink","notes" ],
87
+ data_urls=["https://huggingface.co/datasets/HaifaCLGroup/KnessetCorpus/blob/main/all_knesset_members_jsons.jsonl"],
88
+ citation=_KnessetCorpus_CITATION,
89
+ ),
90
+ KnessetCorpusConfig(
91
+ name="factions",
92
+ description=_Factions_DESCRIPTION,
93
+ features=["faction_name", "faction_popular_initials", "faction_id", "active_periods", "knesset_numbers", "coalition_or_opposition_memberships", "political_orientation", "other_names", "notes", "wiki_link", ],
94
+ data_urls=["https://huggingface.co/datasets/HaifaCLGroup/KnessetCorpus/blob/main/factions_jsons.jsonl"],
95
+ citation=_KnessetCorpus_CITATION,
96
+ ),
97
+ KnessetCorpusConfig(
98
+ name="protocols",
99
+ description=_Protocols_DESCRIPTION,
100
+ features=["protocol_name", "session_name", "parent_session_name", "knesset_number", "protocol_number", "protocol_date", "is_ocr_output", "protocol_type", "protocol_sentences"],
101
+ data_urls=["https://dl.fbaipublicfiles.com/glue/superglue/data/v2/BoolQ.zip"],#TODO
102
+ citation=_KnessetCorpus_CITATION,
103
+ ),
104
+ KnessetCorpusConfig(
105
+ name="all_features_sentences",
106
+ description=_AllFeaturesSentences_DESCRIPTION,
107
+ features=["sentence_id", "protocol_name", "speaker_id", "speaker_name", "is_valid_speaker", "turn_num_in_protocol", "sent_num_in_turn", "sentence_text", "is_chairman","morphological_fields", "speaker_first_name", "speaker_last_name", "speaker_is_knesset_member", "speaker_gender", "speaker_email", "speaker_last_updated_date", "speaker_date_of_birth", "speaker_place_of_birth","speaker_year_of_aliya", "speaker_date_of_death", "speaker_mother_tongue", "speaker_religion", "speaker_nationality", "speaker_religious_orientation", "speaker_residence", "speaker_factions_memberships", "speaker_languages", "speaker_sources", "speaker_notes","faction_id", "faction_general_name", "knesset_faction_id", "current_faction_name", "member_of_coalition_or_opposition", "faction_popular_initials", "faction_active_periods", "faction_knesset_numbers","faction_coalition_or_opposition_memberships", "faction_political_orientation", "faction_other_names", "faction_notes", "faction_wiki_link"],
108
+ data_urls=["https://huggingface.co/datasets/HaifaCLGroup/KnessetCorpus/blob/main/protocols_sentences/committee_full_sentences.jsonl.bz2", "https://huggingface.co/datasets/HaifaCLGroup/KnessetCorpus/blob/main/protocols_sentences/plenary_full_sentences.jsonl.bz2"],
109
+ citation=_KnessetCorpus_CITATION,
110
+ ),
111
+ KnessetCorpusConfig(
112
+ name="committees_all_features_sentences",
113
+ description=_AllFeaturesSentences_DESCRIPTION,
114
+ features=["sentence_id", "protocol_name", "speaker_id", "speaker_name", "is_valid_speaker", "turn_num_in_protocol", "sent_num_in_turn", "sentence_text", "is_chairman","morphological_fields", "speaker_first_name", "speaker_last_name", "speaker_is_knesset_member", "speaker_gender", "speaker_email", "speaker_last_updated_date", "speaker_date_of_birth", "speaker_place_of_birth","speaker_year_of_aliya", "speaker_date_of_death", "speaker_mother_tongue", "speaker_religion", "speaker_nationality", "speaker_religious_orientation", "speaker_residence", "speaker_factions_memberships", "speaker_languages", "speaker_sources", "speaker_notes","faction_id", "faction_general_name", "knesset_faction_id", "current_faction_name", "member_of_coalition_or_opposition", "faction_popular_initials", "faction_active_periods", "faction_knesset_numbers","faction_coalition_or_opposition_memberships", "faction_political_orientation", "faction_other_names", "faction_notes", "faction_wiki_link"],
115
+ data_urls=["https://huggingface.co/datasets/HaifaCLGroup/KnessetCorpus/blob/main/protocols_sentences/committee_full_sentences.jsonl.bz2"],
116
+ citation=_KnessetCorpus_CITATION,
117
+ ),
118
+ KnessetCorpusConfig(
119
+ name="plenary_all_features_sentences",
120
+ description=_AllFeaturesSentences_DESCRIPTION,
121
+ features=["sentence_id", "protocol_name", "speaker_id", "speaker_name", "is_valid_speaker", "turn_num_in_protocol", "sent_num_in_turn", "sentence_text", "is_chairman","morphological_fields", "speaker_first_name", "speaker_last_name", "speaker_is_knesset_member", "speaker_gender", "speaker_email", "speaker_last_updated_date", "speaker_date_of_birth", "speaker_place_of_birth","speaker_year_of_aliya", "speaker_date_of_death", "speaker_mother_tongue", "speaker_religion", "speaker_nationality", "speaker_religious_orientation", "speaker_residence", "speaker_factions_memberships", "speaker_languages", "speaker_sources", "speaker_notes","faction_id", "faction_general_name", "knesset_faction_id", "current_faction_name", "member_of_coalition_or_opposition", "faction_popular_initials", "faction_active_periods", "faction_knesset_numbers","faction_coalition_or_opposition_memberships", "faction_political_orientation", "faction_other_names", "faction_notes", "faction_wiki_link"],
122
+ data_urls=["https://huggingface.co/datasets/HaifaCLGroup/KnessetCorpus/blob/main/protocols_sentences/plenary_full_sentences.jsonl.bz2"],
123
+ citation=_KnessetCorpus_CITATION,
124
+ )]
125
+
126
+ # DEFAULT_CONFIG_NAME = "all_features_sentences"
127
+
128
+ def _info(self):
129
+ features = {feature: datasets.Value("string") for feature in self.config.features}
130
+
131
+ if "all_features_sentences" in self.config.name:
132
+ features.update({
133
+ "faction_active_periods": datasets.Sequence({
134
+ "end_date": datasets.Value("string"), # Date converted to string
135
+ "start_date": datasets.Value("string"), # Date converted to string
136
+ }),
137
+ "faction_coalition_or_opposition_memberships": datasets.Sequence({
138
+ "end_date": datasets.Value("string"), # Date converted to string
139
+ "knesset_faction_name": datasets.Value("string"),
140
+ "knesset_num": datasets.Value("string"),
141
+ "member_of_coalition": datasets.Value("bool"),
142
+ "notes": datasets.Value("string"),
143
+ "start_date": datasets.Value("string") # Date converted to string
144
+ }),
145
+ "faction_other_names": datasets.Sequence({
146
+ "name": datasets.Value("string"),
147
+ "name_end_date": datasets.Value("string"), # Date converted to string
148
+ "name_start_date": datasets.Value("string") # Date converted to string
149
+ }),
150
+ "is_chairman": datasets.Value("bool"),
151
+ "is_ocr_output": datasets.Value("bool"),
152
+ "is_valid_speaker": datasets.Value("bool"),
153
+ "sent_num_in_turn": datasets.Value("int64"),
154
+ "turn_num_in_protocol": datasets.Value("int64"),
155
+ "morphological_fields": datasets.Sequence({
156
+ "id": datasets.Value("string"),
157
+ "form": datasets.Value("string"),
158
+ "lemma": datasets.Value("string"),
159
+ "upos": datasets.Value("string"),
160
+ "xpos": datasets.Value("string"),
161
+ "feats": datasets.Value("string"),
162
+ "head": datasets.Value("int32"),
163
+ "deprel": datasets.Value("string"),
164
+ "deps": datasets.Value("string"),
165
+ "misc": datasets.Value("string")}),
166
+ "speaker_factions_memberships": datasets.Sequence({
167
+ "end_date": datasets.Value("string"),
168
+ "faction_id": datasets.Value("string"),
169
+ "faction_name": datasets.Value("string"),
170
+ "knesset_faction_id": datasets.Value("string"),
171
+ "knesset_number": datasets.Value("string"),
172
+ "start_date": datasets.Value("string")}),
173
+ "speaker_is_knesset_member": datasets.Value("bool"),
174
+ "speaker_notes": datasets.Sequence(datasets.Value("string")),
175
+ "speaker_languages": datasets.Sequence(datasets.Value("string"))
176
+ })
177
+
178
+ if self.config.name == "protocols":
179
+ features.update({
180
+ "is_ocr_output": datasets.Value("bool"),
181
+ "protocol_sentences": datasets.Sequence({
182
+ "sentence_id": datasets.Value("string"),
183
+ "protocol_name": datasets.Value("string"),
184
+ "speaker_id": datasets.Value("string"),
185
+ "speaker_name": datasets.Value("string"),
186
+ "is_valid_speaker": datasets.Value("bool"),
187
+ "turn_num_in_protocol": datasets.Value("int64"),
188
+ "sent_num_in_turn": datasets.Value("int64"),
189
+ "sentence_text": datasets.Value("string"),
190
+ "is_chairman": datasets.Value("bool"),
191
+ "morphological_fields": datasets.Sequence({
192
+ "id": datasets.Value("string"),
193
+ "form": datasets.Value("string"),
194
+ "lemma": datasets.Value("string"),
195
+ "upos": datasets.Value("string"),
196
+ "xpos": datasets.Value("string"),
197
+ "feats": datasets.Value("string"),
198
+ "head": datasets.Value("int32"),
199
+ "deprel": datasets.Value("string"),
200
+ "deps": datasets.Value("string"),
201
+ "misc": datasets.Value("string"),
202
+ }),
203
+ "factuality_fields": datasets.Value("string")
204
+ })
205
+ })
206
+ if self.config.name == "factions":
207
+ features.update({
208
+ "active_periods": datasets.Sequence({
209
+ "end_date": datasets.Value("string"), # Date converted to string
210
+ "start_date": datasets.Value("string"), # Date converted to string
211
+ }),
212
+ "coalition_or_opposition_memberships": datasets.Sequence({
213
+ "end_date": datasets.Value("string"), # Date converted to string
214
+ "knesset_faction_name": datasets.Value("string"),
215
+ "knesset_num": datasets.Value("string"),
216
+ "member_of_coalition": datasets.Value("bool"),
217
+ "notes": datasets.Value("string"),
218
+ "start_date": datasets.Value("string"), # Date converted to string
219
+ }),
220
+ "other_names": datasets.Sequence({
221
+ "name": datasets.Value("string"),
222
+ "name_end_date": datasets.Value("string"), # Date converted to string
223
+ "name_start_date": datasets.Value("string"), # Date converted to string
224
+ })
225
+ })
226
+ if self.config.name == "KnessetMembers":
227
+ features.update({
228
+ "is_knesset_member": datasets.Value("bool"),
229
+ "factions_memberships": datasets.Sequence({
230
+ "end_date": datasets.Value("string"),
231
+ "faction_id": datasets.Value("string"),
232
+ "faction_name": datasets.Value("string"),
233
+ "knesset_faction_id": datasets.Value("string"),
234
+ "knesset_number": datasets.Value("string"),
235
+ "start_date": datasets.Value("string")}),
236
+ "notes": datasets.Sequence(datasets.Value("string")),
237
+ "languages": datasets.Sequence(datasets.Value("string"))
238
+ })
239
+
240
+ return datasets.DatasetInfo(
241
+ description=_KnessetCorpus_DESCRIPTION + self.config.description,
242
+ features=datasets.Features(features),
243
+ citation=self.config.citation
244
+ )
245
+ def _split_generators(self, dl_manager: datasets.DownloadManager) -> List[datasets.SplitGenerator]:
246
+ urls = self.config.data_urls
247
+ downloaded_files = dl_manager.download_and_extract(urls)
248
+
249
+ return [
250
+ datasets.SplitGenerator(
251
+ name=datasets.Split.TRAIN,
252
+ gen_kwargs={
253
+ "data_files": downloaded_files,
254
+ "split": "train",
255
+ },
256
+ ),
257
+ ]
258
+
259
+ def _generate_examples(self, data_files):
260
+ if "all_features_sentences" in self.config.name:
261
+ id_field_name = "sentence_id"
262
+ elif self.config.name == "protocols":
263
+ id_field_name = "protocol_name"
264
+ elif self.config.name == "factions":
265
+ id_field_name = "faction_id"
266
+ elif self.config.name == "knessetMembers":
267
+ id_field_name = "person_id"
268
+
269
+ for i, filepath in enumerate(data_files):
270
+ with open(filepath, encoding="utf-8") as f:
271
+ for line in f:
272
+ try:
273
+ row = json.loads(line)
274
+ except Exception as e:
275
+ print(f'couldnt load sample. error was: {e}. Continuing to next sample')
276
+ continue
277
+ id_ = row[id_field_name]
278
+ yield id_, row
279
+
280
+
281
+
282
+
283
+