vontonkin commited on
Commit
bd27973
1 Parent(s): 82079c2

Upload europarl_doc.py

Browse files
Files changed (1) hide show
  1. europarl_doc.py +73 -0
europarl_doc.py ADDED
@@ -0,0 +1,73 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import os
2
+ import json
3
+ import datasets
4
+ from huggingface_hub import hf_hub_url
5
+
6
+ _BASE_URL = hf_hub_url("TrustHLT/europarl_doc", filename="europarl_doc.tar.gz", repo_type="dataset")
7
+
8
+ class Europarl(datasets.GeneratorBasedBuilder):
9
+ VERSION = datasets.Version("1.0.0")
10
+
11
+ def _info(self):
12
+ features = datasets.Features(
13
+ {
14
+ "translation": {
15
+ "file": datasets.Value("string"),
16
+ "name": datasets.Value("string"),
17
+ "en": datasets.Value("string"),
18
+ "de": datasets.Value("string"),
19
+ }
20
+ }
21
+ )
22
+ return datasets.DatasetInfo(
23
+ features=features,
24
+ supervised_keys=None,
25
+ )
26
+
27
+ def _split_generators(self, dl_manager):
28
+ """Returns SplitGenerators."""
29
+ data_dir = dl_manager.download_and_extract(_BASE_URL)
30
+
31
+ path = {
32
+ "train": data_dir + "/europarl-doc-train-v10.de-en.json",
33
+ "dev": data_dir + "/europarl-doc-val-v10.de-en.json",
34
+ "test": data_dir + "/europarl-doc-test-v10.de-en.json",
35
+ }
36
+
37
+ return [
38
+ datasets.SplitGenerator(
39
+ name=datasets.Split.TRAIN,
40
+ gen_kwargs={
41
+ "filepath": path["train"],
42
+ "split": "train",
43
+ },
44
+ ),
45
+ datasets.SplitGenerator(
46
+ name=datasets.Split.TEST,
47
+ gen_kwargs={
48
+ "filepath": path["test"],
49
+ "split": "test"
50
+ },
51
+ ),
52
+ datasets.SplitGenerator(
53
+ name=datasets.Split.VALIDATION,
54
+ gen_kwargs={
55
+ "filepath": path["dev"],
56
+ "split": "dev",
57
+ },
58
+ ),
59
+ ]
60
+
61
+ def _generate_examples(self, filepath):
62
+ """Yields examples."""
63
+ with open(filepath, encoding="utf-8") as f:
64
+ data = json.load(f)
65
+ for idx, sentence in enumerate(data):
66
+ yield idx, {
67
+ "translation": {
68
+ "file": sentence["file"],
69
+ "name": sentence["name"],
70
+ "en": sentence["en"],
71
+ "de": sentence["de"],
72
+ }
73
+ }