Datasets:
cjvt
/

Matej Klemen commited on
Commit
9bbe4fa
·
1 Parent(s): b2bdc31

Add option to choose between a sentence-level dataset and a document-level dataset

Browse files
Files changed (2) hide show
  1. dataset_infos.json +1 -1
  2. solar3.py +100 -6
dataset_infos.json CHANGED
@@ -1 +1 @@
1
- {"default": {"description": "\u0160olar is a developmental corpus of 5485 school texts (e.g., essays), written by students in Slovenian secondary schools \n(age 15-19) and pupils in the 7th-9th grade of primary school (13-15), with a small percentage also from the 6th grade. \nPart of the corpus (2,094 texts) is annotated with teachers' corrections using a system of labels described in the \ndocument available at https://www.clarin.si/repository/xmlui/bitstream/handle/11356/1589/Smernice-za-oznacevanje-korpusa-Solar_V1.1.pdf (in Slovenian).\n", "citation": "@misc{solar3.0,\n title = {Developmental corpus {\u000b S}olar 3.0},\n author = {Arhar Holdt, {\u000b S}pela and Rozman, Tadeja and Stritar Ku{\u000b c}uk, Mojca and Krek, Simon and Krap{\u000b s} Vodopivec, Irena and Stabej, Marko and Pori, Eva and Goli, Teja and Lavri{\u000b c}, Polona and Laskowski, Cyprian and Kocjan{\u000b c}i{\u000b c}, Polonca and Klemenc, Bojan and Krsnik, Luka and Kosem, Iztok},\n url = {http://hdl.handle.net/11356/1589},\n note = {Slovenian language resource repository {CLARIN}.{SI}},\n year = {2022}\n}\n", "homepage": "http://hdl.handle.net/11356/1589", "license": "Creative Commons - Attribution-NonCommercial-ShareAlike 4.0 International (CC BY-NC-SA 4.0)", "features": {"id_doc": {"dtype": "string", "id": null, "_type": "Value"}, "doc_title": {"dtype": "string", "id": null, "_type": "Value"}, "is_manually_validated": {"dtype": "bool", "id": null, "_type": "Value"}, "id_src_tokens": {"feature": {"dtype": "string", "id": null, "_type": "Value"}, "length": -1, "id": null, "_type": "Sequence"}, "src_tokens": {"feature": {"dtype": "string", "id": null, "_type": "Value"}, "length": -1, "id": null, "_type": "Sequence"}, "id_tgt_tokens": {"feature": {"dtype": "string", "id": null, "_type": "Value"}, "length": -1, "id": null, "_type": "Sequence"}, "tgt_tokens": {"feature": {"dtype": "string", "id": null, "_type": "Value"}, "length": -1, "id": null, "_type": "Sequence"}, "corrections": [{"idx_src": {"feature": {"dtype": "int32", "id": null, "_type": "Value"}, "length": -1, "id": null, "_type": "Sequence"}, "idx_tgt": {"feature": {"dtype": "int32", "id": null, "_type": "Value"}, "length": -1, "id": null, "_type": "Sequence"}, "corr_types": {"feature": {"dtype": "string", "id": null, "_type": "Value"}, "length": -1, "id": null, "_type": "Sequence"}}]}, "post_processed": null, "supervised_keys": null, "task_templates": null, "builder_name": "solar3", "config_name": "default", "version": {"version_str": "1.0.0", "description": null, "major": 1, "minor": 0, "patch": 0}, "splits": {"train": {"name": "train", "num_bytes": 120154479, "num_examples": 125867, "dataset_name": "solar3"}}, "download_checksums": {"https://www.clarin.si/repository/xmlui/bitstream/handle/11356/1589/Solar.TEI.zip": {"num_bytes": 99287852, "checksum": "188945c90c663cc34c77c6aefd40357b60b88436b3d9fd53f24304c927ac1cbf"}}, "download_size": 99287852, "post_processing_size": null, "dataset_size": 120154479, "size_in_bytes": 219442331}}
 
