"""Climate Evaluation: Datasets used in the ClimateGPT paper""" import os import datasets import csv import textwrap import json from pathlib import Path _CITATION = """ @misc{thulke2024climategpt, title={ClimateGPT: Towards AI Synthesizing Interdisciplinary Research on Climate Change}, author={David Thulke and Yingbo Gao and Petrus Pelser and Rein Brune and Rricha Jalota and Floris Fok and Michael Ramos and Ian van Wyk and Abdallah Nasir and Hayden Goldstein and Taylor Tragemann and Katie Nguyen and Ariana Fowler and Andrew Stanco and Jon Gabriel and Jordan Taylor and Dean Moro and Evgenii Tsymbalov and Juliette de Waal and Evgeny Matusov and Mudar Yaghi and Mohammad Shihadah and Hermann Ney and Christian Dugast and Jonathan Dotan and Daniel Erasmus}, year={2024}, eprint={2401.09646}, archivePrefix={arXiv}, primaryClass={cs.LG} } """ _DESCRIPTION = """\ Datasets for Climate Evaluation. """ _HOMEPAGE = "https://arxiv.org/abs/2401.09646" _URL = "https://huggingface.co/datasets/eci-io/climate-evaluation/resolve/main/" _LICENSE = "" # _BASE_HF_URL = "https://huggingface.co/datasets/eci-io/climate-evaluation/resolve/main" #Path("./") # _BASE_HF_URL = Path("./") # print(f"_BASE_HF_URL: {_BASE_HF_URL}") _ClimateEvaluation_BASE_KWARGS = dict( citation=_CITATION, url=_HOMEPAGE, ) # DEFAULT_CONFIG_NAME = "climate_stance" class ClimateEvaluationConfig(datasets.BuilderConfig): """BuilderConfig for ClimateEvaluation.""" def __init__( self, data_dir, citation, url=None, text_features=None, label_column=None, label_classes=None, process_label=lambda x: x, **kwargs, ): """BuilderConfig for ClimateGPT-Evaluation. Args: text_features: `dict[string, string]`, map from the name of the feature dict for each text field to the name of the column in the tsv file label_column: `string`, name of the column in the tsv file corresponding to the label data_dir: `string`, the path to the folder containing the tsv files in the downloaded zip citation: `string`, citation for the data set url: `string`, url for information about the data set label_classes: `list[string]`, the list of classes if the label is categorical. If not provided, then the label will be of type `datasets.Value('float32')`. process_label: `Function[string, any]`, function taking in the raw value of the label and processing it to the form required by the label feature **kwargs: keyword arguments forwarded to super. """ super(ClimateEvaluationConfig, self).__init__( version=datasets.Version("1.0.0", ""), **kwargs ) self.text_features = text_features self.label_column = label_column self.label_classes = label_classes self.data_dir = data_dir self.citation = citation self.url = url self.process_label = process_label class ClimateEvaluation(datasets.GeneratorBasedBuilder): """On ClimaBench, Pira 2.0 MCQs, Exeter datasets""" VERSION = datasets.Version("1.0.0") BUILDER_CONFIG_CLASS = ClimateEvaluationConfig BUILDER_CONFIGS = [ ClimateEvaluationConfig( name="climate_stance", description=textwrap.dedent( """\ Climate-Stance contains climate change-related tweets that were posted during the 2019 United Nations Framework Convention on Climate Change. The tweets have been manually categorized into three groups for the purpose of stance detection: those expressing support for climate change prevention, those opposing it, and those with an ambiguous stance.""" ), text_features={"text": "text"}, label_classes=[0, 1, 2], label_column="label", data_dir="ClimateStance", citation=textwrap.dedent( """\ @inproceedings{vaid-etal-2022-towards, title = "Towards Fine-grained Classification of Climate Change related Social Media Text", author = "Vaid, Roopal and Pant, Kartikey and Shrivastava, Manish", booktitle = "Proceedings of the 60th Annual Meeting of the Association for Computational Linguistics: Student Research Workshop", month = may, year = "2022", address = "Dublin, Ireland", publisher = "Association for Computational Linguistics", url = "https://aclanthology.org/2022.acl-srw.35", doi = "10.18653/v1/2022.acl-srw.35", pages = "434--443", abstract = "With climate change becoming a cause of concern worldwide, it becomes essential to gauge people{'}s reactions. This can help educate and spread awareness about it and help leaders improve decision-making. This work explores the fine-grained classification and Stance detection of climate change-related social media text. Firstly, we create two datasets, ClimateStance and ClimateEng, consisting of 3777 tweets each, posted during the 2019 United Nations Framework Convention on Climate Change and comprehensively outline the dataset collection, annotation methodology, and dataset composition. Secondly, we propose the task of Climate Change stance detection based on our proposed ClimateStance dataset. Thirdly, we propose a fine-grained classification based on the ClimateEng dataset, classifying social media text into five categories: Disaster, Ocean/Water, Agriculture/Forestry, Politics, and General. We benchmark both the datasets for climate change stance detection and fine-grained classification using state-of-the-art methods in text classification. We also create a Reddit-based dataset for both the tasks, ClimateReddit, consisting of 6262 pseudo-labeled comments along with 329 manually annotated comments for the label. We then perform semi-supervised experiments for both the tasks and benchmark their results using the best-performing model for the supervised experiments. Lastly, we provide insights into the ClimateStance and ClimateReddit using part-of-speech tagging and named-entity recognition.", } }""" ), url="https://github.com/roopalv54/finegrained-climate-change-social-media", ), ClimateEvaluationConfig( name="climate_eng", description=textwrap.dedent( """\ ClimateEng contains climate change-related tweets that were posted during the 2019 United Nations Framework Convention on Climate Change. The tweets have been manually categorized for the task of fine-grained classification into topics such as: Disaster, Ocean/Water, Agriculture/forestry, Politics, General. """ ), text_features={"text": "text"}, label_classes=["0", "1", "2", "3", "4"], label_column="label", data_dir="ClimateEng", citation=textwrap.dedent( """\ @inproceedings{vaid-etal-2022-towards, title = "Towards Fine-grained Classification of Climate Change related Social Media Text", author = "Vaid, Roopal and Pant, Kartikey and Shrivastava, Manish", booktitle = "Proceedings of the 60th Annual Meeting of the Association for Computational Linguistics: Student Research Workshop", month = may, year = "2022", address = "Dublin, Ireland", publisher = "Association for Computational Linguistics", url = "https://aclanthology.org/2022.acl-srw.35", doi = "10.18653/v1/2022.acl-srw.35", pages = "434--443", abstract = "With climate change becoming a cause of concern worldwide, it becomes essential to gauge people{'}s reactions. This can help educate and spread awareness about it and help leaders improve decision-making. This work explores the fine-grained classification and Stance detection of climate change-related social media text. Firstly, we create two datasets, ClimateStance and ClimateEng, consisting of 3777 tweets each, posted during the 2019 United Nations Framework Convention on Climate Change and comprehensively outline the dataset collection, annotation methodology, and dataset composition. Secondly, we propose the task of Climate Change stance detection based on our proposed ClimateStance dataset. Thirdly, we propose a fine-grained classification based on the ClimateEng dataset, classifying social media text into five categories: Disaster, Ocean/Water, Agriculture/Forestry, Politics, and General. We benchmark both the datasets for climate change stance detection and fine-grained classification using state-of-the-art methods in text classification. We also create a Reddit-based dataset for both the tasks, ClimateReddit, consisting of 6262 pseudo-labeled comments along with 329 manually annotated comments for the label. We then perform semi-supervised experiments for both the tasks and benchmark their results using the best-performing model for the supervised experiments. Lastly, we provide insights into the ClimateStance and ClimateReddit using part-of-speech tagging and named-entity recognition.", } }""" ), url="https://github.com/roopalv54/finegrained-climate-change-social-media", ), ClimateEvaluationConfig( name="climatext", description=textwrap.dedent( """\ ClimaText is a binary classification dataset containing sentences from the web, Wikipedia and the section of US public companies' 10-K reports that addresses climate-related risks. The dataset is employed for the task of predicting whether a given sentence is relevant to climate change or not. """ ), text_features={"text": "sentence"}, label_classes=["0", "1"], label_column="label", data_dir="ClimaText", citation=textwrap.dedent( """\ @misc{varini2021climatext, title={ClimaText: A Dataset for Climate Change Topic Detection}, author={Francesco S. Varini and Jordan Boyd-Graber and Massimiliano Ciaramita and Markus Leippold}, year={2021}, eprint={2012.00483}, archivePrefix={arXiv}, primaryClass={cs.CL} } }""" ), url="https://www.sustainablefinance.uzh.ch/en/research/climate-fever/climatext.html", ), ClimateEvaluationConfig( name="cdp_qa", description=textwrap.dedent( """\ CDP-QA is a dataset compiled from the questionnaires of the Carbon Disclosure Project, where cities, corporations, and states disclose their environmental information. The dataset presents pairs of questions and answers, and the objective is to predict whether a given answer is valid for the corresponding question. We benchmarked ClimateGPT on the questionnaires from the Combined split. """ ), data_dir="CDP/Combined", text_features={"question": "question", "answer": "answer"}, label_classes=["0", "1"], label_column="label", url="https://arxiv.org/abs/2301.04253", citation=textwrap.dedent( """\ @misc{laud2023Climabench, title={ClimaBench: A Benchmark Dataset For Climate Change Text Understanding in English}, author={Tanmay Laud and Daniel Spokoyny and Tom Corringham and Taylor Berg-Kirkpatrick}, year={2023}, eprint={2301.04253}, archivePrefix={arXiv}, primaryClass={cs.CL} } }""" ), ), ClimateEvaluationConfig( name="exeter", description=textwrap.dedent( """\ The Exeter Climate Claims dataset contains textual data from 33 influential climate contrarian blogs and the climate-change-related content from 20 conservative think tanks spanning the years 1998 to 2020. Annotation of the dataset was done manually using a thorough three-layer taxonomy of (climate-change related) contrarian claims, which was developed by the authors. We utilize this dataset specifically for the binary classification task of discerning whether a given text contains a contrarian claim pertaining to climate change or not.  """ ), data_dir="exeter", text_features={"text": "text"}, label_classes=["0", "1"], label_column="label", url="https://www.nature.com/articles/s41598-021-01714-4", citation=textwrap.dedent( """\ @article{coan2021computer, title={Computer-assisted classification of contrarian claims about climate change}, author={Coan, Travis G and Boussalis, Constantine and Cook, John and Nanko, Mirjam O}, journal={Scientific reports}, volume={11}, number={1}, pages={22320}, year={2021}, publisher={Nature Publishing Group UK London} } }""" ), ), ClimateEvaluationConfig( name="translated_exams", description=textwrap.dedent( """\ EXAMS is a multiple choice question answering collected from high school examinations. To evaluate ClimateGPT on the cascaded machine translation approach, we evaluate on the English translation of the Arabic subset of this dataset. The Arabic subset covers questions from biology, physics, science, social science and Islamic studies. """ ), data_dir="exams/translated", text_features={"subject": "subject", "question_stem": "question_stem", "choices": "choices"}, label_classes=["A", "B", "C", "D"], label_column="answerKey", url="https://arxiv.org/abs/2301.04253", citation=textwrap.dedent( """\ @inproceedings{hardalov-etal-2020-exams, title = "{EXAMS}: A Multi-subject High School Examinations Dataset for Cross-lingual and Multilingual Question Answering", author = "Hardalov, Momchil and Mihaylov, Todor and Zlatkova, Dimitrina and Dinkov, Yoan and Koychev, Ivan and Nakov, Preslav", editor = "Webber, Bonnie and Cohn, Trevor and He, Yulan and Liu, Yang", booktitle = "Proceedings of the 2020 Conference on Empirical Methods in Natural Language Processing (EMNLP)", month = nov, year = "2020", address = "Online", publisher = "Association for Computational Linguistics", url = "https://aclanthology.org/2020.emnlp-main.438", doi = "10.18653/v1/2020.emnlp-main.438", pages = "5427--5444", } }""" ), ), ClimateEvaluationConfig( name="exams", description=textwrap.dedent( """\ EXAMS is a multiple choice question answering collected from high school examinations. To evaluate ClimateGPT on the cascaded machine translation approach, we evaluate on the Arabic subset of this dataset. The Arabic subset covers questions from biology, physics, science, social science and Islamic studies. Note, this dataset is in arabic. """ ), data_dir="exams", text_features={"subject": "subject", "question_stem": "question_stem", "choices": "choices"}, label_classes=["A", "B", "C", "D"], label_column="answerKey", url="https://arxiv.org/abs/2301.04253", citation=textwrap.dedent( """\ @inproceedings{hardalov-etal-2020-exams, title = "{EXAMS}: A Multi-subject High School Examinations Dataset for Cross-lingual and Multilingual Question Answering", author = "Hardalov, Momchil and Mihaylov, Todor and Zlatkova, Dimitrina and Dinkov, Yoan and Koychev, Ivan and Nakov, Preslav", editor = "Webber, Bonnie and Cohn, Trevor and He, Yulan and Liu, Yang", booktitle = "Proceedings of the 2020 Conference on Empirical Methods in Natural Language Processing (EMNLP)", month = nov, year = "2020", address = "Online", publisher = "Association for Computational Linguistics", url = "https://aclanthology.org/2020.emnlp-main.438", doi = "10.18653/v1/2020.emnlp-main.438", pages = "5427--5444", } }""" ), ), ] def _info(self): if self.config.name == "exams" or self.config.name == "translated_exams": features = datasets.Features( { "subject": datasets.Value("string"), "question_stem": datasets.Value("string"), "choices": datasets.Value("string"), "answerKey": datasets.ClassLabel( names=["A", "B", "C", "D"] ), } ) features["idx"] = datasets.Value("int32") else: if self.config.name == "cdp_qa": #print(f"self.config.text_features: {self.config.text_features.keys()}") features = { text_feature: datasets.Value("string") for text_feature in self.config.text_features.keys() } # features["category"] = datasets.Value("string") else: features = { text_feature: datasets.Value("string") for text_feature in self.config.text_features.keys() } if self.config.label_classes: features["label"] = datasets.features.ClassLabel( names=self.config.label_classes ) else: features["label"] = datasets.Value("float32") features["idx"] = datasets.Value("int32") return datasets.DatasetInfo( description=_DESCRIPTION, features=datasets.Features(features), homepage=self.config.url, citation=self.config.citation + "\n" + _CITATION, ) def _split_generators(self, dl_manager): data_dir = self.config.data_dir # urls_to_download = _URL # print(f"self.config.data_dir: {self.config.data_dir}") if self.config.name == "exams" or self.config.name == "translated_exams": # urls_to_download={ # "test": _BASE_HF_URL / data_dir / f"test.csv" # } urls_to_download={ "test": _URL + os.path.join(data_dir or "", "test.csv"), } downloaded_files = dl_manager.download_and_extract(urls_to_download) return [ datasets.SplitGenerator( name=datasets.Split.TEST, gen_kwargs={ "data_file": downloaded_files["test"], #os.path.join(data_dir or "", "test.csv"), "split": "test", }, ), ] if self.config.name == "exeter": # urls_to_download={ # "train": _BASE_HF_URL / data_dir / f"training.csv", # "valid": _BASE_HF_URL / data_dir / f"validation.csv", # "test": _BASE_HF_URL / data_dir / f"test.csv" # } urls_to_download={ "train": _URL + os.path.join(data_dir or "", "training.csv"), "valid": _URL + os.path.join(data_dir or "", "validation.csv"), "test": _URL + os.path.join(data_dir or "", "test.csv"), } downloaded_files = dl_manager.download_and_extract(urls_to_download) return [ datasets.SplitGenerator( name=datasets.Split.TRAIN, gen_kwargs={ "data_file": downloaded_files["train"], "split": "train", }, ), datasets.SplitGenerator( name=datasets.Split.VALIDATION, gen_kwargs={ "data_file": downloaded_files["valid"], "split": "valid", }, ), datasets.SplitGenerator( name=datasets.Split.TEST, gen_kwargs={ "data_file": downloaded_files["test"], "split": "test", }, ), ] if self.config.name == "climatext": files = { "train": [ "train-data/AL-10Ks.tsv : 3000 (58 positives, 2942 negatives) (TSV, 127138 KB).tsv", "train-data/AL-Wiki (train).tsv", ], "valid": ["dev-data/Wikipedia (dev).tsv"], "test": [ "test-data/Claims (test).tsv", "test-data/Wikipedia (test).tsv", "test-data/10-Ks (2018, test).tsv", ], } # os.path.join(data_dir or "", f) # urls_to_download={ # "train": [_BASE_HF_URL / data_dir / f for f in files["train"]], # "valid": [_BASE_HF_URL / data_dir / f for f in files["valid"]], # "test": [_BASE_HF_URL / data_dir / f for f in files["test"]], # } urls_to_download={ "train": [_URL + os.path.join(data_dir or "", f) for f in files["train"]], "valid": [_URL + os.path.join(data_dir or "", f) for f in files["valid"]], "test": [_URL + os.path.join(data_dir or "", f) for f in files["test"]], } downloaded_files = dl_manager.download_and_extract(urls_to_download) return [ datasets.SplitGenerator( name=datasets.Split.TRAIN, gen_kwargs={ "data_file": downloaded_files["train"], # [ # os.path.join(data_dir or "", f) for f in files["train"] # ], "split": "train", }, ), datasets.SplitGenerator( name=datasets.Split.VALIDATION, gen_kwargs={ "data_file": downloaded_files["valid"], "split": "valid", }, ), datasets.SplitGenerator( name=datasets.Split.TEST, gen_kwargs={ "data_file": downloaded_files["test"], "split": "test", }, ), ] if self.config.name == "cdp_qa": # categories = { # "cities": "Cities/Cities Responses", # "states": "States", # "corporations": "Corporations/Corporations Responses/Climate Change", # "combined": "Combined", # } # urls_to_download={ # "train": _BASE_HF_URL / data_dir / f"train_qa.csv", # "valid": _BASE_HF_URL / data_dir / f"val_qa.csv", # "test": _BASE_HF_URL / data_dir / f"test_qa.csv" # } urls_to_download={ "train": _URL + os.path.join(data_dir or "", "train_qa.csv"), "valid": _URL + os.path.join(data_dir or "", "val_qa.csv"), "test": _URL + os.path.join(data_dir or "", "test_qa.csv"), } downloaded_files = dl_manager.download_and_extract(urls_to_download) #print(f"downloaded_files: {downloaded_files['train']}") return [ datasets.SplitGenerator( name=datasets.Split.TRAIN, gen_kwargs={ "data_file": downloaded_files["train"], # "data_file": [ # (k, os.path.join(data_dir or "", v, "train_qa.csv")) # for k, v in categories.items() # ], "split": "train", }, ), datasets.SplitGenerator( name=datasets.Split.VALIDATION, gen_kwargs={ "data_file": downloaded_files["valid"], # [ # (k, os.path.join(data_dir or "", v, "val_qa.csv")) # for k, v in categories.items() # ], "split": "valid", }, ), datasets.SplitGenerator( name=datasets.Split.TEST, gen_kwargs={ "data_file": downloaded_files["test"], # [ # (k, os.path.join(data_dir or "", v, "test_qa.csv")) # for k, v in categories.items() # ], "split": "test", }, ), ] # urls_to_download={ # "train": _BASE_HF_URL / data_dir / f"train.csv", #os.path.join(data_dir or "", "train.csv"), # "valid": _BASE_HF_URL / data_dir / f"val.csv", #+ os.path.join(data_dir or "", "val.csv"), # "test": _BASE_HF_URL / data_dir / f"test.csv", #+ os.path.join(data_dir or "", "test.csv") # } urls_to_download={ "train": _URL + os.path.join(data_dir or "", "train.csv"), "valid": _URL + os.path.join(data_dir or "", "val.csv"), "test": _URL + os.path.join(data_dir or "", "test.csv") } # print(f"urls_to_download['train']: {urls_to_download['train']}") # print(f"urls_to_download['valid']: {urls_to_download['valid']}") downloaded_files = dl_manager.download_and_extract(urls_to_download) return [ datasets.SplitGenerator( name=datasets.Split.TRAIN, gen_kwargs={ "data_file": downloaded_files["train"], "split": "train", }, ), datasets.SplitGenerator( name=datasets.Split.VALIDATION, gen_kwargs={ "data_file": downloaded_files["valid"], "split": "valid", }, ), datasets.SplitGenerator( name=datasets.Split.TEST, gen_kwargs={ "data_file": downloaded_files["test"], "split": "test", }, ), ] def _generate_examples(self, data_file, split): if self.config.name == "climatext": idx = iter(range(100000)) for file in data_file: yield from self._process_file(file, delimiter="\t", idx=idx) # elif self.config.name == "cdp_qa": # idx = iter(range(10000000)) # print(f"!!!data_file: {data_file}") # for file in data_file: # yield from self._process_file(data_file) else: yield from self._process_file(data_file) def _process_file(self, data_file, delimiter=",", idx=None, category=None): # print(f"data_file: {data_file}") with open(data_file, encoding="utf8") as f: process_label = self.config.process_label label_classes = self.config.label_classes # print(f"self.config.text_features: {self.config.text_features}") # data = f.read() # print(f"data: {data}") reader = csv.DictReader(f, delimiter=delimiter, quoting=csv.QUOTE_ALL) # print(f"reader: {reader}") for n, row in enumerate(reader): # print(f"row: {row}") example = { feat: row[col] for feat, col in self.config.text_features.items() } if idx: example["idx"] = next(idx) else: example["idx"] = n # if category: # example["category"] = category if self.config.label_column in row: # print(f"self.config.label_column: {self.config.label_column}") label = row[self.config.label_column] if self.config.name in ["exams", "translated_exams"]: example["answerKey"] = process_label(label) else: if label_classes and label not in label_classes: label = int(label) if label else None example["label"] = process_label(label) else: example["label"] = process_label(-1) # Filter out corrupted rows. for value in example.values(): if value is None: break else: yield example["idx"], example