Datasets:
License:
Matīss
commited on
Commit
•
a88cc29
1
Parent(s):
13d6772
Upload liv4ever.py
Browse files- liv4ever.py +139 -0
liv4ever.py
ADDED
@@ -0,0 +1,139 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
# coding=utf-8
|
2 |
+
# Copyright 2020 The HuggingFace Datasets Authors and the current dataset script contributor.
|
3 |
+
#
|
4 |
+
# Licensed under the Apache License, Version 2.0 (the "License");
|
5 |
+
# you may not use this file except in compliance with the License.
|
6 |
+
# You may obtain a copy of the License at
|
7 |
+
#
|
8 |
+
# http://www.apache.org/licenses/LICENSE-2.0
|
9 |
+
#
|
10 |
+
# Unless required by applicable law or agreed to in writing, software
|
11 |
+
# distributed under the License is distributed on an "AS IS" BASIS,
|
12 |
+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
13 |
+
# See the License for the specific language governing permissions and
|
14 |
+
# limitations under the License.
|
15 |
+
"""Liv4ever dataset."""
|
16 |
+
|
17 |
+
|
18 |
+
import json
|
19 |
+
|
20 |
+
import datasets
|
21 |
+
|
22 |
+
|
23 |
+
_CITATION = """\
|
24 |
+
@inproceedings{rikters-etal-2022,
|
25 |
+
title = "Machine Translation for Livonian: Catering for 20 Speakers",
|
26 |
+
author = "Rikters, Matīss and
|
27 |
+
Tomingas, Marili and
|
28 |
+
Tuisk, Tuuli and
|
29 |
+
Valts, Ernštreits and
|
30 |
+
Fishel, Mark",
|
31 |
+
booktitle = "Proceedings of ACL 2022",
|
32 |
+
year = "2022",
|
33 |
+
address = "Dublin, Ireland",
|
34 |
+
publisher = "Association for Computational Linguistics"
|
35 |
+
}
|
36 |
+
"""
|
37 |
+
|
38 |
+
|
39 |
+
_DESCRIPTION = """\
|
40 |
+
Livonian is one of the most endangered languages in Europe with just a tiny handful of speakers and virtually no publicly available corpora.
|
41 |
+
In this paper we tackle the task of developing neural machine translation (NMT) between Livonian and English, with a two-fold aim: on one hand,
|
42 |
+
preserving the language and on the other – enabling access to Livonian folklore, lifestories and other textual intangible heritage as well as
|
43 |
+
making it easier to create further parallel corpora. We rely on Livonian's linguistic similarity to Estonian and Latvian and collect parallel
|
44 |
+
and monolingual data for the four languages for translation experiments. We combine different low-resource NMT techniques like zero-shot translation,
|
45 |
+
cross-lingual transfer and synthetic data creation to reach the highest possible translation quality as well as to find which base languages are
|
46 |
+
empirically more helpful for transfer to Livonian. The resulting NMT systems and the collected monolingual and parallel data, including a manually
|
47 |
+
translated and verified translation benchmark, are publicly released.
|
48 |
+
|
49 |
+
Fields:
|
50 |
+
- source: source of the data
|
51 |
+
- en: sentence in English
|
52 |
+
- liv: sentence in Livonian
|
53 |
+
"""
|
54 |
+
|
55 |
+
_HOMEPAGE = "https://huggingface.co/datasets/tartuNLP/liv4ever-data"
|
56 |
+
|
57 |
+
_LICENSE = "CC BY-NC-SA 4.0"
|
58 |
+
|
59 |
+
_REPO = "https://huggingface.co/datasets/tartuNLP/liv4ever/raw/main/"
|
60 |
+
|
61 |
+
_URLs = {
|
62 |
+
"train": _REPO + "train.json",
|
63 |
+
"dev": _REPO + "dev.json",
|
64 |
+
"test": _REPO + "test.json",
|
65 |
+
}
|
66 |
+
|
67 |
+
|
68 |
+
class liv4ever(datasets.GeneratorBasedBuilder):
|
69 |
+
"""Liv4ever dataset."""
|
70 |
+
|
71 |
+
VERSION = datasets.Version("1.0.0")
|
72 |
+
|
73 |
+
def _info(self):
|
74 |
+
features = datasets.Features(
|
75 |
+
{
|
76 |
+
"source": datasets.Value("string"),
|
77 |
+
"en": datasets.Value("string"),
|
78 |
+
"liv: datasets.Value("string"),
|
79 |
+
}
|
80 |
+
)
|
81 |
+
return datasets.DatasetInfo(
|
82 |
+
description=_DESCRIPTION,
|
83 |
+
features=features,
|
84 |
+
supervised_keys=None,
|
85 |
+
homepage=_HOMEPAGE,
|
86 |
+
license=_LICENSE,
|
87 |
+
citation=_CITATION,
|
88 |
+
)
|
89 |
+
|
90 |
+
def _split_generators(self, dl_manager):
|
91 |
+
"""Returns SplitGenerators."""
|
92 |
+
data_dir = dl_manager.download_and_extract(_URLs)
|
93 |
+
|
94 |
+
return [
|
95 |
+
datasets.SplitGenerator(
|
96 |
+
name=datasets.Split.TRAIN,
|
97 |
+
gen_kwargs={
|
98 |
+
"filepath": data_dir["train"],
|
99 |
+
"split": "train",
|
100 |
+
},
|
101 |
+
),
|
102 |
+
datasets.SplitGenerator(
|
103 |
+
name=datasets.Split.TEST,
|
104 |
+
gen_kwargs={"filepath": data_dir["test"], "split": "test"},
|
105 |
+
),
|
106 |
+
datasets.SplitGenerator(
|
107 |
+
name=datasets.Split.VALIDATION,
|
108 |
+
gen_kwargs={
|
109 |
+
"filepath": data_dir["dev"],
|
110 |
+
"split": "dev",
|
111 |
+
},
|
112 |
+
),
|
113 |
+
]
|
114 |
+
|
115 |
+
def _generate_examples(self, filepath, split):
|
116 |
+
"""Yields examples."""
|
117 |
+
|
118 |
+
with open(filepath, encoding="utf-8") as f:
|
119 |
+
data = json.load(f)
|
120 |
+
|
121 |
+
|
122 |
+
for dialogue in data:
|
123 |
+
source = dialogue["source"]
|
124 |
+
sentences = dialogue["sentences"]
|
125 |
+
|
126 |
+
i=0
|
127 |
+
|
128 |
+
for turn in sentences:
|
129 |
+
i = i+1
|
130 |
+
sent_no = i
|
131 |
+
en = dialogue["en"]
|
132 |
+
liv = dialogue["liv"]
|
133 |
+
|
134 |
+
yield f"{sent_no}", {
|
135 |
+
"no": sent_no,
|
136 |
+
"source": source,
|
137 |
+
"en": en,
|
138 |
+
"liv": liv,
|
139 |
+
}
|