1
+ {"default": {"description": "\u0160olar is a developmental corpus of 5485 school texts (e.g., essays), written by students in Slovenian secondary schools \n(age 15-19) and pupils in the 7th-9th grade of primary school (13-15), with a small percentage also from the 6th grade. \nPart of the corpus (2,094 texts) is annotated with teachers' corrections using a system of labels described in the \ndocument available at https://www.clarin.si/repository/xmlui/bitstream/handle/11356/1589/Smernice-za-oznacevanje-korpusa-Solar_V1.1.pdf (in Slovenian).\n", "citation": "@misc{solar3.0,\n title = {Developmental corpus {\u000b S}olar 3.0},\n author = {Arhar Holdt, {\u000b S}pela and Rozman, Tadeja and Stritar Ku{\u000b c}uk, Mojca and Krek, Simon and Krap{\u000b s} Vodopivec, Irena and Stabej, Marko and Pori, Eva and Goli, Teja and Lavri{\u000b c}, Polona and Laskowski, Cyprian and Kocjan{\u000b c}i{\u000b c}, Polonca and Klemenc, Bojan and Krsnik, Luka and Kosem, Iztok},\n url = {http://hdl.handle.net/11356/1589},\n note = {Slovenian language resource repository {CLARIN}.{SI}},\n year = {2022}\n}\n", "homepage": "http://hdl.handle.net/11356/1589", "license": "Creative Commons - Attribution-NonCommercial-ShareAlike 4.0 International (CC BY-NC-SA 4.0)", "features": {"id_doc": {"dtype": "string", "id": null, "_type": "Value"}, "doc_title": {"dtype": "string", "id": null, "_type": "Value"}, "is_manually_validated": {"dtype": "bool", "id": null, "_type": "Value"}, "id_src_tokens": {"feature": {"dtype": "string", "id": null, "_type": "Value"}, "length": -1, "id": null, "_type": "Sequence"}, "src_tokens": {"feature": {"dtype": "string", "id": null, "_type": "Value"}, "length": -1, "id": null, "_type": "Sequence"}, "id_tgt_tokens": {"feature": {"dtype": "string", "id": null, "_type": "Value"}, "length": -1, "id": null, "_type": "Sequence"}, "tgt_tokens": {"feature": {"dtype": "string", "id": null, "_type": "Value"}, "length": -1, "id": null, "_type": "Sequence"}, "corrections": [{"idx_src": {"feature": {"dtype": "int32", "id": null, "_type": "Value"}, "length": -1, "id": null, "_type": "Sequence"}, "idx_tgt": {"feature": {"dtype": "int32", "id": null, "_type": "Value"}, "length": -1, "id": null, "_type": "Sequence"}, "corr_types": {"feature": {"dtype": "string", "id": null, "_type": "Value"}, "length": -1, "id": null, "_type": "Sequence"}}]}, "post_processed": null, "supervised_keys": null, "task_templates": null, "builder_name": "solar3", "config_name": "default", "version": {"version_str": "1.0.0", "description": null, "major": 1, "minor": 0, "patch": 0}, "splits": {"train": {"name": "train", "num_bytes": 120154479, "num_examples": 125867, "dataset_name": "solar3"}}, "download_checksums": {"https://www.clarin.si/repository/xmlui/bitstream/handle/11356/1589/Solar.TEI.zip": {"num_bytes": 99287852, "checksum": "188945c90c663cc34c77c6aefd40357b60b88436b3d9fd53f24304c927ac1cbf"}}, "download_size": 99287852, "post_processing_size": null, "dataset_size": 120154479, "size_in_bytes": 219442331}, "sentence_level": {"description": "\u0160olar is a developmental corpus of 5485 school texts (e.g., essays), written by students in Slovenian secondary schools \n(age 15-19) and pupils in the 7th-9th grade of primary school (13-15), with a small percentage also from the 6th grade. \nPart of the corpus (1516 texts) is annotated with teachers' corrections using a system of labels described in the \ndocument available at https://www.clarin.si/repository/xmlui/bitstream/handle/11356/1589/Smernice-za-oznacevanje-korpusa-Solar_V1.1.pdf (in Slovenian).\n", "citation": "@misc{solar3.0,\n title = {Developmental corpus {\u000b S}olar 3.0},\n author = {Arhar Holdt, {\u000b S}pela and Rozman, Tadeja and Stritar Ku{\u000b c}uk, Mojca and Krek, Simon and Krap{\u000b s} Vodopivec, Irena and Stabej, Marko and Pori, Eva and Goli, Teja and Lavri{\u000b c}, Polona and Laskowski, Cyprian and Kocjan{\u000b c}i{\u000b c}, Polonca and Klemenc, Bojan and Krsnik, Luka and Kosem, Iztok},\n url = {http://hdl.handle.net/11356/1589},\n note = {Slovenian language resource repository {CLARIN}.{SI}},\n year = {2022}\n}\n", "homepage": "http://hdl.handle.net/11356/1589", "license": "Creative Commons - Attribution-NonCommercial-ShareAlike 4.0 International (CC BY-NC-SA 4.0)", "features": {"id_doc": {"dtype": "string", "id": null, "_type": "Value"}, "doc_title": {"dtype": "string", "id": null, "_type": "Value"}, "is_manually_validated": {"dtype": "bool", "id": null, "_type": "Value"}, "src_tokens": {"feature": {"dtype": "string", "id": null, "_type": "Value"}, "length": -1, "id": null, "_type": "Sequence"}, "tgt_tokens": {"feature": {"dtype": "string", "id": null, "_type": "Value"}, "length": -1, "id": null, "_type": "Sequence"}, "corrections": [{"idx_src": {"feature": {"dtype": "int32", "id": null, "_type": "Value"}, "length": -1, "id": null, "_type": "Sequence"}, "idx_tgt": {"feature": {"dtype": "int32", "id": null, "_type": "Value"}, "length": -1, "id": null, "_type": "Sequence"}, "corr_types": {"feature": {"dtype": "string", "id": null, "_type": "Value"}, "length": -1, "id": null, "_type": "Sequence"}}]}, "post_processed": null, "supervised_keys": null, "task_templates": null, "builder_name": "solar3", "config_name": "sentence_level", "version": {"version_str": "3.0.1", "description": null, "major": 3, "minor": 0, "patch": 1}, "splits": {"train": {"name": "train", "num_bytes": 41032273, "num_examples": 125867, "dataset_name": "solar3"}}, "download_checksums": {"https://www.clarin.si/repository/xmlui/bitstream/handle/11356/1589/Solar.TEI.zip": {"num_bytes": 99287852, "checksum": "188945c90c663cc34c77c6aefd40357b60b88436b3d9fd53f24304c927ac1cbf"}}, "download_size": 99287852, "post_processing_size": null, "dataset_size": 41032273, "size_in_bytes": 140320125}, "document_level": {"description": "\u0160olar is a developmental corpus of 5485 school texts (e.g., essays), written by students in Slovenian secondary schools \n(age 15-19) and pupils in the 7th-9th grade of primary school (13-15), with a small percentage also from the 6th grade. \nPart of the corpus (1516 texts) is annotated with teachers' corrections using a system of labels described in the \ndocument available at https://www.clarin.si/repository/xmlui/bitstream/handle/11356/1589/Smernice-za-oznacevanje-korpusa-Solar_V1.1.pdf (in Slovenian).\n", "citation": "@misc{solar3.0,\n title = {Developmental corpus {\u000b S}olar 3.0},\n author = {Arhar Holdt, {\u000b S}pela and Rozman, Tadeja and Stritar Ku{\u000b c}uk, Mojca and Krek, Simon and Krap{\u000b s} Vodopivec, Irena and Stabej, Marko and Pori, Eva and Goli, Teja and Lavri{\u000b c}, Polona and Laskowski, Cyprian and Kocjan{\u000b c}i{\u000b c}, Polonca and Klemenc, Bojan and Krsnik, Luka and Kosem, Iztok},\n url = {http://hdl.handle.net/11356/1589},\n note = {Slovenian language resource repository {CLARIN}.{SI}},\n year = {2022}\n}\n", "homepage": "http://hdl.handle.net/11356/1589", "license": "Creative Commons - Attribution-NonCommercial-ShareAlike 4.0 International (CC BY-NC-SA 4.0)", "features": {"id_doc": {"dtype": "string", "id": null, "_type": "Value"}, "doc_title": {"dtype": "string", "id": null, "_type": "Value"}, "is_manually_validated": {"dtype": "bool", "id": null, "_type": "Value"}, "src_tokens": {"feature": {"dtype": "string", "id": null, "_type": "Value"}, "length": -1, "id": null, "_type": "Sequence"}, "tgt_tokens": {"feature": {"dtype": "string", "id": null, "_type": "Value"}, "length": -1, "id": null, "_type": "Sequence"}, "corrections": [{"idx_src": {"feature": {"dtype": "int32", "id": null, "_type": "Value"}, "length": -1, "id": null, "_type": "Sequence"}, "idx_tgt": {"feature": {"dtype": "int32", "id": null, "_type": "Value"}, "length": -1, "id": null, "_type": "Sequence"}, "corr_types": {"feature": {"dtype": "string", "id": null, "_type": "Value"}, "length": -1, "id": null, "_type": "Sequence"}}]}, "post_processed": null, "supervised_keys": null, "task_templates": null, "builder_name": "solar3", "config_name": "document_level", "version": {"version_str": "3.0.1", "description": null, "major": 3, "minor": 0, "patch": 1}, "splits": {"train": {"name": "train", "num_bytes": 33456666, "num_examples": 5485, "dataset_name": "solar3"}}, "download_checksums": {"https://www.clarin.si/repository/xmlui/bitstream/handle/11356/1589/Solar.TEI.zip": {"num_bytes": 99287852, "checksum": "188945c90c663cc34c77c6aefd40357b60b88436b3d9fd53f24304c927ac1cbf"}}, "download_size": 99287852, "post_processing_size": null, "dataset_size": 33456666, "size_in_bytes": 132744518}}
solar3.py CHANGED
@@ -2,6 +2,7 @@ import logging
2
  import os
