AmineNumeric commited on
Commit
aa0d90a
1 Parent(s): 0654704

Upload folder using huggingface_hub

Browse files
Files changed (4) hide show
  1. data/test.json +0 -0
  2. data/train.json +0 -0
  3. data/validation.json +0 -0
  4. zindi_translate.py +132 -0
data/test.json ADDED
The diff for this file is too large to render. See raw diff
 
data/train.json ADDED
The diff for this file is too large to render. See raw diff
 
data/validation.json ADDED
The diff for this file is too large to render. See raw diff
 
zindi_translate.py ADDED
@@ -0,0 +1,132 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import csv
2
+ import json
3
+ import os
4
+ import datasets
5
+
6
+ # TODO: Add BibTeX citation
7
+ # Find for instance the citation on arxiv or on the dataset repo/website
8
+ _CITATION = """\
9
+ @InProceedings{huggingface:dataset,
10
+ title = {Dataset to train specialized translation model},
11
+ author={huggingface, Inc.
12
+ },
13
+ year={2024}
14
+ }
15
+ """
16
+
17
+ # TODO: Add description of the dataset here
18
+ # You can copy an official description
19
+ _DESCRIPTION = """\
20
+ This dataset has different translation examples from the ivorycost language dyu to frensh.
21
+ """
22
+
23
+ # TODO: Add a link to an official homepage for the dataset here
24
+ _HOMEPAGE = ""
25
+
26
+ # TODO: Add the licence for the dataset here if you can find it
27
+ _LICENSE = ""
28
+
29
+ # TODO: Add link to the official dataset URLs here
30
+ # The HuggingFace Datasets library doesn't host the datasets but only points to the original files.
31
+ # This can be an arbitrary nested dict/list of URLs (see below in `_split_generators` method)
32
+ _URL = "./data/"
33
+ _URLS = {
34
+ "train": _URL + "train.json",
35
+ "test": _URL + "test.json",
36
+ "dev": _URL + "dev.json",
37
+ }
38
+ # TODO: Name of the dataset usually matches the script name with CamelCase instead of snake_case
39
+ class ZindiTranslate(datasets.GeneratorBasedBuilder):
40
+ """TODO: Short description of my dataset."""
41
+
42
+ VERSION = datasets.Version("1.1.0")
43
+
44
+ # This is an example of a dataset with multiple configurations.
45
+ # If you don't want/need to define several sub-sets in your dataset,
46
+ # just remove the BUILDER_CONFIG_CLASS and the BUILDER_CONFIGS attributes.
47
+
48
+ # If you need to make complex sub-parts in the datasets with configurable options
49
+ # You can create your own builder configuration class to store attribute, inheriting from datasets.BuilderConfig
50
+ # BUILDER_CONFIG_CLASS = MyBuilderConfig
51
+
52
+ # You will be able to load one or the other configurations in the following list with
53
+ # data = datasets.load_dataset('my_dataset', 'first_domain')
54
+ # data = datasets.load_dataset('my_dataset', 'second_domain')
55
+ BUILDER_CONFIGS = [
56
+ datasets.BuilderConfig(name="fr--->dyu", version=VERSION, description="Translation fr --> dyu"),
57
+
58
+ ]
59
+
60
+ DEFAULT_CONFIG_NAME = "fr--->dyu" # It's not mandatory to have a default configuration. Just use one if it make sense.
61
+
62
+ def _info(self):
63
+ # TODO: This method specifies the datasets.DatasetInfo object which contains informations and typings for the dataset
64
+ if self.config.name =="fr--->dyu" : # This is the name of the configuration selected in BUILDER_CONFIGS above
65
+ features = datasets.features.Translation(['dyu', 'fr'] )
66
+
67
+ return datasets.DatasetInfo(
68
+ # This is the description that will appear on the datasets page.
69
+ description=_DESCRIPTION,
70
+ # This defines the different columns of the dataset and their types
71
+ features=features, # Here we define them above because they are different between the two configurations
72
+ # If there's a common (input, target) tuple from the features, uncomment supervised_keys line below and
73
+ # specify them. They'll be used if as_supervised=True in builder.as_dataset.
74
+ # supervised_keys=("sentence", "label"),
75
+ # Homepage of the dataset for documentation
76
+ homepage=_HOMEPAGE,
77
+ # License for the dataset if available
78
+ license=_LICENSE,
79
+ # Citation for the dataset
80
+ citation=_CITATION,
81
+ )
82
+
83
+ def _split_generators(self, dl_manager):
84
+ # TODO: This method is tasked with downloading/extracting the data and defining the splits depending on the configuration
85
+ # If several configurations are possible (listed in BUILDER_CONFIGS), the configuration selected by the user is in self.config.name
86
+
87
+ # dl_manager is a datasets.download.DownloadManager that can be used to download and extract URLS
88
+ # It can accept any type or nested list/dict and will give back the same structure with the url replaced with path to local files.
89
+ # By default the archives will be extracted and a path to a cached folder where they are extracted is returned instead of the archive
90
+ urls = _URLS
91
+ data_dir = dl_manager.download_and_extract(urls)
92
+ return [
93
+ datasets.SplitGenerator(
94
+ name=datasets.Split.TRAIN,
95
+ # These kwargs will be passed to _generate_examples
96
+ gen_kwargs={
97
+ "filepath": os.path.join(data_dir, "train.json"),
98
+ "split": "train",
99
+ },
100
+ ),
101
+ datasets.SplitGenerator(
102
+ name=datasets.Split.VALIDATION,
103
+ # These kwargs will be passed to _generate_examples
104
+ gen_kwargs={
105
+ "filepath": os.path.join(data_dir, "dev.json"),
106
+ "split": "dev",
107
+ },
108
+ ),
109
+ datasets.SplitGenerator(
110
+ name=datasets.Split.TEST,
111
+ # These kwargs will be passed to _generate_examples
112
+ gen_kwargs={
113
+ "filepath": os.path.join(data_dir, "test.json"),
114
+ "split": "test"
115
+ },
116
+ ),
117
+ ]
118
+
119
+ # method parameters are unpacked from `gen_kwargs` as given in `_split_generators`
120
+ def _generate_examples(self, filepath, split):
121
+ # TODO: This method handles input defined in _split_generators to yield (key, example) tuples from the dataset.
122
+ # The `key` is for legacy reasons (tfds) and is not important in itself, but must be unique for each example.
123
+ with open(filepath, encoding="utf-8") as f:
124
+ data = json.load(f)
125
+ if self.config.name == "fr--->dyu":
126
+ for trans in data:
127
+ # Yields examples as (key, example) tuples
128
+ id_=trans["ID"]
129
+ translation=trans["translation"]
130
+ yield id_, {
131
+ "translation":translation,
132
+ }