|
import datasets |
|
from datasets.tasks import LanguageModeling |
|
|
|
|
|
|
|
|
|
|
|
_DATA_URL = "https://huggingface.co/datasets/anhaltai/fincorpus-de-10k/resolve/main/data/corpus_safe_txt_only.zip" |
|
|
|
ALL_COLLECTIONS_NAME = "all" |
|
|
|
|
|
CONFIG_NAMES = { |
|
"Annual_reports", |
|
"BBK_monthly", |
|
"Base_prospectuses", |
|
"Final_terms", |
|
|
|
|
|
"Law", |
|
ALL_COLLECTIONS_NAME |
|
} |
|
|
|
|
|
|
|
_DESCRIPTION = """\ |
|
We introduce a predominantly German corpus comprising 12.5k PDF documents (and 10.5k extracted txt files) sourced from the financial domain. The corresponding extracted textual data encompasses more than 165 million tokens derived predominantly from German, and to a lesser extent, bilingual documents. |
|
We provide detailed information about the document types included in the corpus, such as final terms, base prospectuses, annual reports, information materials, law documents, international financial reporting standards, and monthly reports from the Bundesbank, accompanied by comprehensive statistical analysis. |
|
This version of the dataset excludes two collections, IFRS and Informational_materials, leaving only datasets definitely releasable with an open license. |
|
""" |
|
|
|
|
|
_CITATION = """ """ |
|
|
|
|
|
class FincorpusConfig(datasets.BuilderConfig): |
|
def __init__(self, generate_sentences=False, **kwargs): |
|
super(FincorpusConfig, self).__init__( |
|
version=datasets.Version("1.0.0"), **kwargs |
|
) |
|
|
|
|
|
class Fincorpus(datasets.GeneratorBasedBuilder): |
|
|
|
|
|
BUILDER_CONFIGS = [ |
|
FincorpusConfig(name=config_name) for config_name in CONFIG_NAMES |
|
] |
|
DEFAULT_CONFIG_NAME = ALL_COLLECTIONS_NAME |
|
|
|
def _info(self): |
|
return datasets.DatasetInfo( |
|
description=_DESCRIPTION, |
|
features=datasets.Features( |
|
{ |
|
"filename": datasets.Value("string"), |
|
"text": datasets.Value("string"), |
|
} |
|
), |
|
supervised_keys=None, |
|
|
|
task_templates=[LanguageModeling(text_column="text")], |
|
) |
|
|
|
def _split_generators(self, dl_manager): |
|
|
|
config_url = _DATA_URL |
|
arch_path = dl_manager.download(config_url) |
|
|
|
|
|
|
|
return [ |
|
datasets.SplitGenerator( |
|
name=datasets.Split.TRAIN, |
|
gen_kwargs={"files": dl_manager.iter_archive(arch_path)}, |
|
), |
|
] |
|
|
|
def _path_belongs_to_collection(self, path: str): |
|
subfolder_name = self.config.name |
|
if subfolder_name == ALL_COLLECTIONS_NAME: |
|
return True |
|
|
|
if path.startswith("txt/" + subfolder_name): |
|
return True |
|
return False |
|
|
|
def _generate_examples(self, files): |
|
_id = 0 |
|
for path, f in files: |
|
if not self._path_belongs_to_collection(path): |
|
continue |
|
text = f.read().decode("utf-8").strip() |
|
yield _id, {"text": text, "filename": path} |
|
_id += 1 |
|
|