3
  import re
4
  import xml.etree.ElementTree as ET
 
5
  from typing import Optional
6
 
7
  import datasets
@@ -19,7 +20,7 @@ _CITATION = """\
19
  _DESCRIPTION = """\
20
  Šolar is a developmental corpus of 5485 school texts (e.g., essays), written by students in Slovenian secondary schools
21
  (age 15-19) and pupils in the 7th-9th grade of primary school (13-15), with a small percentage also from the 6th grade.
22
- Part of the corpus (2,094 texts) is annotated with teachers' corrections using a system of labels described in the
23
  document available at https://www.clarin.si/repository/xmlui/bitstream/handle/11356/1589/Smernice-za-oznacevanje-korpusa-Solar_V1.1.pdf (in Slovenian).
24
  """
25
 
@@ -131,7 +132,16 @@ class Solar3(datasets.GeneratorBasedBuilder):
131
  """Šolar is a developmental corpus of school texts (e.g., essays), annotated with metadata and (partially)
132
  with teachers' corrections. """
133
 
134
- VERSION = datasets.Version("3.0.0")
 
 
 
 
 
 
 
 
 
135
 
136
  def _info(self):
137
  features = datasets.Features(
@@ -139,9 +149,7 @@ class Solar3(datasets.GeneratorBasedBuilder):
139
  "id_doc": datasets.Value("string"),
140
  "doc_title": datasets.Value("string"),
141
  "is_manually_validated": datasets.Value("bool"),
142
- "id_src_tokens": datasets.Sequence(datasets.Value("string")),
143
  "src_tokens": datasets.Sequence(datasets.Value("string")),
144
- "id_tgt_tokens": datasets.Sequence(datasets.Value("string")),
145
  "tgt_tokens": datasets.Sequence(datasets.Value("string")),
146
  "corrections": [
147
  {
@@ -177,7 +185,8 @@ class Solar3(datasets.GeneratorBasedBuilder):
177
  )
178
  ]
179
 
180
- def _generate_examples(self, source_path, target_path, links_path):
 
181
  source_data = read_data(source_path)
182
  target_data = read_data(target_path)
183
 
@@ -186,7 +195,6 @@ class Solar3(datasets.GeneratorBasedBuilder):
186
  NAMESPACE = namespace(root)
187
 
188
  for idx_corr, corrected_sent in enumerate(root.iterfind(f"{NAMESPACE}linkGrp")):
189
- involved_sents = corrected_sent.attrib["corresp"].split(" ")
190
  # Involved sentences according to the IDs of token mappings - 'corresp' does not list all of them!
191
  # (possible bug in data)
192
  involved_src_sents, involved_tgt_sents = find_involved_sents(corrected_sent)
@@ -261,3 +269,89 @@ class Solar3(datasets.GeneratorBasedBuilder):
261
  "tgt_tokens": tgt_sent_data.get("form", []),
262
  "corrections": corr_data
263
  }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
