shamikbose89 commited on
Commit
4c207ef
1 Parent(s): afd6453

Upload contentious_contexts.py

Browse files
Files changed (1) hide show
  1. contentious_contexts.py +132 -0
contentious_contexts.py ADDED
@@ -0,0 +1,132 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # Copyright 2020 The HuggingFace Datasets Authors and the current dataset script contributor.
2
+ #
3
+ # Licensed under the Apache License, Version 2.0 (the "License");
4
+ # you may not use this file except in compliance with the License.
5
+ # You may obtain a copy of the License at
6
+ #
7
+ # http://www.apache.org/licenses/LICENSE-2.0
8
+ #
9
+ # Unless required by applicable law or agreed to in writing, software
10
+ # distributed under the License is distributed on an "AS IS" BASIS,
11
+ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12
+ # See the License for the specific language governing permissions and
13
+ # limitations under the License.
14
+ """This dataset contains extracts from historical Dutch newspapers which have been containing keywords of potentially contentious words (according to present-day sensibilities).
15
+ The dataset contains multiple annotations per instance, given the option to quantify agreement scores for annotations."""
16
+
17
+ import pandas as pd
18
+ import datasets
19
+
20
+
21
+ _CITATION = """@misc{ContentiousContextsCorpus2021,
22
+ author = {Cultural AI},
23
+ title = {Contentious Contexts Corpus},
24
+ year = {2021},
25
+ publisher = {GitHub},
26
+ journal = {GitHub repository},
27
+ howpublished = {\\url{https://github.com/cultural-ai/ConConCor}},
28
+ }
29
+ """
30
+
31
+ _DESCRIPTION = """This dataset contains extracts from historical Dutch newspapers which have been containing keywords of potentially contentious words (according to present-day sensibilities).
32
+ The dataset contains multiple annotations per instance, given the option to quantify agreement scores for annotations. This dataset can be used to track how words and their meanings have changed over time
33
+ """
34
+
35
+
36
+ _HOMEPAGE = "https://github.com/cultural-ai/ConConCor"
37
+
38
+
39
+ _LICENSE = "CC-BY"
40
+
41
+ _URLS = [
42
+ "https://raw.githubusercontent.com/cultural-ai/ConConCor/main/Dataset/Annotations.csv",
43
+ "https://raw.githubusercontent.com/cultural-ai/ConConCor/main/Dataset/Extracts.csv",
44
+ ]
45
+ response_mapping = {
46
+ "Omstreden naar huidige maatstaven": "Contentious according to current standards",
47
+ "Niet omstreden": "Not contentious",
48
+ "Weet ik niet": "I don't know",
49
+ "Onleesbare OCR": "Illegible OCR",
50
+ }
51
+
52
+ logger = datasets.utils.logging.get_logger(__name__)
53
+
54
+
55
+ class ContentiousContexts(datasets.GeneratorBasedBuilder):
56
+ """This dataset contains extracts from historical Dutch newspapers which have been containing keywords of potentially contentious words"""
57
+
58
+ VERSION = datasets.Version("1.0.0")
59
+
60
+ def _info(self):
61
+ features = datasets.Features(
62
+ {
63
+ "extract_id": datasets.Value("string"),
64
+ "text": datasets.Value("string"),
65
+ "target": datasets.Value("string"),
66
+ "annotator_responses_english": [
67
+ {
68
+ "id": datasets.Value("string"),
69
+ "response": datasets.Value("string"),
70
+ }
71
+ ],
72
+ "annotator_responses_dutch": [
73
+ {
74
+ "id": datasets.Value("string"),
75
+ "response": datasets.Value("string"),
76
+ }
77
+ ],
78
+ "annotator_suggestions": [
79
+ {
80
+ "id": datasets.Value("string"),
81
+ "suggestion": datasets.Value("string"),
82
+ }
83
+ ],
84
+ }
85
+ )
86
+ return datasets.DatasetInfo(
87
+ description=_DESCRIPTION,
88
+ features=features,
89
+ homepage=_HOMEPAGE,
90
+ license=_LICENSE,
91
+ citation=_CITATION,
92
+ )
93
+
94
+ def _split_generators(self, dl_manager):
95
+ ann_file = dl_manager.download(_URLS[0])
96
+ text_file = dl_manager.download(_URLS[1])
97
+ return [
98
+ datasets.SplitGenerator(
99
+ name=datasets.Split.TRAIN,
100
+ gen_kwargs={"filepaths": [ann_file, text_file], "split": "train",},
101
+ ),
102
+ ]
103
+
104
+ def _generate_examples(self, filepaths, split):
105
+ annotations = pd.read_csv(filepaths[0], dtype="object")
106
+ texts = pd.read_csv(filepaths[1], dtype="object")
107
+ annotations.fillna("", inplace=True)
108
+ texts.fillna("", inplace=True)
109
+ for _, row in texts.iterrows():
110
+ data_point = {}
111
+ data_point["extract_id"] = row["extract_id"]
112
+ data_point["target"] = row["target_compound_bolded"]
113
+ data_point["text"] = row["text"]
114
+ annotator_responses = annotations[
115
+ annotations["extract_id"] == row["extract_id"]
116
+ ]
117
+ resp_en_list = []
118
+ resp_nl_list = []
119
+ sugg_list = []
120
+ for _, ann_row in annotator_responses.iterrows():
121
+ ann_id = ann_row["anonymised_participant_id"]
122
+ response_dutch = ann_row["response"]
123
+ response_english = response_mapping[response_dutch]
124
+ suggestion = ann_row["suggestion"]
125
+ resp_en_list.append({"id": ann_id, "response": response_english})
126
+ resp_nl_list.append({"id": ann_id, "response": response_dutch})
127
+ sugg_list.append({"id": ann_id, "suggestion": suggestion})
128
+
129
+ data_point["annotator_responses_english"] = resp_en_list
130
+ data_point["annotator_responses_dutch"] = resp_nl_list
131
+ data_point["annotator_suggestions"] = sugg_list
132
+ yield data_point["extract_id"], data_point