albertvillanova HF staff commited on
Commit
22be71f
1 Parent(s): 116b77d

Support streaming UDHR dataset (#4487)

Browse files

* Support streaming udhr dataset

* Add BCP 47 language ID

* Update homepage

* Update dataset card

* Update metadata JSON

* Update dummy data

* Remove unused import

Commit from https://github.com/huggingface/datasets/commit/dc41a8821afac7efa0db66be2e11e2e78ffc31d6

Files changed (4) hide show
  1. README.md +9 -4
  2. dataset_infos.json +1 -1
  3. dummy/1.0.0/dummy_data.zip +2 -2
  4. udhr.py +21 -29
README.md CHANGED
@@ -501,7 +501,7 @@ pretty_name: The Universal Declaration of Human Rights (UDHR)
501
 
502
  ## Dataset Description
503
 
504
- - **Homepage:** https://www.ohchr.org/EN/UDHR/Pages/UDHRIndex.aspx, https://unicode.org/udhr/index.html
505
  - **Repository:** https://github.com/unicode-org/udhr
506
  - **Paper:**
507
  - **Leaderboard:**
@@ -516,7 +516,7 @@ Assembly in Paris on 10 December 1948 during its 183rd plenary meeting.
516
 
517
  © 1996 – 2009 The Office of the High Commissioner for Human Rights
518
 
519
- This plain text version prepared by the UDHR in Unicode project, https://www.unicode.org/udhr.
520
 
521
  ### Supported Tasks and Leaderboards
522
 
@@ -536,16 +536,21 @@ text.
536
 
537
  ### Data Fields
538
 
539
- - `text`: The full document text with each line of text delimitted by a newline (`\n`).
540
  - `lang_key`: The unique identifier of a given translation.
541
  - `lang_name`: The textual description of language/dialect.
542
  - `iso639-3`: The [iso639-3](https://iso639-3.sil.org/) language identifier.
543
  - `iso15924`: The [iso15924](https://unicode.org/iso15924/iso15924-codes.html) language identifier.
 
544
 
545
  ### Data Splits
546
 
547
  Only a `train` split included which includes the full document in all languages.
548
 
 
 
 
 
549
  ## Dataset Creation
550
 
551
  ### Curation Rationale
@@ -583,7 +588,7 @@ document in the world and as such can be useful for settings requiring paired te
583
 
584
  In addition to the social and political significance of the United Nations' Universal Declaration of Human Rights,
585
  the document set a world record in 1999 for being the most translated document in the world and as such can be useful
586
- for settings requiring paired text between many languagers including those that are low resource and significantly
587
  underrepresented in NLP research.
588
 
589
  ### Discussion of Biases
 
501
 
502
  ## Dataset Description
503
 
504
+ - **Homepage:** https://www.ohchr.org/en/universal-declaration-of-human-rights, https://unicode.org/udhr/index.html
505
  - **Repository:** https://github.com/unicode-org/udhr
506
  - **Paper:**
507
  - **Leaderboard:**
 
516
 
517
  © 1996 – 2009 The Office of the High Commissioner for Human Rights
518
 
519
+ This plain text version prepared by the "UDHR in Unicode" project, https://www.unicode.org/udhr.
520
 
521
  ### Supported Tasks and Leaderboards
522
 
 
536
 
537
  ### Data Fields
538
 
539
+ - `text`: The full document text with each line of text delimited by a newline (`\n`).
540
  - `lang_key`: The unique identifier of a given translation.
541
  - `lang_name`: The textual description of language/dialect.
542
  - `iso639-3`: The [iso639-3](https://iso639-3.sil.org/) language identifier.
543
  - `iso15924`: The [iso15924](https://unicode.org/iso15924/iso15924-codes.html) language identifier.
544
+ - `bcp47`: The [BCP 47](https://www.rfc-editor.org/info/bcp47) language identifier.
545
 
546
  ### Data Splits
547
 
548
  Only a `train` split included which includes the full document in all languages.
549
 
550
+ | | train |
551
+ |--------------------|------:|
552
+ | Number of examples | 488 |
553
+
554
  ## Dataset Creation
555
 
556
  ### Curation Rationale
 
588
 
589
  In addition to the social and political significance of the United Nations' Universal Declaration of Human Rights,
590
  the document set a world record in 1999 for being the most translated document in the world and as such can be useful
591
+ for settings requiring paired text between many languages including those that are low resource and significantly
592
  underrepresented in NLP research.
593
 
594
  ### Discussion of Biases
dataset_infos.json CHANGED
@@ -1 +1 @@
1
- {"default": {"description": "The Universal Declaration of Human Rights (UDHR) is a milestone document in the history of human rights. Drafted by\nrepresentatives with different legal and cultural backgrounds from all regions of the world, it set out, for the\nfirst time, fundamental human rights to be universally protected. The Declaration was adopted by the UN General\nAssembly in Paris on 10 December 1948 during its 183rd plenary meeting. The dataset includes translations of the\ndocument in 464 languages and dialects.\n\n\u00a9 1996 \u2013 2009 The Office of the High Commissioner for Human Rights\n\nThis plain text version prepared by the \u201cUDHR in Unicode\u201d project, https://www.unicode.org/udhr.\n", "citation": "", "homepage": "https://www.ohchr.org/EN/UDHR/Pages/UDHRIndex.aspx", "license": "", "features": {"text": {"dtype": "string", "id": null, "_type": "Value"}, "lang_key": {"dtype": "string", "id": null, "_type": "Value"}, "lang_name": {"dtype": "string", "id": null, "_type": "Value"}, "iso639-3": {"dtype": "string", "id": null, "_type": "Value"}, "iso15924": {"dtype": "string", "id": null, "_type": "Value"}}, "post_processed": null, "supervised_keys": null, "task_templates": null, "builder_name": "udhn", "config_name": "default", "version": {"version_str": "1.0.0", "description": null, "major": 1, "minor": 0, "patch": 0}, "splits": {"train": {"name": "train", "num_bytes": 6749909, "num_examples": 488, "dataset_name": "udhn"}}, "download_checksums": {"https://unicode.org/udhr/assemblies/udhr_xml.zip": {"num_bytes": 2389690, "checksum": "a3350912790196c6e1b26bfd1c8a50e8575f5cf185922ecd9bd15713d7d21438"}, "https://unicode.org/udhr/assemblies/udhr_txt.zip": {"num_bytes": 2215441, "checksum": "cb87ecb25b56f34e4fd6f22b323000524fd9c06ae2a29f122b048789cf17e9fe"}}, "download_size": 4605131, "post_processing_size": null, "dataset_size": 6749909, "size_in_bytes": 11355040}}
 
1
+ {"default": {"description": "The Universal Declaration of Human Rights (UDHR) is a milestone document in the history of human rights. Drafted by\nrepresentatives with different legal and cultural backgrounds from all regions of the world, it set out, for the\nfirst time, fundamental human rights to be universally protected. The Declaration was adopted by the UN General\nAssembly in Paris on 10 December 1948 during its 183rd plenary meeting. The dataset includes translations of the\ndocument in 464+ languages and dialects.\n\n\u00a9 1996 \u2013 2009 The Office of the High Commissioner for Human Rights\n\nThis plain text version prepared by the \u201cUDHR in Unicode\u201d project, https://www.unicode.org/udhr.\n", "citation": "", "homepage": "https://www.ohchr.org/en/universal-declaration-of-human-rights", "license": "", "features": {"text": {"dtype": "string", "id": null, "_type": "Value"}, "lang_key": {"dtype": "string", "id": null, "_type": "Value"}, "lang_name": {"dtype": "string", "id": null, "_type": "Value"}, "iso639-3": {"dtype": "string", "id": null, "_type": "Value"}, "iso15924": {"dtype": "string", "id": null, "_type": "Value"}, "bcp47": {"dtype": "string", "id": null, "_type": "Value"}}, "post_processed": null, "supervised_keys": null, "task_templates": null, "builder_name": "udhr", "config_name": "default", "version": {"version_str": "1.0.0", "description": null, "major": 1, "minor": 0, "patch": 0}, "splits": {"train": {"name": "train", "num_bytes": 6753383, "num_examples": 488, "dataset_name": "udhr"}}, "download_checksums": {"https://unicode.org/udhr/assemblies/udhr_xml.zip": {"num_bytes": 2389690, "checksum": "a3350912790196c6e1b26bfd1c8a50e8575f5cf185922ecd9bd15713d7d21438"}}, "download_size": 2389690, "post_processing_size": null, "dataset_size": 6753383, "size_in_bytes": 9143073}}
dummy/1.0.0/dummy_data.zip CHANGED
@@ -1,3 +1,3 @@
1
  version https://git-lfs.github.com/spec/v1
2
- oid sha256:19063b07d325e85347e7f9ad82e55a8db619e739784ec6613049ce51d98ced17
3
- size 11931
 
1
  version https://git-lfs.github.com/spec/v1
2
+ oid sha256:0ee4681ffc0c16a7f1ff227cc8e9c5eda924c9d7ce1b78184b01f60265baf542
3
+ size 6205
udhr.py CHANGED
@@ -17,7 +17,6 @@
17
  """Universal Declaration of Human Rights"""
18
 
19
 
20
- import glob
21
  import os
22
  import xml.etree.ElementTree as ET
23
 
@@ -36,11 +35,9 @@ document in 464+ languages and dialects.
36
  This plain text version prepared by the “UDHR in Unicode” project, https://www.unicode.org/udhr.
37
  """
38
 
39
- _WEBPAGE = "https://www.ohchr.org/EN/UDHR/Pages/UDHRIndex.aspx"
40
 
41
- # XML for meta-info about language and TXT for text
42
- _XML_DOWNLOAD_URL = "https://unicode.org/udhr/assemblies/udhr_xml.zip"
43
- _TXT_DOWNLOAD_URL = "https://unicode.org/udhr/assemblies/udhr_txt.zip"
44
 
45
 
46
  class UDHN(datasets.GeneratorBasedBuilder):
@@ -58,36 +55,31 @@ class UDHN(datasets.GeneratorBasedBuilder):
58
  "lang_name": datasets.Value("string"),
59
  "iso639-3": datasets.Value("string"),
60
  "iso15924": datasets.Value("string"),
 
61
  }
62
  ),
63
- homepage=_WEBPAGE,
64
  )
65
 
66
  def _split_generators(self, dl_manager):
67
- xml_dir = dl_manager.download_and_extract(_XML_DOWNLOAD_URL)
68
- txt_dir = dl_manager.download_and_extract(_TXT_DOWNLOAD_URL)
69
 
70
  return [
71
- datasets.SplitGenerator(name=datasets.Split.TRAIN, gen_kwargs={"xml_dir": xml_dir, "txt_dir": txt_dir}),
 
 
72
  ]
73
 
74
- def _generate_examples(self, xml_dir, txt_dir):
75
- xml_paths = glob.glob(os.path.join(xml_dir, "udhr_*.xml"))
76
- for i, xml_path in enumerate(xml_paths):
77
- lang_attr = ET.parse(xml_path).getroot().attrib
78
- lang = lang_attr["key"]
79
-
80
- txt_path = os.path.join(txt_dir, f"udhr_{lang}.txt")
81
- assert os.path.exists(txt_path), f"xml file {xml_path} found with no corresponding txt file"
82
-
83
- with open(txt_path, "r", encoding="utf-8") as f:
84
- lines = f.readlines()[6:] # ignore first 6 lines (metainfo)
85
- text = "\n".join([line.strip() for line in lines if len(line.strip()) > 0])
86
-
87
- yield i, {
88
- "text": text,
89
- "lang_key": lang,
90
- "lang_name": lang_attr["n"],
91
- "iso639-3": lang_attr["iso639-3"],
92
- "iso15924": lang_attr["iso15924"],
93
- }
 
17
  """Universal Declaration of Human Rights"""
18
 
19
 
 
20
  import os
21
  import xml.etree.ElementTree as ET
22
 
 
35
  This plain text version prepared by the “UDHR in Unicode” project, https://www.unicode.org/udhr.
36
  """
37
 
38
+ _HOMEPAGE = "https://www.ohchr.org/en/universal-declaration-of-human-rights"
39
 
40
+ _URL = "https://unicode.org/udhr/assemblies/udhr_xml.zip"
 
 
41
 
42
 
43
  class UDHN(datasets.GeneratorBasedBuilder):
 
55
  "lang_name": datasets.Value("string"),
56
  "iso639-3": datasets.Value("string"),
57
  "iso15924": datasets.Value("string"),
58
+ "bcp47": datasets.Value("string"),
59
  }
60
  ),
61
+ homepage=_HOMEPAGE,
62
  )
63
 
64
  def _split_generators(self, dl_manager):
65
+ dl_dir = dl_manager.download_and_extract(_URL)
 
66
 
67
  return [
68
+ datasets.SplitGenerator(
69
+ name=datasets.Split.TRAIN, gen_kwargs={"file_paths": dl_manager.iter_files(dl_dir)}
70
+ ),
71
  ]
72
 
73
+ def _generate_examples(self, file_paths):
74
+ for id_, path in enumerate(file_paths):
75
+ if os.path.basename(path).startswith("udhr_"):
76
+ root = ET.parse(path).getroot()
77
+ text = "\n".join([line.strip() for line in root.itertext() if line.strip()])
78
+ yield id_, {
79
+ "text": text,
80
+ "lang_key": root.get("key"),
81
+ "lang_name": root.get("n"),
82
+ "iso639-3": root.get("iso639-3"),
83
+ "iso15924": root.get("iso15924"),
84
+ "bcp47": root.get("{http://www.w3.org/XML/1998/namespace}lang"),
85
+ }