Datasets:
File size: 4,402 Bytes
60d7b90 0e1d0b6 60d7b90 0e1d0b6 93f7079 60d7b90 0e1d0b6 60d7b90 0e1d0b6 93f7079 0e1d0b6 60d7b90 |
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 |
# coding=utf-8
# Copyright 2020 The TensorFlow Datasets Authors and the 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
"""Survey Variable Identification (SV-Ident) Corpus."""
import csv
import random
import datasets
# TODO: Add BibTeX citation
_CITATION = """\
@misc{sv-ident,
author={vadis-project},
title={SV-Ident},
year={2022},
url={https://github.com/vadis-project/sv-ident},
}
"""
_DESCRIPTION = """\
The SV-Ident corpus (version 0.3) is a collection of 4,248 expert-annotated English
and German sentences from social science publications, supporting the task of
multi-label text classification.
"""
_HOMEPAGE = "https://github.com/vadis-project/sv-ident"
# TODO: Add the licence
# _LICENSE = ""
_URL = "https://raw.githubusercontent.com/vadis-project/sv-ident/a8e71bba570f628c460e2b542d4cc645e4eb7d03/data/train/"
_URLS = {
"train": _URL+"train.tsv",
"dev": _URL+"val.tsv",
# "trial": "https://github.com/vadis-project/sv-ident/tree/9962c3274444ce84c59d42e2a6f8c0958ed15a26/data/trial",
}
class SVIdent(datasets.GeneratorBasedBuilder):
"""Survey Variable Identification (SV-Ident) Corpus."""
VERSION = datasets.Version("0.3.0")
def _info(self):
features = datasets.Features(
{
"sentence": datasets.Value("string"),
"is_variable": datasets.ClassLabel(names=["0", "1"]),
"variable": datasets.Sequence(datasets.Value(dtype="string")),
"research_data": datasets.Sequence(datasets.Value(dtype="string")),
"doc_id": datasets.Value("string"),
"uuid": datasets.Value("string"),
"lang": datasets.Value("string"),
}
)
return datasets.DatasetInfo(
description=_DESCRIPTION,
features=features,
supervised_keys=("sentence", "is_variable"),
homepage=_HOMEPAGE,
# license=_LICENSE,
citation=_CITATION,
)
def _split_generators(self, dl_manager):
"""Returns SplitGenerators."""
downloaded_files = dl_manager.download(_URLS)
return [
datasets.SplitGenerator(
name=datasets.Split.TRAIN,
gen_kwargs={
"filepath": downloaded_files["train"],
},
),
datasets.SplitGenerator(
name=datasets.Split.VALIDATION,
gen_kwargs={
"filepath": downloaded_files["dev"],
},
)
]
def _generate_examples(self, filepath):
"""Yields examples."""
data = []
with open(filepath, newline="", encoding="utf-8") as csvfile:
reader = csv.reader(csvfile, delimiter="\t")
next(reader, None) # skip the headers
for row in reader:
data.append(row)
seed = 42
random.seed(seed)
random.shuffle(data)
for id_, example in enumerate(data):
sentence = example[0]
is_variable = example[1]
variable = example[2] if example[2] != "" else []
if variable:
variable = variable.split(";") if ";" in variable else [variable]
research_data = example[3] if example[3] != "" else []
if research_data:
research_data = research_data.split(";") if ";" in research_data else [research_data]
doc_id = example[4]
uuid = example[5]
lang = example[6]
yield id_, {
"sentence": sentence,
"is_variable": is_variable,
"variable": variable,
"research_data": research_data,
"doc_id": doc_id,
"uuid": uuid,
"lang": lang,
}
|