Touche23-ValueEval / Touche23-ValueEval.py
gate-tec's picture
Switch to loading script
f9233bd
raw
history blame
32.6 kB
# Copyright 2023 The Touché23-ValueEval Datasets Authors and the current dataset script contributor.
#
# Licensed under the Creative Commons Attribution 4.0 International (CC BY 4.0) (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# https://creativecommons.org/licenses/by/4.0/legalcode
"""The Touch\u00E923-ValueEval Dataset"""
import json
import pandas as pd
import os
import sys
import subprocess
import datasets
_DESCRIPTION = """\
Dataset for Touch\u00E9 / SemEval 2023 Task 4; ValueEval: Identification of Human Values behind Arguments:
https://www.overleaf.com/6679855346wrdckzkdccxg
Based on the original Webis-ArgValues-22 (https://doi.org/10.5281/zenodo.5657249) dataset accompanying the paper
Identifying the Human Values behind Arguments (Kiesel et al. 2022b; https://webis.de/publications.html#kiesel_2022b),
published at ACL'22.
"""
_CITATION = """\
@Article{mirzakhmedova:2023a,
author = {Nailia Mirzakhmedova and Johannes Kiesel and Milad Alshomary and Maximilian Heinrich and Nicolas Handke\
and Xiaoni Cai and Valentin Barriere and Doratossadat Dastgheib and Omid Ghahroodi and {Mohammad Ali} Sadraei\
and Ehsaneddin Asgari and Lea Kawaletz and Henning Wachsmuth and Benno Stein},
doi = {10.48550/arXiv.2301.13771},
journal = {CoRR},
month = jan,
publisher = {arXiv},
title = {{The Touch{\'e}23-ValueEval Dataset for Identifying Human Values behind Arguments}},
volume = {abs/2301.13771},
year = 2023
}"""
_ARGUMENT_DATASET_DESCRIPTION = """\
Each row corresponds to an argument consisting of it's unique identifier (Argument ID) and the arguments content being
its Premise, Stance, and Conclusion.
"""
_LEVEL1_DESCRIPTION = _ARGUMENT_DATASET_DESCRIPTION + """\
The Labels for each example is an array of 1s (argument resorts to value) and 0s (argument does not resort to value).
The 54 human values from the level 1 of the value taxonomy (Kiesel et al. 2022b) are not used for the 2023 task
(except for the annotation), but are still listed here for some might find them useful for understanding the value
categories. Their order is the same as in the original files. For more details see the 'value-categories' configuration."""
_LEVEL2_DESCRIPTION = _ARGUMENT_DATASET_DESCRIPTION + """\
The Labels for each example is an array of 1s (argument resorts to value) and 0s (argument does not resort to value).
The order of the 20 value categories from the level 2 of the value taxonomy (Kiesel et al. 2022b)
is the same as in the original files. For more details see the 'value-categories' configuration."""
_IBM_DESCRIPTION = """\
The 7368 arguments from the IBM-ArgQ-Rank-30kArgs corpus (Gretz et al., 2020):
https://research.ibm.com/haifa/dept/vst/debating_data.shtml#Argument%20Quality"""
_IBM_META_DESCRIPTION = """\
Each entry corresponds to one argument (IDs starting with A) containing the data on argument quality for the respective
argument taken from the IBM-ArgQ-Rank-30kArgs corpus."""
_ZHIHU_DESCRIPTION = """\
Supplementary set of 100 arguments from the recommendation and hotlist section of the Chinese question-answering website Zhihu:
https://www.zhihu.com/explore
which teams can use for training or validating more robust approaches; these have been part of the original\
Webis-ArgValues-22 dataset."""
_ZHIHU_META_DESCRIPTION = """\
Each entry corresponds to one argument (IDs starting with C) reporting the original chinese conclusion and premise
as well as the link to the original statement the argument was taken from."""
_GROUP_DISCUSSION_IDEAS_DESCRIPTION = """\
A set of 399 arguments from the Group Discussion Ideas (GD IDEAS) web page:
https://www.groupdiscussionideas.com/"""
_GROUP_DISCUSSION_IDEAS_META_DESCRIPTION = """\
Each entry corresponds to one argument (IDs starting with D) reporting the link to the topic the argument was taken from."""
_COFE_DESCRIPTION = """\
A set of 1098 arguments from the Conference on the Future of Europe portal:
https://futureu.europa.eu/
The arguments were sampled from an existing dataset (Barriere et al., 2022)."""
_COFE_META_DESCRIPTION = """\
Each entry corresponds to one argument (IDs starting with E) reporting the link to the comment the argument was taken from."""
_NAHJALBALAGHA_DESCRIPTION = """\
Arguments from and based on the Nahj al-Balagha.
This data was contributed by the language.ml lab (Doratossadat, Omid, Mohammad, Ehsaneddin):
https://language.ml/"""
_NAHJALBALAGHA_META_DESCRIPTION = """\
Each entry corresponds to one argument (IDs starting with F) containing information on the 279 arguments in the dataset
(configuration: 'nahjalbalagha') and 1047 additional arguments that were not labeled so far."""
_NYT_DESCRIPTION = """\
Supplementary set of 80 arguments from 12 news articles of The New York Times
https://www.nytimes.com/
that were published between July 2020 and May 2021 and contain at least one of these keywords:
coronavirus (2019-ncov), vaccination and immunization, and epidemics."""
_NYT_META_DESCRIPTION = """\
Each entry corresponds to one argument (IDs starting with G) reporting the link to the article the argument was taken
from and the timestamp of the article's version in the Internet Archive that was used."""
_CATEGORIES_JSON_DESCRIPTION = """\
The single JSON entry in value-categories describes the 20 value categories (level 2 of the taxonomy) of this task
through examples. Each category maps to a dictionary of its contained level 1 values with a given list of exemplary phrases.
The level 1 values are not used for the 2023 task (except for the annotation), but are still listed here for some might
find them useful for understanding the value categories."""
_IBM_CITATION = """\
@inproceedings{gretz:2020,
author = {Shai Gretz and Roni Friedman and Edo Cohen{-}Karlik and Assaf Toledo and Dan Lahav and Ranit Aharonov and Noam Slonim},
title = {A Large-Scale Dataset for Argument Quality Ranking: Construction and Analysis},
booktitle = {34th {AAAI} Conference on Artificial Intelligence ({AAAI} 2020)},
pages = {7805-7813},
publisher = {{AAAI} Press},
year = {2020},
doi = {10.1609/aaai.v34i05.6285},
url = {https://aaai.org/ojs/index.php/AAAI/article/view/6285}
}"""
_COFE_CITATION = """\
@inproceedings{barriere-etal-2022-cofe,
title = "{C}o{FE}: A New Dataset of Intra-Multilingual Multi-target Stance Classification from an Online {E}uropean Participatory Democracy Platform",
author = "Barriere, Valentin and Jacquet, Guillaume Guillaume and Hemamou, Leo",
booktitle = "Proceedings of the 2nd Conference of the Asia-Pacific Chapter of the Association for Computational Linguistics and the 12th International Joint Conference on Natural Language Processing (Volume 2: Short Papers)",
month = nov,
year = "2022",
address = "Online only",
publisher = "Association for Computational Linguistics",
url = "https://aclanthology.org/2022.aacl-short.52",
pages = "418--422"
}"""
_HOMEPAGE = "https://webis.de/data/touche23-valueeval.html"
_LICENSE = "https://creativecommons.org/licenses/by/4.0/legalcode"
######################################
# START OF: Additional variables #####
######################################
_SPLIT_META = datasets.Split('meta')
_CONFIG_NAME_MAIN, _CONFIG_NAME_NAHJALBALAGHA, _CONFIG_NAME_ZHIHU = "main", "nahjalbalagha", "zhihu"
_CONFIG_NAME_MAIN_LEVEL1, _CONFIG_NAME_NAHJALBALAGHA_LEVEL1, _CONFIG_NAME_ZHIHU_LEVEL1 = "main-level1", "nahjalbalagha-level1", "zhihu-level1"
_CONFIG_NAME_NYT, _CONFIG_NAME_NYT_LEVEL1 = "nyt", "nyt-level1"
_CONFIG_NAME_META_A, _CONFIG_NAME_META_D, _CONFIG_NAME_META_E = "ibm-meta", "gdi-meta", "cofe-meta"
_CONFIG_NAME_META_C, _CONFIG_NAME_META_F, _CONFIG_NAME_META_G = "zhihu-meta", "nahjalbalagha-meta", "nyt-meta"
_CONFIG_NAME_VALUE_CATEGORIES = "value-categories"
_SPLIT_TYPE_TRAIN, _SPLIT_TYPE_VAL, _SPLIT_TYPE_TEST = "training", "validation", "test"
_SPLIT_TYPE_META = "meta"
_FILE_TYPE_ARGUMENTS, _FILE_TYPE_LABELS = "arguments", "labels"
_FILE_TYPE_META, _FILE_TYPE_JSON = "meta", "json"
_FILE_TYPE_DOWNLOADER = "downloader"
####################################
# END OF: Additional variables #####
####################################
###########################
# START OF: Data URLs #####
###########################
_ZENODO_LINK = "https://zenodo.org/record/7879430/files/"
_URL = os.environ.get('TIRA_INPUT_DIRECTORY', _ZENODO_LINK)
_NYT_DOWNLOADER_URL = "https://raw.githubusercontent.com/touche-webis-de/touche-code/main/semeval23/human-value-detection/nyt-downloader/"
_NYT_ARGUMENTS_FILE_LOCAL = "webis_touche23-valueeval_arguments-test-nyt.tsv"
_NYT_ARGUMENTS_FILE_ON_TIRA = "arguments-test-nyt.tsv"
_URLS = {
_CONFIG_NAME_MAIN: {
_SPLIT_TYPE_TRAIN: {
_FILE_TYPE_ARGUMENTS: _URL + "arguments-training.tsv",
_FILE_TYPE_LABELS: _URL + "labels-training.tsv"
},
_SPLIT_TYPE_VAL: {
_FILE_TYPE_ARGUMENTS: _URL + "arguments-validation.tsv",
_FILE_TYPE_LABELS: _URL + "labels-validation.tsv"
},
_SPLIT_TYPE_TEST: {
_FILE_TYPE_ARGUMENTS: _URL + "arguments-test.tsv",
_FILE_TYPE_LABELS: _URL + "labels-test.tsv"
}
},
_CONFIG_NAME_MAIN_LEVEL1: {
_SPLIT_TYPE_TRAIN: {
_FILE_TYPE_ARGUMENTS: _URL + "arguments-training.tsv",
_FILE_TYPE_LABELS: _URL + "level1-labels-training.tsv"
},
_SPLIT_TYPE_VAL: {
_FILE_TYPE_ARGUMENTS: _URL + "arguments-validation.tsv",
_FILE_TYPE_LABELS: _URL + "level1-labels-validation.tsv"
},
_SPLIT_TYPE_TEST: {
_FILE_TYPE_ARGUMENTS: _URL + "arguments-test.tsv",
_FILE_TYPE_LABELS: _URL + "level1-labels-test.tsv"
}
},
_CONFIG_NAME_NAHJALBALAGHA: {
_SPLIT_TYPE_TEST: {
_FILE_TYPE_ARGUMENTS: _URL + "arguments-test-nahjalbalagha.tsv",
_FILE_TYPE_LABELS: _URL + "labels-test-nahjalbalagha.tsv"
}
},
_CONFIG_NAME_NAHJALBALAGHA_LEVEL1: {
_SPLIT_TYPE_TEST: {
_FILE_TYPE_ARGUMENTS: _URL + "arguments-test-nahjalbalagha.tsv",
_FILE_TYPE_LABELS: _URL + "level1-labels-test-nahjalbalagha.tsv"
}
},
_CONFIG_NAME_NYT: {
_SPLIT_TYPE_TEST: {
_FILE_TYPE_LABELS: _URL + "labels-test-nyt.tsv"
}
},
_CONFIG_NAME_NYT_LEVEL1: {
_SPLIT_TYPE_TEST: {
_FILE_TYPE_LABELS: _URL + "level1-labels-test-nyt.tsv"
}
},
_CONFIG_NAME_ZHIHU: {
_SPLIT_TYPE_VAL: {
_FILE_TYPE_ARGUMENTS: _URL + "arguments-validation-zhihu.tsv",
_FILE_TYPE_LABELS: _URL + "labels-validation-zhihu.tsv"
}
},
_CONFIG_NAME_ZHIHU_LEVEL1: {
_SPLIT_TYPE_VAL: {
_FILE_TYPE_ARGUMENTS: _URL + "arguments-validation-zhihu.tsv",
_FILE_TYPE_LABELS: _URL + "level1-labels-validation-zhihu.tsv"
}
},
_CONFIG_NAME_META_A: {
_SPLIT_TYPE_META: {
_FILE_TYPE_META: _URL + "meta-arguments-a.tsv"
}
},
_CONFIG_NAME_META_D: {
_SPLIT_TYPE_META: {
_FILE_TYPE_META: _URL + "meta-arguments-d.tsv"
}
},
_CONFIG_NAME_META_E: {
_SPLIT_TYPE_META: {
_FILE_TYPE_META: _URL + "meta-arguments-e.tsv"
}
},
_CONFIG_NAME_META_C: {
_SPLIT_TYPE_META: {
_FILE_TYPE_META: _URL + "meta-arguments-c.tsv"
}
},
_CONFIG_NAME_META_F: {
_SPLIT_TYPE_META: {
_FILE_TYPE_META: _URL + "meta-arguments-f.tsv"
}
},
_CONFIG_NAME_META_G: {
_SPLIT_TYPE_META: {
_FILE_TYPE_META: _URL + "meta-arguments-g.tsv"
}
},
_CONFIG_NAME_VALUE_CATEGORIES: {
_SPLIT_TYPE_META: {
_FILE_TYPE_JSON: _URL + "value-categories.json"
}
}
}
_NYT_DOWNLOADER_FILES = {
"requirements": _NYT_DOWNLOADER_URL + "requirements.txt",
"downloader": _NYT_DOWNLOADER_URL + "nyt-downloader.py",
"input-file": _NYT_DOWNLOADER_URL + "nyt01-spans.tsv",
"checksum": _NYT_DOWNLOADER_URL + "arguments-test-nyt.sha256"
}
if _URL != _ZENODO_LINK:
# running on TIRA
_URLS[_CONFIG_NAME_NYT][_SPLIT_TYPE_TEST][_FILE_TYPE_ARGUMENTS] = _URL + _NYT_ARGUMENTS_FILE_ON_TIRA
_URLS[_CONFIG_NAME_NYT_LEVEL1][_SPLIT_TYPE_TEST][_FILE_TYPE_ARGUMENTS] = _URL + _NYT_ARGUMENTS_FILE_ON_TIRA
else:
# running locally
_URLS[_CONFIG_NAME_NYT][_SPLIT_TYPE_TEST][_FILE_TYPE_DOWNLOADER] = _NYT_DOWNLOADER_FILES
_URLS[_CONFIG_NAME_NYT_LEVEL1][_SPLIT_TYPE_TEST][_FILE_TYPE_DOWNLOADER] = _NYT_DOWNLOADER_FILES
#########################
# END OF: Data URLs #####
#########################
##########################
# START OF: Features #####
##########################
_FEATURES_ARGUMENT_SETS = datasets.Features(
{
"Argument ID": datasets.Value("string"),
"Conclusion": datasets.Value("string"),
"Stance": datasets.Value("string"),
"Premise": datasets.Value("string"),
"Labels": datasets.Sequence(feature=datasets.Value("int32"))
}
)
_FEATURES_META_SETS = {
_CONFIG_NAME_META_A: datasets.Features(
{
"Argument ID": datasets.Value("string"),
"WA": datasets.Value("float64"),
"MACE-P": datasets.Value("float64"),
"stance_WA": datasets.Value("int32"),
"stance_WA_conf": datasets.Value("float64")
}
),
_CONFIG_NAME_META_D: datasets.Features(
{
"Argument ID": datasets.Value("string"),
"URL": datasets.Value("string")
}
),
_CONFIG_NAME_META_E: datasets.Features(
{
"Argument ID": datasets.Value("string"),
"URL": datasets.Value("string")
}
),
_CONFIG_NAME_META_C: datasets.Features(
{
"Argument ID": datasets.Value("string"),
"Conclusion Chinese": datasets.Value("string"),
"Premise Chinese": datasets.Value("string"),
"URL": datasets.Value("string")
}
),
_CONFIG_NAME_META_F: datasets.Features(
{
"Argument ID": datasets.Value("string"),
"Conclusion Farsi": datasets.Value("string"),
"Stance Farsi": datasets.Value("string"),
"Premise Farsi": datasets.Value("string"),
"Conclusion English": datasets.Value("string"),
"Stance English": datasets.Value("string"),
"Premise English": datasets.Value("string"),
"Source": datasets.Value("string"),
"Method": datasets.Value("string")
}
),
_CONFIG_NAME_META_G: datasets.Features(
{
"Argument ID": datasets.Value("string"),
"URL": datasets.Value("string"),
"Internet Archive timestamp": datasets.Value("string")
}
),
_CONFIG_NAME_VALUE_CATEGORIES: datasets.Features(
{
"Self-direction: thought": {
"Be creative": datasets.Sequence(feature=datasets.Value("string")),
"Be curious": datasets.Sequence(feature=datasets.Value("string")),
"Have freedom of thought": datasets.Sequence(feature=datasets.Value("string"))
},
"Self-direction: action": {
"Be choosing own goals": datasets.Sequence(feature=datasets.Value("string")),
"Be independent": datasets.Sequence(feature=datasets.Value("string")),
"Have freedom of action": datasets.Sequence(feature=datasets.Value("string")),
"Have privacy": datasets.Sequence(feature=datasets.Value("string"))
},
"Stimulation": {
"Have an exciting life": datasets.Sequence(feature=datasets.Value("string")),
"Have a varied life": datasets.Sequence(feature=datasets.Value("string")),
"Be daring": datasets.Sequence(feature=datasets.Value("string"))
},
"Hedonism": {
"Have pleasure": datasets.Sequence(feature=datasets.Value("string"))
},
"Achievement": {
"Be ambitious": datasets.Sequence(feature=datasets.Value("string")),
"Have success": datasets.Sequence(feature=datasets.Value("string")),
"Be capable": datasets.Sequence(feature=datasets.Value("string")),
"Be intellectual": datasets.Sequence(feature=datasets.Value("string")),
"Be courageous": datasets.Sequence(feature=datasets.Value("string"))
},
"Power: dominance": {
"Have influence": datasets.Sequence(feature=datasets.Value("string")),
"Have the right to command": datasets.Sequence(feature=datasets.Value("string"))
},
"Power: resources": {
"Have wealth": datasets.Sequence(feature=datasets.Value("string"))
},
"Face": {
"Have social recognition": datasets.Sequence(feature=datasets.Value("string")),
"Have a good reputation": datasets.Sequence(feature=datasets.Value("string"))
},
"Security: personal": {
"Have a sense of belonging": datasets.Sequence(feature=datasets.Value("string")),
"Have good health": datasets.Sequence(feature=datasets.Value("string")),
"Have no debts": datasets.Sequence(feature=datasets.Value("string")),
"Be neat and tidy": datasets.Sequence(feature=datasets.Value("string")),
"Have a comfortable life": datasets.Sequence(feature=datasets.Value("string"))
},
"Security: societal": {
"Have a safe country": datasets.Sequence(feature=datasets.Value("string")),
"Have a stable society": datasets.Sequence(feature=datasets.Value("string"))
},
"Tradition": {
"Be respecting traditions": datasets.Sequence(feature=datasets.Value("string")),
"Be holding religious faith": datasets.Sequence(feature=datasets.Value("string"))
},
"Conformity: rules": {
"Be compliant": datasets.Sequence(feature=datasets.Value("string")),
"Be self-disciplined": datasets.Sequence(feature=datasets.Value("string")),
"Be behaving properly": datasets.Sequence(feature=datasets.Value("string"))
},
"Conformity: interpersonal": {
"Be polite": datasets.Sequence(feature=datasets.Value("string")),
"Be honoring elders": datasets.Sequence(feature=datasets.Value("string"))
},
"Humility": {
"Be humble": datasets.Sequence(feature=datasets.Value("string")),
"Have life accepted as is": datasets.Sequence(feature=datasets.Value("string"))
},
"Benevolence: caring": {
"Be helpful": datasets.Sequence(feature=datasets.Value("string")),
"Be honest": datasets.Sequence(feature=datasets.Value("string")),
"Be forgiving": datasets.Sequence(feature=datasets.Value("string")),
"Have the own family secured": datasets.Sequence(feature=datasets.Value("string")),
"Be loving": datasets.Sequence(feature=datasets.Value("string"))
},
"Benevolence: dependability": {
"Be responsible": datasets.Sequence(feature=datasets.Value("string")),
"Have loyalty towards friends": datasets.Sequence(feature=datasets.Value("string"))
},
"Universalism: concern": {
"Have equality": datasets.Sequence(feature=datasets.Value("string")),
"Be just": datasets.Sequence(feature=datasets.Value("string")),
"Have a world at peace": datasets.Sequence(feature=datasets.Value("string"))
},
"Universalism: nature": {
"Be protecting the environment": datasets.Sequence(feature=datasets.Value("string")),
"Have harmony with nature": datasets.Sequence(feature=datasets.Value("string")),
"Have a world of beauty": datasets.Sequence(feature=datasets.Value("string"))
},
"Universalism: tolerance": {
"Be broadminded": datasets.Sequence(feature=datasets.Value("string")),
"Have the wisdom to accept others": datasets.Sequence(feature=datasets.Value("string"))
},
"Universalism: objectivity": {
"Be logical": datasets.Sequence(feature=datasets.Value("string")),
"Have an objective view": datasets.Sequence(feature=datasets.Value("string"))
}
}
)
}
########################
# END OF: Features #####
########################
class ToucheValueEvalConfig(datasets.BuilderConfig):
"""BuilderConfig for Touch\u00E923-ValueEval."""
def __init__(self, features, data_urls, citation=None, **kwargs):
"""BuilderConfig for Touch\u00E923-ValueEval.
Args:
features: `list[string]`, list of the features that will appear in the
feature dict.
data_urls: `dict[string,dict[string,string]`, urls to download the dataset files from.
citation: `string`, citation for the data set.
**kwargs: keyword arguments forwarded to super.
"""
# Version history:
# 0.0.2: Initial version.
super(ToucheValueEvalConfig, self).__init__(version=datasets.Version("0.0.2"), **kwargs)
self.features = features
self.data_urls = data_urls
self.citation = citation
class ToucheValueEval(datasets.GeneratorBasedBuilder):
"""The Touch\u00E923-ValueEval dataset."""
BUILDER_CONFIGS = [
ToucheValueEvalConfig(
name=_CONFIG_NAME_MAIN,
features=_FEATURES_ARGUMENT_SETS,
data_urls=_URLS[_CONFIG_NAME_MAIN],
description=_IBM_DESCRIPTION + '\n' + _COFE_DESCRIPTION + '\n' + _GROUP_DISCUSSION_IDEAS_DESCRIPTION + '\n' + _LEVEL2_DESCRIPTION,
citation=_IBM_CITATION + '\n' + _COFE_CITATION
),
ToucheValueEvalConfig(
name=_CONFIG_NAME_MAIN_LEVEL1,
features=_FEATURES_ARGUMENT_SETS,
data_urls=_URLS[_CONFIG_NAME_MAIN_LEVEL1],
description=_IBM_DESCRIPTION + '\n' + _COFE_DESCRIPTION + '\n' + _GROUP_DISCUSSION_IDEAS_DESCRIPTION + '\n' + _LEVEL1_DESCRIPTION,
citation=_IBM_CITATION + '\n' + _COFE_CITATION
),
ToucheValueEvalConfig(
name=_CONFIG_NAME_NAHJALBALAGHA,
features=_FEATURES_ARGUMENT_SETS,
data_urls=_URLS[_CONFIG_NAME_NAHJALBALAGHA],
description=_NAHJALBALAGHA_DESCRIPTION + '\n' + _LEVEL2_DESCRIPTION
),
ToucheValueEvalConfig(
name=_CONFIG_NAME_NAHJALBALAGHA_LEVEL1,
features=_FEATURES_ARGUMENT_SETS,
data_urls=_URLS[_CONFIG_NAME_NAHJALBALAGHA],
description=_NAHJALBALAGHA_DESCRIPTION + '\n' + _LEVEL1_DESCRIPTION
),
ToucheValueEvalConfig(
name=_CONFIG_NAME_NYT,
features=_FEATURES_ARGUMENT_SETS,
data_urls=_URLS[_CONFIG_NAME_NYT],
description=_NYT_DESCRIPTION + '\n' + _LEVEL2_DESCRIPTION
),
ToucheValueEvalConfig(
name=_CONFIG_NAME_NYT_LEVEL1,
features=_FEATURES_ARGUMENT_SETS,
data_urls=_URLS[_CONFIG_NAME_NYT_LEVEL1],
description=_NYT_DESCRIPTION + '\n' + _LEVEL1_DESCRIPTION
),
ToucheValueEvalConfig(
name=_CONFIG_NAME_ZHIHU,
features=_FEATURES_ARGUMENT_SETS,
data_urls=_URLS[_CONFIG_NAME_ZHIHU],
description=_ZHIHU_DESCRIPTION + '\n' + _LEVEL2_DESCRIPTION
),
ToucheValueEvalConfig(
name=_CONFIG_NAME_ZHIHU_LEVEL1,
features=_FEATURES_ARGUMENT_SETS,
data_urls=_URLS[_CONFIG_NAME_ZHIHU_LEVEL1],
description=_ZHIHU_DESCRIPTION + '\n' + _LEVEL1_DESCRIPTION
),
ToucheValueEvalConfig(
name=_CONFIG_NAME_META_A,
features=_FEATURES_META_SETS[_CONFIG_NAME_META_A],
data_urls=_URLS[_CONFIG_NAME_META_A],
description=_IBM_DESCRIPTION + '\n' + _IBM_META_DESCRIPTION,
citation=_IBM_CITATION
),
ToucheValueEvalConfig(
name=_CONFIG_NAME_META_D,
features=_FEATURES_META_SETS[_CONFIG_NAME_META_D],
data_urls=_URLS[_CONFIG_NAME_META_D],
description=_GROUP_DISCUSSION_IDEAS_DESCRIPTION + '\n' + _GROUP_DISCUSSION_IDEAS_META_DESCRIPTION
),
ToucheValueEvalConfig(
name=_CONFIG_NAME_META_E,
features=_FEATURES_META_SETS[_CONFIG_NAME_META_E],
data_urls=_URLS[_CONFIG_NAME_META_E],
description=_COFE_DESCRIPTION + '\n' + _COFE_META_DESCRIPTION,
citation=_COFE_CITATION
),
ToucheValueEvalConfig(
name=_CONFIG_NAME_META_C,
features=_FEATURES_META_SETS[_CONFIG_NAME_META_C],
data_urls=_URLS[_CONFIG_NAME_META_C],
description=_ZHIHU_DESCRIPTION + '\n' + _ZHIHU_META_DESCRIPTION
),
ToucheValueEvalConfig(
name=_CONFIG_NAME_META_F,
features=_FEATURES_META_SETS[_CONFIG_NAME_META_F],
data_urls=_URLS[_CONFIG_NAME_META_F],
description=_NAHJALBALAGHA_DESCRIPTION + '\n' + _NAHJALBALAGHA_META_DESCRIPTION
),
ToucheValueEvalConfig(
name=_CONFIG_NAME_META_G,
features=_FEATURES_META_SETS[_CONFIG_NAME_META_G],
data_urls=_URLS[_CONFIG_NAME_META_G],
description=_NYT_DESCRIPTION + '\n' + _NYT_META_DESCRIPTION
),
ToucheValueEvalConfig(
name=_CONFIG_NAME_VALUE_CATEGORIES,
features=_FEATURES_META_SETS[_CONFIG_NAME_VALUE_CATEGORIES],
data_urls=_URLS[_CONFIG_NAME_VALUE_CATEGORIES],
description=_CATEGORIES_JSON_DESCRIPTION
),
]
DEFAULT_CONFIG_NAME = _CONFIG_NAME_MAIN
def _info(self):
return datasets.DatasetInfo(
description=_DESCRIPTION + self.config.description,
features=self.config.features,
homepage=_HOMEPAGE,
license=_LICENSE,
citation=(self.config.citation + '\n' if self.config.citation is not None else '') + _CITATION,
)
def _split_generators(self, dl_manager):
urls = self.config.data_urls
file_dict = dl_manager.download_and_extract(urls)
if self.config.name == _CONFIG_NAME_MAIN or self.config.name == _CONFIG_NAME_MAIN_LEVEL1:
splits = [
datasets.SplitGenerator(
name=datasets.Split.TRAIN,
gen_kwargs={
"filepaths": file_dict[_SPLIT_TYPE_TRAIN],
"split": _SPLIT_TYPE_TRAIN
},
),
datasets.SplitGenerator(
name=datasets.Split.VALIDATION,
gen_kwargs={
"filepaths": file_dict[_SPLIT_TYPE_VAL],
"split": _SPLIT_TYPE_VAL
},
),
datasets.SplitGenerator(
name=datasets.Split.TEST,
gen_kwargs={
"filepaths": file_dict[_SPLIT_TYPE_TEST],
"split": _SPLIT_TYPE_TEST
},
),
]
elif self.config.name in [_CONFIG_NAME_ZHIHU, _CONFIG_NAME_ZHIHU_LEVEL1]:
splits = [
datasets.SplitGenerator(
name=datasets.Split.VALIDATION,
gen_kwargs={
"filepaths": file_dict[_SPLIT_TYPE_VAL],
"split": _SPLIT_TYPE_VAL
},
),
]
elif self.config.name in [_CONFIG_NAME_NYT, _CONFIG_NAME_NYT_LEVEL1]:
splits = [
datasets.SplitGenerator(
name=datasets.Split.TEST,
gen_kwargs={
"filepaths": file_dict[_SPLIT_TYPE_TEST],
"split": _SPLIT_TYPE_TEST
},
),
]
elif self.config.name in [_CONFIG_NAME_NAHJALBALAGHA, _CONFIG_NAME_NAHJALBALAGHA_LEVEL1]:
splits = [
datasets.SplitGenerator(
name=datasets.Split.TEST,
gen_kwargs={
"filepaths": file_dict[_SPLIT_TYPE_TEST],
"split": _SPLIT_TYPE_TEST
},
),
]
else:
splits = [
datasets.SplitGenerator(
name=_SPLIT_META,
gen_kwargs={
"filepaths": file_dict[_SPLIT_TYPE_META],
"split": _SPLIT_TYPE_META
},
),
]
return splits
# method parameters are unpacked from `gen_kwargs` as given in `_split_generators`
def _generate_examples(self, filepaths, split):
file_types = filepaths.keys()
if self.config.name in [_CONFIG_NAME_NYT, _CONFIG_NAME_NYT_LEVEL1] and _FILE_TYPE_DOWNLOADER in file_types:
# running locally => download nyt arguments
downloader_paths = filepaths[_FILE_TYPE_DOWNLOADER]
directory = os.path.dirname(downloader_paths['downloader'])
arguments_file = os.path.join(directory, _NYT_ARGUMENTS_FILE_LOCAL)
if not os.path.exists(arguments_file):
subprocess.check_call(f"pip3 install -r {downloader_paths['requirements']}", shell=True, stdout=sys.stdout,
stderr=subprocess.STDOUT)
subprocess.check_call(f"spacy download en_core_web_sm", shell=True, stdout=sys.stdout,
stderr=subprocess.STDOUT)
subprocess.check_call(
f"python3 {downloader_paths['downloader']} --input-file {downloader_paths['input-file']} --output-file {arguments_file}",
shell=True, stdout=sys.stdout, stderr=subprocess.STDOUT)
# extract checksum
with open(downloader_paths['checksum'], mode='r', encoding='utf-8') as f:
checksum = f.readline().split(' ')[0]
subprocess.check_call(f"echo \"{checksum} {arguments_file}\" | sha256sum --check", shell=True,
stdout=sys.stdout, stderr=subprocess.STDOUT)
filepaths[_FILE_TYPE_ARGUMENTS] = arguments_file
if _FILE_TYPE_ARGUMENTS in file_types:
# argument data
with open(filepaths[_FILE_TYPE_ARGUMENTS], encoding='utf-8') as f:
dataframe_arguments = pd.read_csv(f, sep='\t', header=0)
if _FILE_TYPE_LABELS not in file_types:
label_names = []
else:
with open(filepaths[_FILE_TYPE_LABELS], encoding='utf-8') as f:
dataframe_labels = pd.read_csv(f, sep='\t', header=0)
label_names = [x for x in dataframe_labels.columns if x != "Argument ID"]
dataframe_arguments = dataframe_arguments.join(
dataframe_labels.set_index('Argument ID'), on='Argument ID', how='inner'
)
for key, row in dataframe_arguments.iterrows():
yield key, {
"Argument ID": row["Argument ID"],
"Conclusion": row["Conclusion"],
"Stance": row["Stance"],
"Premise": row["Premise"],
"Labels": [int(row[x]) for x in label_names],
}
elif _FILE_TYPE_META in file_types:
# meta data
with open(filepaths[_FILE_TYPE_META], encoding='utf-8') as f:
dataframe_meta = pd.read_csv(f, sep='\t', header=0)
for key, row in dataframe_meta.iterrows():
yield key, {str(column): row[str(column)] for column in row.keys()}
else:
# json data
with open(filepaths[_FILE_TYPE_JSON], encoding='utf-8') as f:
value_categories = json.load(f)
yield 0, value_categories