Datasets:

scidtb_argmin / scidtb_argmin.py
ArneBinder's picture
fix imports
8c02587
raw
history blame
6.69 kB
"""The SciDTB-Argmin dataset for Argumentation Mining on English scientific abstracts."""
import glob
import json
from os.path import abspath, isdir
from pathlib import Path
import datasets
_CITATION = """\
@inproceedings{accuosto-saggion-2019-transferring,
title = "Transferring Knowledge from Discourse to Arguments: A Case Study with Scientific Abstracts",
author = "Accuosto, Pablo and
Saggion, Horacio",
booktitle = "Proceedings of the 6th Workshop on Argument Mining",
month = aug,
year = "2019",
address = "Florence, Italy",
publisher = "Association for Computational Linguistics",
url = "https://aclanthology.org/W19-4505",
doi = "10.18653/v1/W19-4505",
pages = "41--51",
abstract = "In this work we propose to leverage resources available with discourse-level annotations to facilitate the identification of argumentative components and relations in scientific texts, which has been recognized as a particularly challenging task. In particular, we implement and evaluate a transfer learning approach in which contextualized representations learned from discourse parsing tasks are used as input of argument mining models. As a pilot application, we explore the feasibility of using automatically identified argumentative components and relations to predict the acceptance of papers in computer science venues. In order to conduct our experiments, we propose an annotation scheme for argumentative units and relations and use it to enrich an existing corpus with an argumentation layer.",
}
"""
_DESCRIPTION = (
"The SciDTB-Argmin dataset for Argumentation Mining on English scientific abstracts."
)
_HOMEPAGE = ""
_LICENSE = ""
# The HuggingFace dataset library don't host the datasets but only point to the original files
# This can be an arbitrary nested dict/list of URLs (see below in `_split_generators` method)
_URL = "http://scientmin.taln.upf.edu/argmin/scidtb_argmin_annotations.tgz"
_VERSION = datasets.Version("1.0.0")
_SPAN_CLASS_LABELS = [
"proposal",
"assertion",
"result",
"observation",
"means",
"description",
"none",
]
_RELATION_CLASS_LABELS = ["support", "additional", "detail", "sequence", "none"]
class SciDTBArgmin(datasets.GeneratorBasedBuilder):
"""SciDTB-Argmin is an argumentation mining dataset."""
BUILDER_CONFIGS = [datasets.BuilderConfig(name="default")]
DEFAULT_CONFIG_NAME = "default" # type: ignore
def _info(self):
features = datasets.Features(
{
"id": datasets.Value("string"),
"data": datasets.Sequence(
{
"token": datasets.Value("string"),
"unit-bio": datasets.ClassLabel(names=["B", "I", "O"]),
"unit-label": datasets.ClassLabel(names=_SPAN_CLASS_LABELS),
"role": datasets.ClassLabel(names=_RELATION_CLASS_LABELS),
"parent-offset": datasets.Value("int32"),
# "parent-offset": datasets.Value("string"),
}
),
}
)
return datasets.DatasetInfo(
# This is the description that will appear on the datasets page.
description=_DESCRIPTION,
# This defines the different columns of the dataset and their types
features=features, # Here we define them above because they are different between the two configurations
# If there's a common (input, target) tuple from the features,
# specify them here. They'll be used if as_supervised=True in
# builder.as_dataset.
supervised_keys=None,
# Homepage of the dataset for documentation
homepage=_HOMEPAGE,
# License for the dataset if available
license=_LICENSE,
# Citation for the dataset
citation=_CITATION,
)
def _split_generators(self, dl_manager):
"""Returns SplitGenerators."""
# If several configurations are possible (listed in BUILDER_CONFIGS), the configuration selected by the user is in self.config.name
# dl_manager is a datasets.download.DownloadManager that can be used to download and extract URLs
# It can accept any type or nested list/dict and will give back the same structure with the url replaced with path to local files.
# By default the archives will be extracted and a path to a cached folder where they are extracted is returned instead of the archive
if dl_manager.manual_dir is not None:
base_path = abspath(dl_manager.manual_dir)
if not isdir(base_path):
base_path = dl_manager.extract(base_path)
else:
base_path = dl_manager.download_and_extract(_URL)
return [
datasets.SplitGenerator(name=datasets.Split.TRAIN, gen_kwargs={"path": base_path}),
]
def _generate_examples(self, path):
"""Yields examples."""
# This method will receive as arguments the `gen_kwargs` defined in the previous `_split_generators` method.
# It is in charge of opening the given file and yielding (key, example) tuples from the dataset
# The key is not important, it's more here for legacy reason (legacy from tfds)
_id = 0
conll_file_names = sorted(glob.glob(f"{path}/*.conll"))
for conll_file_name in conll_file_names:
data = []
with open(conll_file_name, encoding="utf-8") as f:
for line in f:
# example content for some lines:
# reading I-proposal-none-0
# . I-proposal-none-0
# We B-means-detail-1
# observe I-means-detail-1
# , I-means-detail-1
# identify I-means-detail-1
token, annotation = line.strip().split("\t")
unit_bio, unit_label, role, parent_offset_str = annotation.split(
"-", maxsplit=3
)
parent_offset = int(parent_offset_str)
data.append(
{
"token": token,
"unit-bio": unit_bio,
"unit-label": unit_label,
"role": role,
"parent-offset": parent_offset,
}
)
yield _id, {
"id": Path(conll_file_name).stem,
"data": data,
}
_id += 1