gsarti commited on
Commit
ca07c0a
1 Parent(s): 0293625

Fixed configs

Browse files
Files changed (1) hide show
  1. 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
- _SPLITS = {
21
- "train": os.path.join("IK_NLP_22_PESTYLE", "train.tsv"),
22
- "test_mask_subject": os.path.join("IK_NLP_22_PESTYLE", "test.tsv"),
23
- "test_mask_modality": os.path.join("IK_NLP_22_PESTYLE", "test.tsv"),
24
- "test_mask_time": os.path.join("IK_NLP_22_PESTYLE", "test.tsv")
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
- "train": _ALL_FIELDS,
54
- "test_mask_subject": _FIELDS_MASK_SUBJECT,
55
- "test_mask_modality": _FIELDS_MASK_MODALITY,
56
- "test_mask_time": _FIELDS_MASK_TIME
57
  }
58
 
59
  class IkNlp22PEStyleConfig(datasets.BuilderConfig):
60
- """BuilderConfig for the IK NLP '22 HT-Style Dataset."""
61
 
62
  def __init__(
63
  self,
@@ -79,12 +72,13 @@ class IkNlp22PEStyle(datasets.GeneratorBasedBuilder):
79
 
80
  BUILDER_CONFIGS = [
81
  IkNlp22PEStyleConfig(
82
- name="main",
83
- features=_ALL_FIELDS,
84
- ),
 
85
  ]
86
 
87
- DEFAULT_CONFIG_NAME = "main"
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.csv and test.csv files."
96
- "Then, load the dataset with: `datasets.load_dataset('GroNLP/ik-nlp-22_pestyle', 'main', data_dir='path/to/root/folder')`"
97
  )
98
 
99
  def _info(self):
100
- features = {feature: datasets.Value("float32") for feature in self.config.features}
101
- for feat in _INT_FIELDS:
102
- features[feat] = datasets.Value("int32")
103
- features["subject_id"] = datasets.Value("string")
104
- features["modality"] = datasets.Value("string")
105
- features["src_text"] = datasets.Value("string")
106
- features["mt_text"] = datasets.Value("string")
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, path),
133
- "name": name,
134
  },
135
  )
136
- for name, path in _SPLITS.items()
137
  ]
138
 
139
- def _generate_examples(self, filepath: str, name):
140
  """Yields examples as (key, example) tuples."""
141
  data = pd.read_csv(filepath, sep="\t")
142
- for f in set(_ALL_FIELDS).difference(set(_DICT_FIELDS[name])):
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()