e-tornike commited on
Commit
60d7b90
1 Parent(s): ff36543

Create sv-ident.py

Browse files
Files changed (1) hide show
  1. sv-ident.py +125 -0
sv-ident.py ADDED
@@ -0,0 +1,125 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # coding=utf-8
2
+ # Copyright 2020 The TensorFlow Datasets Authors and the HuggingFace Datasets Authors.
3
+ #
4
+ # Licensed under the Apache License, Version 2.0 (the "License");
5
+ # you may not use this file except in compliance with the License.
6
+ # You may obtain a copy of the License at
7
+ #
8
+ # http://www.apache.org/licenses/LICENSE-2.0
9
+ #
10
+ # Unless required by applicable law or agreed to in writing, software
11
+ # distributed under the License is distributed on an "AS IS" BASIS,
12
+ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13
+ # See the License for the specific language governing permissions and
14
+ # limitations under the License.
15
+
16
+ # Lint as: python3
17
+ """Survey Variable Identification (SV-Ident) Corpus."""
18
+
19
+ import csv
20
+ import random
21
+
22
+ import datasets
23
+
24
+
25
+ # TODO: Add BibTeX citation
26
+ _CITATION = """\
27
+ @misc{sv-ident,
28
+ author={vadis-project},
29
+ title={SV-Ident},
30
+ year={2022},
31
+ url={https://github.com/vadis-project/sv-ident},
32
+ }
33
+ """
34
+
35
+ _DESCRIPTION = """\
36
+ The SV-Ident corpus (version 0.3) is a collection of 4,248 expert-annotated English
37
+ and German sentences from social science publications, supporting the task of
38
+ multi-label text classification.
39
+ """
40
+
41
+ _HOMEPAGE = "https://github.com/vadis-project/sv-ident"
42
+
43
+ # TODO: Add the licence
44
+ # _LICENSE = ""
45
+
46
+ _URLS = {
47
+ "train": "https://raw.githubusercontent.com/vadis-project/sv-ident/9962c3274444ce84c59d42e2a6f8c0958ed15a26/data/train/data.tsv",
48
+ "trial": "https://github.com/vadis-project/sv-ident/tree/9962c3274444ce84c59d42e2a6f8c0958ed15a26/data/trial",
49
+ }
50
+
51
+
52
+ class SVIdent(datasets.GeneratorBasedBuilder):
53
+ """Survey Variable Identification (SV-Ident) Corpus."""
54
+
55
+ VERSION = datasets.Version("0.3.0")
56
+
57
+ def _info(self):
58
+ features = datasets.Features(
59
+ {
60
+ "sentence": datasets.Value("string"),
61
+ "is_variable": datasets.ClassLabel(names=["0", "1"]),
62
+ "variable": datasets.Sequence(datasets.Value(dtype="string")),
63
+ "research_data": datasets.Sequence(datasets.Value(dtype="string")),
64
+ "doc_id": datasets.Value("string"),
65
+ "uuid": datasets.Value("string"),
66
+ "lang": datasets.Value("string"),
67
+ }
68
+ )
69
+
70
+ return datasets.DatasetInfo(
71
+ description=_DESCRIPTION,
72
+ features=features,
73
+ supervised_keys=("sentence", "is_variable"),
74
+ homepage=_HOMEPAGE,
75
+ # license=_LICENSE,
76
+ citation=_CITATION,
77
+ )
78
+
79
+ def _split_generators(self, dl_manager):
80
+ """Returns SplitGenerators."""
81
+ filepath = dl_manager.download(_URLS["train"])
82
+ return [
83
+ datasets.SplitGenerator(
84
+ name=datasets.Split.TRAIN,
85
+ gen_kwargs={
86
+ "filepath": filepath,
87
+ },
88
+ )
89
+ ]
90
+
91
+ def _generate_examples(self, filepath):
92
+ """Yields examples."""
93
+ data = []
94
+ with open(filepath, newline="", encoding="utf-8") as csvfile:
95
+ reader = csv.reader(csvfile, delimiter="\t")
96
+ next(reader, None) # skip the headers
97
+ for row in reader:
98
+ data.append(row)
99
+
100
+ seed = 42
101
+ random.seed(seed)
102
+ random.shuffle(data)
103
+
104
+ for id_, example in enumerate(data):
105
+ sentence = example[0]
106
+ is_variable = example[1]
107
+ variable = example[2] if example[2] != "" else []
108
+ if variable:
109
+ variable = variable.split(";") if ";" in variable else [variable]
110
+ research_data = example[3] if example[3] != "" else []
111
+ if research_data:
112
+ research_data = research_data.split(";") if ";" in research_data else [research_data]
113
+ doc_id = example[4]
114
+ uuid = example[5]
115
+ lang = example[6]
116
+
117
+ yield id_, {
118
+ "sentence": sentence,
119
+ "is_variable": is_variable,
120
+ "variable": variable,
121
+ "research_data": research_data,
122
+ "doc_id": doc_id,
123
+ "uuid": uuid,
124
+ "lang": lang,
125
+ }