2
  import os
3
  import re
4
  import xml.etree.ElementTree as ET
5
+ from itertools import groupby
6
  from typing import Optional
7
 
8
  import datasets
 
20
  _DESCRIPTION = """\
21
  Šolar is a developmental corpus of 5485 school texts (e.g., essays), written by students in Slovenian secondary schools
22
  (age 15-19) and pupils in the 7th-9th grade of primary school (13-15), with a small percentage also from the 6th grade.
23
+ Part of the corpus (1516 texts) is annotated with teachers' corrections using a system of labels described in the
24
  document available at https://www.clarin.si/repository/xmlui/bitstream/handle/11356/1589/Smernice-za-oznacevanje-korpusa-Solar_V1.1.pdf (in Slovenian).
25
  """
26
 
 
132
  """Šolar is a developmental corpus of school texts (e.g., essays), annotated with metadata and (partially)
133
  with teachers' corrections. """
134
 
135
+ VERSION = datasets.Version("3.0.1")
136
+
137
+ BUILDER_CONFIGS = [
138
+ datasets.BuilderConfig(name="sentence_level", version=VERSION,
139
+ description="Annotations at sentence-level."),
140
+ datasets.BuilderConfig(name="document_level", version=VERSION,
141
+ description="Annotations at document-level."),
142
+ ]
143
+
144
+ DEFAULT_CONFIG_NAME = "sentence_level" # default = annotations as provided in the original data
145
 
