Fixed configs
Browse files- ik-nlp-22_pestyle.py +29 -43
ik-nlp-22_pestyle.py
CHANGED
@@ -2,7 +2,6 @@ import os
|
|
2 |
|
3 |
import datasets
|
4 |
import pandas as pd
|
5 |
-
import numpy as np
|
6 |
|
7 |
_CITATION = """No citation information available."""
|
8 |
|
@@ -17,11 +16,11 @@ _HOMEPAGE = "https://www.rug.nl/masters/information-science/?lang=en"
|
|
17 |
|
18 |
_LICENSE = "Sharing and publishing of the data is not allowed at the moment."
|
19 |
|
20 |
-
|
21 |
-
"
|
22 |
-
"
|
23 |
-
"
|
24 |
-
"
|
25 |
}
|
26 |
|
27 |
_ALL_FIELDS = [
|
@@ -33,12 +32,6 @@ _ALL_FIELDS = [
|
|
33 |
"n_insert", "n_delete", "n_substitute", "n_shift", "bleu", "chrf", "ter", "aligned_edit"
|
34 |
]
|
35 |
|
36 |
-
_INT_FIELDS = [
|
37 |
-
"k_total", "k_letter", "k_digit", "k_white", "k_symbol", "k_nav", "k_erase",
|
38 |
-
"k_copy", "k_cut", "k_paste", "n_pause_geq_300", "len_pause_geq_300",
|
39 |
-
"n_pause_geq_1000", "len_pause_geq_1000", "num_annotations"
|
40 |
-
]
|
41 |
-
|
42 |
_FIELDS_MASK_SUBJECT = [f for f in _ALL_FIELDS if f not in ["subject_id"]]
|
43 |
_FIELDS_MASK_MODALITY = [f for f in _ALL_FIELDS if f not in [
|
44 |
"modality", "mt_text", "n_insert", "n_delete", "n_substitute",
|
@@ -50,14 +43,14 @@ _FIELDS_MASK_TIME = [f for f in _ALL_FIELDS if f not in [
|
|
50 |
]]
|
51 |
|
52 |
_DICT_FIELDS = {
|
53 |
-
"
|
54 |
-
"
|
55 |
-
"
|
56 |
-
"
|
57 |
}
|
58 |
|
59 |
class IkNlp22PEStyleConfig(datasets.BuilderConfig):
|
60 |
-
"""BuilderConfig for the IK NLP '22
|
61 |
|
62 |
def __init__(
|
63 |
self,
|
@@ -79,12 +72,13 @@ class IkNlp22PEStyle(datasets.GeneratorBasedBuilder):
|
|
79 |
|
80 |
BUILDER_CONFIGS = [
|
81 |
IkNlp22PEStyleConfig(
|
82 |
-
name=
|
83 |
-
features=
|
84 |
-
)
|
|
|
85 |
]
|
86 |
|
87 |
-
DEFAULT_CONFIG_NAME = "
|
88 |
|
89 |
@property
|
90 |
|
@@ -92,20 +86,18 @@ class IkNlp22PEStyle(datasets.GeneratorBasedBuilder):
|
|
92 |
return (
|
93 |
"The access to the data is restricted to students of the IK MSc NLP 2022 course working on a related project."
|
94 |
"To load the data using this dataset, download and extract the IK_NLP_22_PESTYLE folder you were provided upon selecting the final project."
|
95 |
-
"After extracting it, the folder (referred to as root) must contain a IK_NLP_22_PESTYLE subfolder, containing train.
|
96 |
-
"Then, load the dataset with: `datasets.load_dataset('GroNLP/ik-nlp-22_pestyle', '
|
97 |
)
|
98 |
|
99 |
def _info(self):
|
100 |
-
features = {feature: datasets.Value("
|
101 |
-
for
|
102 |
-
|
103 |
-
|
104 |
-
|
105 |
-
|
106 |
-
|
107 |
-
features["tgt_text"] = datasets.Value("string")
|
108 |
-
features["aligned_edit"] = datasets.Value("string")
|
109 |
return datasets.DatasetInfo(
|
110 |
description=_DESCRIPTION,
|
111 |
features=datasets.Features(features),
|
@@ -127,23 +119,17 @@ class IkNlp22PEStyle(datasets.GeneratorBasedBuilder):
|
|
127 |
)
|
128 |
return [
|
129 |
datasets.SplitGenerator(
|
130 |
-
name=name,
|
131 |
gen_kwargs={
|
132 |
-
"filepath": os.path.join(data_dir,
|
133 |
-
"
|
134 |
},
|
135 |
)
|
136 |
-
for name, path in _SPLITS.items()
|
137 |
]
|
138 |
|
139 |
-
def _generate_examples(self, filepath: str,
|
140 |
"""Yields examples as (key, example) tuples."""
|
141 |
data = pd.read_csv(filepath, sep="\t")
|
142 |
-
|
143 |
-
if isinstance(data[f][0], float):
|
144 |
-
data[f] = np.nan
|
145 |
-
else:
|
146 |
-
data[f] = None
|
147 |
-
print(data.shape)
|
148 |
for id_, row in data.iterrows():
|
149 |
yield id_, row.to_dict()
|
|
|
2 |
|
3 |
import datasets
|
4 |
import pandas as pd
|
|
|
5 |
|
6 |
_CITATION = """No citation information available."""
|
7 |
|
|
|
16 |
|
17 |
_LICENSE = "Sharing and publishing of the data is not allowed at the moment."
|
18 |
|
19 |
+
_PATHS = {
|
20 |
+
"full": os.path.join("IK_NLP_22_PESTYLE", "train.tsv"),
|
21 |
+
"mask_subject": os.path.join("IK_NLP_22_PESTYLE", "test.tsv"),
|
22 |
+
"mask_modality": os.path.join("IK_NLP_22_PESTYLE", "test.tsv"),
|
23 |
+
"mask_time": os.path.join("IK_NLP_22_PESTYLE", "test.tsv")
|
24 |
}
|
25 |
|
26 |
_ALL_FIELDS = [
|
|
|
32 |
"n_insert", "n_delete", "n_substitute", "n_shift", "bleu", "chrf", "ter", "aligned_edit"
|
33 |
]
|
34 |
|
|
|
|
|
|
|
|
|
|
|
|
|
35 |
_FIELDS_MASK_SUBJECT = [f for f in _ALL_FIELDS if f not in ["subject_id"]]
|
36 |
_FIELDS_MASK_MODALITY = [f for f in _ALL_FIELDS if f not in [
|
37 |
"modality", "mt_text", "n_insert", "n_delete", "n_substitute",
|
|
|
43 |
]]
|
44 |
|
45 |
_DICT_FIELDS = {
|
46 |
+
"full": _ALL_FIELDS,
|
47 |
+
"mask_subject": _FIELDS_MASK_SUBJECT,
|
48 |
+
"mask_modality": _FIELDS_MASK_MODALITY,
|
49 |
+
"mask_time": _FIELDS_MASK_TIME
|
50 |
}
|
51 |
|
52 |
class IkNlp22PEStyleConfig(datasets.BuilderConfig):
|
53 |
+
"""BuilderConfig for the IK NLP '22 Post-editing Stylometry Dataset."""
|
54 |
|
55 |
def __init__(
|
56 |
self,
|
|
|
72 |
|
73 |
BUILDER_CONFIGS = [
|
74 |
IkNlp22PEStyleConfig(
|
75 |
+
name=name,
|
76 |
+
features=fields,
|
77 |
+
)
|
78 |
+
for name, fields in _DICT_FIELDS.items()
|
79 |
]
|
80 |
|
81 |
+
DEFAULT_CONFIG_NAME = "full"
|
82 |
|
83 |
@property
|
84 |
|
|
|
86 |
return (
|
87 |
"The access to the data is restricted to students of the IK MSc NLP 2022 course working on a related project."
|
88 |
"To load the data using this dataset, download and extract the IK_NLP_22_PESTYLE folder you were provided upon selecting the final project."
|
89 |
+
"After extracting it, the folder (referred to as root) must contain a IK_NLP_22_PESTYLE subfolder, containing train.tsv and test.tsv files."
|
90 |
+
f"Then, load the dataset with: `datasets.load_dataset('GroNLP/ik-nlp-22_pestyle', '{self.config.name}', data_dir='path/to/root/folder')`"
|
91 |
)
|
92 |
|
93 |
def _info(self):
|
94 |
+
features = {feature: datasets.Value("int32") for feature in self.config.features}
|
95 |
+
for field in ["subject_id", "modality", "src_text", "mt_text", "tgt_text", "aligned_edit"]:
|
96 |
+
if field in self.config.features:
|
97 |
+
features[field] = datasets.Value("string")
|
98 |
+
for field in ["aligned_edit", "bleu", "chrf", "ter"]:
|
99 |
+
if field in self.config.features:
|
100 |
+
features[field] = datasets.Value("float32")
|
|
|
|
|
101 |
return datasets.DatasetInfo(
|
102 |
description=_DESCRIPTION,
|
103 |
features=datasets.Features(features),
|
|
|
119 |
)
|
120 |
return [
|
121 |
datasets.SplitGenerator(
|
122 |
+
name=datasets.Split.TRAIN if self.config.name == "full" else datasets.Split.TEST,
|
123 |
gen_kwargs={
|
124 |
+
"filepath": os.path.join(data_dir, _PATHS[self.config.name]),
|
125 |
+
"features": self.config.features,
|
126 |
},
|
127 |
)
|
|
|
128 |
]
|
129 |
|
130 |
+
def _generate_examples(self, filepath: str, features: list(str)):
|
131 |
"""Yields examples as (key, example) tuples."""
|
132 |
data = pd.read_csv(filepath, sep="\t")
|
133 |
+
data = data[features]
|
|
|
|
|
|
|
|
|
|
|
134 |
for id_, row in data.iterrows():
|
135 |
yield id_, row.to_dict()
|