Datasets:

ArXiv:
License:
kiddothe2b commited on
Commit
23b4df8
1 Parent(s): 2ae174e

Create eu_debates.py

Browse files
Files changed (1) hide show
  1. eu_debates.py +112 -0
eu_debates.py ADDED
@@ -0,0 +1,112 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ """EU Debates"""
2
+
3
+ import json
4
+ import os
5
+ import textwrap
6
+
7
+ import datasets
8
+
9
+
10
+ MAIN_CITATION = """
11
+ @inproceedings{chalkidis-and-brandl-eu-llama-2024,
12
+ title = "Llama meets EU: Investigating the European political spectrum through the lens of LLMs",
13
+ author = "Chalkidis, Ilias and
14
+ Stephanie Brandl",
15
+ booktitle = "Proceedings of the 2024 Conference of the North American Chapter of the Association for Computational Linguistics",
16
+ month = jun,
17
+ year = "2021",
18
+ address = "Mexico City, Mexico",
19
+ publisher = "Association for Computational Linguistics",
20
+ }
21
+ """
22
+
23
+ _DESCRIPTION = """
24
+ EU Debates is a corpus of parliamentary proceedings (debates) from the EU parliament. The corpus consists of approx. 87k individual speeches in the period 2009-2023.
25
+ We exhaustively scrape the data from the official European Parliament Plenary website. All speeches are time-stamped, thematically organized on debates,
26
+ and include metadata relevant to the speaker's identity (full name, euro-party affiliation, speaker role), and the debate (date and title).
27
+ Older debate speeches are originally in English, while newer ones are linguistically diverse across the 23 official EU languages, thus we also provide machine-translated
28
+ versions in English, when official translations are missing.
29
+ """
30
+ MAIN_PATH = 'https://huggingface.co/datasets/coastalcph/eu_debates/resolve/main'
31
+
32
+
33
+ class EUDebatesConfig(datasets.BuilderConfig):
34
+ """BuilderConfig for EU Debates"""
35
+
36
+ def __init__(
37
+ self,
38
+ data_url,
39
+ citation,
40
+ **kwargs,
41
+ ):
42
+ """BuilderConfig for EU Debates.
43
+
44
+ Args:
45
+ data_url: `string`, url to download the zip file from
46
+ data_file: `string`, filename for data set
47
+ url: `string`, url for information about the data set
48
+ **kwargs: keyword arguments forwarded to super.
49
+ """
50
+ super(EUParliamentsConfig, self).__init__(version=datasets.Version("1.0.0", ""), **kwargs)
51
+ self.data_url = data_url
52
+ self.citation = citation
53
+
54
+
55
+ class EUDebates(datasets.GeneratorBasedBuilder):
56
+ """N/A. Version 1.0"""
57
+
58
+ BUILDER_CONFIGS = [
59
+ EUParliamentsConfig(
60
+ name="eu",
61
+ data_url=os.path.join(MAIN_PATH, "eu_parliament.zip"),
62
+ citation=textwrap.dedent(
63
+ """N/A"""
64
+ ),
65
+ ),
66
+ ]
67
+
68
+ def _info(self):
69
+ features = {"text": datasets.Value("string"),
70
+ "translated_text": datasets.Value("string"),
71
+ "speaker_party": datasets.Value("string"),
72
+ "speaker_role": datasets.Value("string"),
73
+ "speaker_name": datasets.Value("string"),
74
+ "debate_title": datasets.Value("string"),
75
+ "date": datasets.Value("string"),
76
+ "year": datasets.Value("string")}
77
+ return datasets.DatasetInfo(
78
+ description=self.config.description,
79
+ features=datasets.Features(features),
80
+ homepage='https://www.europarl.europa.eu/',
81
+ citation=MAIN_CITATION,
82
+ )
83
+
84
+ def _split_generators(self, dl_manager):
85
+ data_dir = dl_manager.download_and_extract(self.config.data_url)
86
+ return [
87
+ datasets.SplitGenerator(
88
+ name=datasets.Split.TRAIN,
89
+ # These kwargs will be passed to _generate_examples
90
+ gen_kwargs={
91
+ "filepath": os.path.join(data_dir, f"train.jsonl"),
92
+ "split": "train",
93
+ },
94
+ ),
95
+ ]
96
+
97
+ def _generate_examples(self, filepath, split):
98
+ """This function returns the examples."""
99
+ with open(filepath, encoding="utf-8") as f:
100
+ for id_, row in enumerate(f):
101
+ data = json.loads(row)
102
+ example = {
103
+ "text": data["text"],
104
+ "translated_text": data["translated_text"],
105
+ "speaker_party": data["speaker_party"],
106
+ "speaker_role": data["speaker_role"],
107
+ "speaker_name": data["speaker_name"],
108
+ "debate_title": data["debate_title"],
109
+ "date": data["date"],
110
+ "year": data["year"]
111
+ }
112
+ yield id_, example