Update common-corpus.py
Browse files4 unmodified lines567891011121314151617181 unmodified line202122232425262728293031323334353637383940414243444 unmodified linesclass CommonCorpus(GeneratorBasedBuilder):VERSION = datasets.Version("1.0.0")BUILDER_CONFIGS = [datasets.BuilderConfig(name="bytelevel", version=VERSION, description="Bytelevel corpus data"),]def _info(self):return DatasetInfo(description="Common Corpus from InfoTokenizers - bytelevel config",features=Features({"text": Value("string"),}),supervised_keys=None,homepage="https://huggingface.co/datasets/InfoTokenizers/common-corpus",1 unmodified line)def _split_generators(self, dl_manager):# Use the local extracted path to dataset filesdata_dir = os.path.join(dl_manager.manual_dir, "bytelevel")return [SplitGenerator(name=Split.TRAIN,gen_kwargs={"data_dir": data_dir},),]def _generate_examples(self, data_dir):# Iterate over all .txt files inside bytelevel folderfile_paths = [os.path.join(data_dir, f) for f in os.listdir(data_dir) if f.endswith(".txt")]example_id = 0for file_path in file_paths:with open(file_path, encoding="utf-8") as f:for line in f:text = line.strip()if text:yield example_id, {"text": text}example_id += 14 unmodified lines56789101112131415161718191 unmodified line212223242526272829303132333435363738394041424344454647484950515253545556575859606162634 unmodified linesclass CommonCorpus(GeneratorBasedBuilder):VERSION = datasets.Version("1.0.0")BUILDER_CONFIGS = [datasets.BuilderConfig(name="default", version=VERSION, description="Common Corpus dataset"),]def _info(self):return DatasetInfo(description="Common Corpus from InfoTokenizers with multiple subfolders",features=Features({"text": Value("string"),"source": Value("string"),}),supervised_keys=None,homepage="https://huggingface.co/datasets/InfoTokenizers/common-corpus",1 unmodified line)def _split_generators(self, dl_manager):# Downloaded and extracted folder pathdata_dir = dl_manager.download_and_extract("https://huggingface.co/datasets/InfoTokenizers/common-corpus/resolve/main/")# List all subdirectoriessubdirs = ["bytelevel", "bytelevel-llm-data", "bytelevel-subset", "bytelevel-subset_1", "bytelevel-subset_2"]# Check existence of each subdirvalid_dirs = [os.path.join(data_dir, subdir) for subdir in subdirs if os.path.exists(os.path.join(data_dir, subdir))]if not valid_dirs:raise FileNotFoundError(f"No valid data directories found in {data_dir}. Expected one of: {subdirs}")return [SplitGenerator(name=Split.TRAIN,gen_kwargs={"data_dirs": valid_dirs},),]def _generate_examples(self, data_dirs):example_id = 0for data_dir in data_dirs:subdir_name = os.path.basename(data_dir)# Iterate over all .txt files in the directoryfor root, _, files in os.walk(data_dir):for filename in files:if filename.endswith(".txt"):file_path = os.path.join(root, filename)with open(file_path, encoding="utf-8") as f:for line in f:text = line.strip()if text:yield example_id, {"text": text,"source": subdir_name,}example_id += 1
common-corpus.py+35-16