146
  def _info(self):
147
  features = datasets.Features(
 
149
  "id_doc": datasets.Value("string"),
150
  "doc_title": datasets.Value("string"),
151
  "is_manually_validated": datasets.Value("bool"),
 
152
  "src_tokens": datasets.Sequence(datasets.Value("string")),
 
153
  "tgt_tokens": datasets.Sequence(datasets.Value("string")),
154
  "corrections": [
155
  {
 
185
  )
186
  ]
187
 
188
+ @staticmethod
189
+ def generate_sentences(source_path, target_path, links_path):
190
  source_data = read_data(source_path)
191
  target_data = read_data(target_path)
192
 
 
195
  NAMESPACE = namespace(root)
196
 
197
  for idx_corr, corrected_sent in enumerate(root.iterfind(f"{NAMESPACE}linkGrp")):
 
198
  # Involved sentences according to the IDs of token mappings - 'corresp' does not list all of them!
199
  # (possible bug in data)
200
  involved_src_sents, involved_tgt_sents = find_involved_sents(corrected_sent)
 
269
  "tgt_tokens": tgt_sent_data.get("form", []),
270
  "corrections": corr_data
271
  }
272
+
273
+ @staticmethod
274
+ def aggregate_docs(sent_level_data):
275
+ # NOTE: assuming here that `sent_level_data` is pre-sorted by id_doc, which is done in the raw data
276
+ for idx_doc, (curr_id, curr_group) in enumerate(groupby(sent_level_data, key=lambda tup: tup[1]["id_doc"])):
277
+ curr_instances = map(lambda tup: tup[1], curr_group) # remove the redundant index info from datasets
278
+
279
+ src_tokens, tgt_tokens, mapped_corrections = [], [], []
280
+ seen_src_tokens, seen_tgt_tokens = {}, {}
281
+ # Need to keep the current base position of source and target tokens AND previous base position:
282
+ # A source may map into multiple targets (or vice versa), but we do not want to write it twice in a doc.
283
+ # Therefore, when the same sentence is encountered twice, the base is shifted to the previous one to map
284
+ # the indices of corrected tokens correctly.
285
+ src_base, tgt_base = 0, 0
286
+ prev_src_base, prev_tgt_base = 0, 0
287
+
288
+ doc_title, is_validated = None, None
289
+ for curr_inst in curr_instances:
290
+ doc_title, is_validated = curr_inst["doc_title"], curr_inst["is_manually_validated"]
291
+
292
+ id_src_toks, id_tgt_toks = curr_inst["id_src_tokens"], curr_inst["id_tgt_tokens"]
293
+ curr_src_toks, curr_tgt_toks = curr_inst["src_tokens"], curr_inst["tgt_tokens"]
294
+ curr_corrs = curr_inst["corrections"]
295
+
296
+ num_added_src, num_added_tgt = 0, 0
297
+ for id_tok, tok in zip(id_src_toks, curr_src_toks):
298
+ if id_tok not in seen_src_tokens:
299
+ src_tokens.append(tok)
300
+ seen_src_tokens[id_tok] = tok
301
+ num_added_src += 1
302
+
303
+ for id_tok, tok in zip(id_tgt_toks, curr_tgt_toks):
304
+ if id_tok not in seen_tgt_tokens:
305
+ tgt_tokens.append(tok)
306
+ seen_tgt_tokens[id_tok] = tok
307
+ num_added_tgt += 1
308
+
309
+ if num_added_src == 0:
310
+ src_base, prev_src_base = prev_src_base, src_base
311
+
312
+ if num_added_tgt == 0:
313
+ tgt_base, prev_tgt_base = prev_tgt_base, tgt_base
314
+
315
+ for corr in curr_corrs:
316
+ mapped_corrections.append({
317
+ "idx_src": list(map(lambda _i: src_base + _i, corr["idx_src"])),
318
+ "idx_tgt": list(map(lambda _i: tgt_base + _i, corr["idx_tgt"])),
319
+ "corr_types": corr["corr_types"]
320
+ })
321
+
322
+ # TODO: sanity check
323
+ for _idx_src in mapped_corrections[-1]["idx_src"]:
324
+ if _idx_src >= len(src_tokens):
325
+ raise ValueError
326
+
327
+ for _idx_tgt in mapped_corrections[-1]["idx_tgt"]:
328
+ if _idx_tgt >= len(tgt_tokens):
329
+ raise ValueError
330
+
331
+ src_base += num_added_src
332
+ tgt_base += num_added_tgt
333
+
334
+ if num_added_src == 0:
335
+ src_base, prev_src_base = prev_src_base, src_base
336
+
337
+ if num_added_tgt == 0:
338
+ tgt_base, prev_tgt_base = prev_tgt_base, tgt_base
339
+
340
+ yield idx_doc, {
341
+ "id_doc": curr_id,
342
+ "doc_title": doc_title,
343
+ "is_manually_validated": is_validated,
344
+ "src_tokens": src_tokens,
345
+ "tgt_tokens": tgt_tokens,
346
+ "corrections": mapped_corrections
347
+ }
348
+
349
+ def _generate_examples(self, source_path, target_path, links_path):
350
+ sent_level_data = list(Solar3.generate_sentences(source_path, target_path, links_path))
351
+
352
+ if self.config.name == "sentence_level":
353
+ # Remove IDs that are only useful for aggregating the document-level data
354
+ for i, instance in sent_level_data:
355
+ yield i, {_k: _v for _k, _v in instance.items() if _k not in {"id_src_tokens", "id_tgt_tokens"}}
356
+ else:
357
+ yield from list(Solar3.aggregate_docs(sent_level_data))