# coding=utf-8 # Copyright 2020 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 """Introduction to the CoNLL-2003 Shared Task: Language-Independent Named Entity Recognition""" import json import os import datasets logger = datasets.logging.get_logger(__name__) _CITATION = """\ @inproceedings{dlamini_zulu_stance, title={Bridging the Domain Gap for Stance Detection for the Zulu language}, author={Dlamini, Gcinizwe and Bekkouch, Imad Eddine Ibrahim and Khan, Adil and Derczynski, Leon}, booktitle={Proceedings of IEEE IntelliSys}, year={2022} } """ _DESCRIPTION = """\ This is a stance detection dataset in the Zulu language. The data is translated to Zulu by Zulu native speakers, from English source texts. Misinformation has become a major concern in recent last years given its spread across our information sources. In the past years, many NLP tasks have been introduced in this area, with some systems reaching good results on English language datasets. Existing AI based approaches for fighting misinformation in literature suggest automatic stance detection as an integral first step to success. Our paper aims at utilizing this progress made for English to transfers that knowledge into other languages, which is a non-trivial task due to the domain gap between English and the target languages. We propose a black-box non-intrusive method that utilizes techniques from Domain Adaptation to reduce the domain gap, without requiring any human expertise in the target language, by leveraging low-quality data in both a supervised and unsupervised manner. This allows us to rapidly achieve similar results for stance detection for the Zulu language, the target language in this work, as are found for English. We also provide a stance detection dataset in the Zulu language. """ _URL = "ZUstance.json" class ZuluStanceConfig(datasets.BuilderConfig): """BuilderConfig for ZuluStance""" def __init__(self, **kwargs): """BuilderConfig ZuluStance. Args: **kwargs: keyword arguments forwarded to super. """ super(ZuluStanceConfig, self).__init__(**kwargs) class ZuluStance(datasets.GeneratorBasedBuilder): """ZuluStance dataset.""" BUILDER_CONFIGS = [ ZuluStanceConfig(name="zulu-stance", version=datasets.Version("1.0.0"), description="Stance dataset in Zulu"), ] def _info(self): return datasets.DatasetInfo( description=_DESCRIPTION, features=datasets.Features( { "id": datasets.Value("string"), "text": datasets.Value("string"), "target": datasets.Value("string"), "stance": datasets.features.ClassLabel( names=[ "FAVOR", "AGAINST", "NONE", ] ) } ), supervised_keys=None, homepage="https://arxiv.org/abs/2205.03153", citation=_CITATION, ) def _split_generators(self, dl_manager): """Returns SplitGenerators.""" downloaded_file = dl_manager.download_and_extract(_URL) return [ datasets.SplitGenerator(name=datasets.Split.TRAIN, gen_kwargs={"filepath": downloaded_file}), ] def _generate_examples(self, filepath): logger.info("⏳ Generating examples from = %s", filepath) with open(filepath, encoding="utf-8") as f: guid = 0 zustance_dataset = json.load(f) for instance in zustance_dataset: instance["id"] = str(guid) instance["text"] = instance.pop("Tweet") instance["target"] = instance.pop("Target") instance["stance"] = instance.pop("Stance") yield guid, instance guid += 1