Datasets:
Tasks:
Text Classification
Modalities:
Text
Sub-tasks:
fact-checking
Languages:
Danish
Size:
1K<n<10K
License:
File size: 6,871 Bytes
6dda140 |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 |
# coding=utf-8
# Copyright 2022 Leon Derczynski, HuggingFace Datasets Authors.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
# Lint as: python3
"""Danish Stance Dataset DAST"""
from collections import defaultdict
import glob
import json
import os
import sys
import datasets
logger = datasets.logging.get_logger(__name__)
_CITATION = """\
@inproceedings{lillie-etal-2019-joint,
title = "Joint Rumour Stance and Veracity Prediction",
author = "Lillie, Anders Edelbo and
Middelboe, Emil Refsgaard and
Derczynski, Leon",
booktitle = "Proceedings of the 22nd Nordic Conference on Computational Linguistics",
month = sep # "{--}" # oct,
year = "2019",
address = "Turku, Finland",
publisher = {Link{\"o}ping University Electronic Press},
url = "https://aclanthology.org/W19-6122",
pages = "208--221",
}
"""
_DESCRIPTION = """\
This dataset presents a series of stories on Reddit and the conversation around
them, annotated for stance. Stories are also annotated for veracity.
For more details see https://aclanthology.org/W19-6122/
"""
_URL = "dast.jsonl"
class DastConfig(datasets.BuilderConfig):
"""BuilderConfig for IPM NEL"""
def __init__(self, **kwargs):
"""BuilderConfig for IPM NEL.
Args:
**kwargs: keyword arguments forwarded to super.
"""
super(DastConfig, self).__init__(**kwargs)
class Dast(datasets.GeneratorBasedBuilder):
"""Dast dataset."""
BUILDER_CONFIGS = [
DastConfig(name="dkstance", version=datasets.Version("1.0.0"), description="Danish Stance"),
]
def _info(self):
return datasets.DatasetInfo(
description=_DESCRIPTION,
features=datasets.Features(
{
"id": datasets.Value("string"),
"native_id": datasets.Value("string"),
"text": datasets.Value("string"),
"parent_id": datasets.Value("string"),
"parent_text": datasets.Value("string"),
"parent_stance": datasets.features.ClassLabel(
names=[
"Supporting",
"Denying",
"Querying",
"Commenting",
]
),
"source_id": datasets.Value("string"),
"source_text": datasets.Value("string"),
"source_stance": datasets.features.ClassLabel(
names=[
"Supporting",
"Denying",
"Querying",
"Commenting",
]
),
}
),
supervised_keys=None,
homepage="https://aclanthology.org/W19-6122/",
citation=_CITATION,
)
def _split_generators(self, dl_manager):
"""Returns SplitGenerators."""
downloaded_file = dl_manager.download_and_extract(_URL)
print(downloaded_file)
data_files = {
"dast": downloaded_file,
}
return [
datasets.SplitGenerator(name=datasets.Split.TRAIN, gen_kwargs={"filepath": data_files['dast'], "split":"train"}),
datasets.SplitGenerator(name=datasets.Split.VALIDATION, gen_kwargs={"filepath": data_files['dast'], "split":"validation"}),
datasets.SplitGenerator(name=datasets.Split.TEST, gen_kwargs={"filepath": data_files['dast'], "split":"test"}),
]
def unpack(self, entry, parent_id = None, source_id = None):
if isinstance(entry, dict):
e = entry['comment']
original_id = e['comment_id']
text = e['text']
parent_id = e['parent_id']
parent_stance = e['SDQC_Parent']
source_id = e['submission_id']
source_stance = e['SDQC_Submission']
self.texts[original_id] = text
instance = {
"id":self.guid,
"native_id":original_id,
"text":text,
"parent_id":parent_id,
"parent_text":self.texts[parent_id],
"parent_stance":parent_stance,
"source_id":source_id,
"source_text":self.texts[source_id],
"source_stance":source_stance,
}
self.id_mapper[e['comment_id']] = self.guid
self.guid += 1
yield instance
elif isinstance(entry, list):
for sub_entry in entry:
yield from self.unpack(sub_entry, parent_id=parent_id, source_id=source_id)
def process_block(self, block):
j = json.loads(block)
s = j['redditSubmission']
descr = s['RumourDescription']
source_id = s['submission_id']
#print(i, '', descr, '', '', s['title'], s['SourceSDQC'])
self.id_mapper[source_id] = self.guid
self.guid += 1
self.texts[source_id] = s['title']
yield from self.unpack(j['branches'], source_id = 0, parent_id = 0)
def _generate_examples(self, filepath, split):
logger.info("⏳ Generating %s examples from = %s", (split, filepath))
def _deleted():
return "[deleted]"
self.guid = 0
self.id_mapper = {}
self.texts = defaultdict(_deleted)
partition_sources = ()
if split == 'train':
partition_sources = ('8sjevz', 'a0954m', 'a1gsmt', 'a2fpjr', 'a6o3us', 'ax70y5', 'axnshu', 'b23eat', 'b2xrgd', 'b72gok', 'b7aybw', 'b7ohqt', 'bb9iqt')
elif split == 'validation':
partition_sources = ('6v1ivh', '76y6rb', '7r9ouo', '8192oe', '83l9nm', '8agt1s', '8clb74', '8k6lcb')
elif split == 'test':
partition_sources = ('3qc12m', '3ud5z9', '53u5j7', '5emjyw', '5pfq1r', '5t1h6y', '60il0b', '67c2zf', '6jqtkm', '6nz7dy', '6szxwj', '6tm5kp')
with open(filepath, 'r', encoding="utf-8") as dastfile:
for line in dastfile:
instances = self.process_block(line.strip())
for instance in instances:
if instance['source_id'] in partition_sources:
yield instance['id'], instance |