bibles / bibles.py
versae's picture
Adding year, century, and codebook
e2a3eb5
raw
history blame
7.23 kB
# coding=utf-8
# Copyright 2020 The HuggingFace Datasets Authors and the current dataset script contributor.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
"""Multilingual Bibles"""
import csv
import datasets
_CITATION = """
@InProceedings{--,
author = {---},
title = {---},
booktitle = {---},
year = 2021,
address = "---"
}
"""
_DESCRIPTION = """\
Multilingual Bibles
"""
_HOMEPAGE = "https://github.com/versae/bibles/"
BIBLES_BASE_URI = "https://huggingface.co/datasets/versae/bibles/resolve/main"
BIBLES = {
"validation": lambda config: f"{BIBLES_BASE_URI}/{config}_validation.csv",
"test": lambda config: f"{BIBLES_BASE_URI}/{config}_test.csv",
"train": lambda config: f"{BIBLES_BASE_URI}/{config}_train.csv"
}
class BiblesConfig(datasets.BuilderConfig):
"""BuilderConfig for NorNE."""
def __init__(self, **kwargs):
"""BuilderConfig for Bibles.
Args:
**kwargs: keyword arguments forwarded to super.
"""
super(BiblesConfig, self).__init__(**kwargs)
class Bibles(datasets.GeneratorBasedBuilder):
"""Bibles"""
BUILDER_CONFIGS = [
BiblesConfig(name="testament", version=datasets.Version("1.0.0"), description="Bibles testament dataset (full set)"),
BiblesConfig(name="genre", version=datasets.Version("1.0.0"), description="Bibles genre dataset (full set)"),
BiblesConfig(name="division", version=datasets.Version("1.0.0"), description="Bibles division dataset (full set)"),
]
def _info(self):
if self.config.name == "division":
labels = [
'Gospel',
'Historical',
'Letters',
'Pentateuch',
'Prophetic',
'Revelation',
'Wisdom'
]
languages = [
'ALB',
'ARA',
'AZB',
'BEL',
'BUL',
'CEB',
'CHI',
'CZE',
'DAN',
'ENG',
'ESP',
'FIN',
'FRE',
'GER',
'GRC',
'HAT',
'HEB',
'HIN',
'HUN',
'ITA',
'KOR',
'LAT',
'MAR',
'NL_',
'NOR',
'POR',
'RUM',
'RUS',
'SCR',
'SPA',
'SWE',
'TAM',
'TGL',
'THA',
'TUR',
'VIE',
'XKL',
]
elif self.config.name == "genre":
labels = [
'apocalyptic',
'gospel',
'historical',
'law',
'letter',
'lyric',
'prophecy',
'wisdom'
]
languages = [
'ALB',
'ARA',
'AZB',
'BEL',
'BUL',
'CEB',
'CHI',
'CZE',
'DAN',
'ENG',
'ESP',
'FIN',
'FRE',
'GER',
'GRC',
'HAT',
'HEB',
'HIN',
'HUN',
'ITA',
'KOR',
'LAT',
'MAR',
'NL_',
'NOR',
'POR',
'RUM',
'RUS',
'SCR',
'SPA',
'SWE',
'TAM',
'TGL',
'THA',
'TUR',
'VIE',
'XKL',
]
else: # self.config.name == "testament":
labels = ["new", "old"]
languages = [
'ALB',
'ARA',
'AZB',
'BEL',
'BUL',
'CEB',
'CHA',
'CHI',
'CZE',
'DAN',
'ENG',
'ESP',
'FIN',
'FRE',
'GER',
'GRC',
'HAT',
'HEB',
'HIN',
'HUN',
'ITA',
'KOR',
'LAT',
'MAR',
'NDS',
'NL_',
'NOR',
'PON',
'POR',
'RUM',
'RUS',
'SCR',
'SPA',
'SWE',
'TAM',
'TGL',
'THA',
'TUR',
'VIE',
'XKL',
]
self.labels = labels
return datasets.DatasetInfo(
description=_DESCRIPTION,
features=datasets.Features(
{
"text": datasets.Value("string"),
"label": datasets.ClassLabel(names=labels),
"language": datasets.Value("string"),
"year": datasets.Value("int16"),
"century": datasets.Value("string"),
"codebook": datasets.Value("string"),
}
),
supervised_keys=None,
homepage=_HOMEPAGE,
citation=_CITATION,
)
def _split_generators(self, dl_manager):
URLS = {key: BIBLES[key](self.config.name) for key in BIBLES.keys()}
downloaded_files = dl_manager.download(URLS)
return [
datasets.SplitGenerator(name=datasets.Split.TRAIN, gen_kwargs={"filepath": downloaded_files["train"]}),
datasets.SplitGenerator(name=datasets.Split.VALIDATION, gen_kwargs={"filepath": downloaded_files["validation"]}),
datasets.SplitGenerator(name=datasets.Split.TEST, gen_kwargs={"filepath": downloaded_files["test"]}),
]
def _generate_examples(self, filepath):
with open(filepath, encoding="utf-8") as csv_file:
csv_reader = csv.reader(csv_file, delimiter=",")
next(csv_reader) # skip header
for idx, (text, label, language, year, century, codebook) in enumerate(csv_reader):
yield int(idx), {
"text": text,
"label": self.labels.index(label),
"language": language,
"year": year,
"century": century,
"codebook": codebook,
}