|
import os |
|
import pandas as pd |
|
import glob |
|
|
|
import datasets |
|
|
|
_CITATION = """\ |
|
@misc{shmidman2022introducing, |
|
title={Introducing BEREL: BERT Embeddings for Rabbinic-Encoded Language}, |
|
author={Avi Shmidman and Joshua Guedalia and Shaltiel Shmidman and Cheyn Shmuel Shmidman and Eli Handel and Moshe Koppel}, |
|
year={2022}, |
|
eprint={2208.01875}, |
|
archivePrefix={arXiv}, |
|
primaryClass={cs.CL} |
|
} |
|
""" |
|
|
|
_DESCRIPTION = """\ |
|
This Dataset is a Hugging Face Reflection of the Sefaria Database. |
|
The following is the description of Sefaria from the sefaria.org website: |
|
|
|
Sefaria is home to 3,000 years of Jewish texts. We are a non-profit organization |
|
offering free access to texts, translations, and commentaries so that everyone |
|
can participate in the ongoing process of studying, interpreting, and creating Torah |
|
""" |
|
|
|
_HOMEPAGE = "https://github.com/Sefaria/Sefaria-Export" |
|
_LICENSE = "Each text is licensed separately, so there is no overall license for this repository." |
|
|
|
class Sefaria(datasets.GeneratorBasedBuilder): |
|
VERSION = datasets.Version("1.0.8") |
|
|
|
BUILDER_CONFIGS = [ |
|
datasets.BuilderConfig(name="english", version=VERSION, description="This configuration contains only English texts"), |
|
datasets.BuilderConfig(name="hebrew", version=VERSION, description="This configuration contains only Hebrew texts"), |
|
datasets.BuilderConfig(name="all", version=VERSION, description="This configuration contains both English and Hebrew texts"), |
|
] |
|
|
|
DEFAULT_CONFIG_NAME = "all" |
|
|
|
DATA_URLS = { |
|
"english": ['https://huggingface.co/datasets/mehdie/sefaria/raw/main/data/Chasidut_english.parquet', 'https://huggingface.co/datasets/mehdie/sefaria/raw/main/data/Midrash_english.parquet', 'https://huggingface.co/datasets/mehdie/sefaria/raw/main/data/Apocrypha_english.parquet', 'https://huggingface.co/datasets/mehdie/sefaria/raw/main/data/Halakhah_english.parquet', 'https://huggingface.co/datasets/mehdie/sefaria/raw/main/data/Talmud_english.parquet', 'https://huggingface.co/datasets/mehdie/sefaria/raw/main/data/Mishnah_english.parquet', 'https://huggingface.co/datasets/mehdie/sefaria/raw/main/data/Tanaitic_english.parquet', 'https://huggingface.co/datasets/mehdie/sefaria/raw/main/data/Halakhah_Commentary_english.parquet', 'https://huggingface.co/datasets/mehdie/sefaria/raw/main/data/Philosophy_english.parquet', 'https://huggingface.co/datasets/mehdie/sefaria/raw/main/data/Tanakh_english.parquet', 'https://huggingface.co/datasets/mehdie/sefaria/raw/main/data/Halakhah_Tur_and_Commentaries_english.parquet', 'https://huggingface.co/datasets/mehdie/sefaria/raw/main/data/Halakhah_Mishneh_Torah_english.parquet', 'https://huggingface.co/datasets/mehdie/sefaria/raw/main/data/Modern_Works_english.parquet', 'https://huggingface.co/datasets/mehdie/sefaria/raw/main/data/Responsa_english.parquet', 'https://huggingface.co/datasets/mehdie/sefaria/raw/main/data/Halakhah_Shulchan_Arukh_english.parquet', 'https://huggingface.co/datasets/mehdie/sefaria/raw/main/data/Kabbalah_english.parquet', 'https://huggingface.co/datasets/mehdie/sefaria/raw/main/data/Musar_english.parquet', 'https://huggingface.co/datasets/mehdie/sefaria/raw/main/data/Other_english.parquet', 'https://huggingface.co/datasets/mehdie/sefaria/raw/main/data/Liturgy_english.parquet'], |
|
"hebrew": ['https://huggingface.co/datasets/mehdie/sefaria/raw/main/data/Responsa_hebrew.parquet', 'https://huggingface.co/datasets/mehdie/sefaria/raw/main/data/Halakhah_Mishneh_Torah_hebrew.parquet', 'https://huggingface.co/datasets/mehdie/sefaria/raw/main/data/Kabbalah_hebrew.parquet', 'https://huggingface.co/datasets/mehdie/sefaria/raw/main/data/Halakhah_Commentary_hebrew.parquet', 'https://huggingface.co/datasets/mehdie/sefaria/raw/main/data/Liturgy_hebrew.parquet', 'https://huggingface.co/datasets/mehdie/sefaria/raw/main/data/Tanaitic_hebrew.parquet', 'https://huggingface.co/datasets/mehdie/sefaria/raw/main/data/Halakhah_Shulchan_Arukh_hebrew.parquet', 'https://huggingface.co/datasets/mehdie/sefaria/raw/main/data/Tanakh_hebrew.parquet', 'https://huggingface.co/datasets/mehdie/sefaria/raw/main/data/Mishnah_hebrew.parquet', 'https://huggingface.co/datasets/mehdie/sefaria/raw/main/data/Halakhah_hebrew.parquet', 'https://huggingface.co/datasets/mehdie/sefaria/raw/main/data/Other_hebrew.parquet', 'https://huggingface.co/datasets/mehdie/sefaria/raw/main/data/Halakhah_Tur_and_Commentaries_hebrew.parquet', 'https://huggingface.co/datasets/mehdie/sefaria/raw/main/data/Midrash_hebrew.parquet', 'https://huggingface.co/datasets/mehdie/sefaria/raw/main/data/Modern_Works_hebrew.parquet', 'https://huggingface.co/datasets/mehdie/sefaria/raw/main/data/Chasidut_hebrew.parquet', 'https://huggingface.co/datasets/mehdie/sefaria/raw/main/data/Musar_hebrew.parquet', 'https://huggingface.co/datasets/mehdie/sefaria/raw/main/data/Apocrypha_hebrew.parquet', 'https://huggingface.co/datasets/mehdie/sefaria/raw/main/data/Talmud_hebrew.parquet', 'https://huggingface.co/datasets/mehdie/sefaria/raw/main/data/Philosophy_hebrew.parquet'], |
|
"all": ['https://huggingface.co/datasets/mehdie/sefaria/raw/main/data/Chasidut_english.parquet', 'https://huggingface.co/datasets/mehdie/sefaria/raw/main/data/Midrash_english.parquet', 'https://huggingface.co/datasets/mehdie/sefaria/raw/main/data/Apocrypha_english.parquet', 'https://huggingface.co/datasets/mehdie/sefaria/raw/main/data/Halakhah_english.parquet', 'https://huggingface.co/datasets/mehdie/sefaria/raw/main/data/Talmud_english.parquet', 'https://huggingface.co/datasets/mehdie/sefaria/raw/main/data/Mishnah_english.parquet', 'https://huggingface.co/datasets/mehdie/sefaria/raw/main/data/Tanaitic_english.parquet', 'https://huggingface.co/datasets/mehdie/sefaria/raw/main/data/Halakhah_Commentary_english.parquet', 'https://huggingface.co/datasets/mehdie/sefaria/raw/main/data/Philosophy_english.parquet', 'https://huggingface.co/datasets/mehdie/sefaria/raw/main/data/Tanakh_english.parquet', 'https://huggingface.co/datasets/mehdie/sefaria/raw/main/data/Halakhah_Tur_and_Commentaries_english.parquet', 'https://huggingface.co/datasets/mehdie/sefaria/raw/main/data/Halakhah_Mishneh_Torah_english.parquet', 'https://huggingface.co/datasets/mehdie/sefaria/raw/main/data/Modern_Works_english.parquet', 'https://huggingface.co/datasets/mehdie/sefaria/raw/main/data/Responsa_english.parquet', 'https://huggingface.co/datasets/mehdie/sefaria/raw/main/data/Halakhah_Shulchan_Arukh_english.parquet', 'https://huggingface.co/datasets/mehdie/sefaria/raw/main/data/Kabbalah_english.parquet', 'https://huggingface.co/datasets/mehdie/sefaria/raw/main/data/Musar_english.parquet', 'https://huggingface.co/datasets/mehdie/sefaria/raw/main/data/Other_english.parquet', 'https://huggingface.co/datasets/mehdie/sefaria/raw/main/data/Liturgy_english.parquet', 'https://huggingface.co/datasets/mehdie/sefaria/raw/main/data/Responsa_hebrew.parquet', 'https://huggingface.co/datasets/mehdie/sefaria/raw/main/data/Halakhah_Mishneh_Torah_hebrew.parquet', 'https://huggingface.co/datasets/mehdie/sefaria/raw/main/data/Kabbalah_hebrew.parquet', 'https://huggingface.co/datasets/mehdie/sefaria/raw/main/data/Halakhah_Commentary_hebrew.parquet', 'https://huggingface.co/datasets/mehdie/sefaria/raw/main/data/Liturgy_hebrew.parquet', 'https://huggingface.co/datasets/mehdie/sefaria/raw/main/data/Tanaitic_hebrew.parquet', 'https://huggingface.co/datasets/mehdie/sefaria/raw/main/data/Halakhah_Shulchan_Arukh_hebrew.parquet', 'https://huggingface.co/datasets/mehdie/sefaria/raw/main/data/Tanakh_hebrew.parquet', 'https://huggingface.co/datasets/mehdie/sefaria/raw/main/data/Mishnah_hebrew.parquet', 'https://huggingface.co/datasets/mehdie/sefaria/raw/main/data/Halakhah_hebrew.parquet', 'https://huggingface.co/datasets/mehdie/sefaria/raw/main/data/Other_hebrew.parquet', 'https://huggingface.co/datasets/mehdie/sefaria/raw/main/data/Halakhah_Tur_and_Commentaries_hebrew.parquet', 'https://huggingface.co/datasets/mehdie/sefaria/raw/main/data/Midrash_hebrew.parquet', 'https://huggingface.co/datasets/mehdie/sefaria/raw/main/data/Modern_Works_hebrew.parquet', 'https://huggingface.co/datasets/mehdie/sefaria/raw/main/data/Chasidut_hebrew.parquet', 'https://huggingface.co/datasets/mehdie/sefaria/raw/main/data/Musar_hebrew.parquet', 'https://huggingface.co/datasets/mehdie/sefaria/raw/main/data/Apocrypha_hebrew.parquet', 'https://huggingface.co/datasets/mehdie/sefaria/raw/main/data/Talmud_hebrew.parquet', 'https://huggingface.co/datasets/mehdie/sefaria/raw/main/data/Philosophy_hebrew.parquet'] |
|
} |
|
|
|
def _info(self): |
|
features = datasets.Features( |
|
{ |
|
"text": datasets.Value("string"), |
|
"meta": datasets.Value("string") |
|
} |
|
) |
|
return datasets.DatasetInfo( |
|
description=_DESCRIPTION, |
|
features=features, |
|
homepage=_HOMEPAGE, |
|
license=_LICENSE, |
|
citation=_CITATION, |
|
) |
|
|
|
def _split_generators(self, dl_manager): |
|
|
|
if self.config.name in ["english", "hebrew"]: |
|
data_dir = dl_manager.download(self.DATA_URLS[self.config.name]) |
|
print("datadir:") |
|
print(data_dir) |
|
print("found the following files in ") |
|
for f in os.listdir(data_dir): |
|
print(f) |
|
|
|
filepaths = glob.glob(os.path.join(data_dir, "*" + self.config.name + ".parquet")) |
|
else: |
|
data_dir = dl_manager.download(self.DATA_URLS["all"]) |
|
print("datadir:") |
|
print(data_dir) |
|
print("found the following files") |
|
for f in os.listdir(data_dir): |
|
print(f) |
|
filepaths = glob.glob(os.path.join(data_dir, "*.parquet")) |
|
|
|
|
|
|
|
print(f"Filepaths found: {filepaths}") |
|
|
|
return [ |
|
datasets.SplitGenerator( |
|
name=datasets.Split.TRAIN, |
|
gen_kwargs={ |
|
"filepaths": filepaths, |
|
}, |
|
), |
|
] |
|
|
|
def _generate_examples(self, filepaths): |
|
for filepath in filepaths: |
|
df = pd.read_parquet(filepath) |
|
print(f"Reading file: {filepath}, number of rows: {len(df)}") |
|
for idx, row in df.iterrows(): |
|
yield idx, { |
|
"text": row["text"], |
|
"meta": row["meta"], |
|
} |
|
|
|
|