File size: 10,490 Bytes
4590a93 06f5f78 4590a93 8cb60b0 4590a93 2173d81 7ccd97b 2173d81 4590a93 06f5f78 1492e33 3aceff6 8cb60b0 596a2a6 2173d81 4590a93 1492e33 3aceff6 8cb60b0 2173d81 06f5f78 2173d81 4590a93 596a2a6 d546583 4590a93 d546583 4590a93 1adebb3 4590a93 |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 |
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):
# Download and extract the dataset files
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)}") # Add this line to print the number of row
for idx, row in df.iterrows():
yield idx, {
"text": row["text"],
"meta": row["meta"],
}
|