Support streaming
#4
by albertvillanova HF Staff - opened
Files changed (2)
- data.zipAdded+3
- sofc_materials_articles.py+12-28
123version https://git-lfs.github.com/spec/v1oid sha256:5430c7563887db6067e75bcfbad99dfa83b02b38834dbf5cfd355919d84554ecsize 362796844 unmodified lines45464748495051180 unmodified lines2322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632641 unmodified line26626726826927027127227327427527627727827928028128228328428528621 unmodified lines30830931031131231331468 unmodified lines38338438538638738838944 unmodified lines_LICENSE = ""_URL = "https://github.com/boschresearch/sofc-exp_textmining_resources/archive/master.zip"class SOFCMaterialsArticles(datasets.GeneratorBasedBuilder):180 unmodified linesdef _split_generators(self, dl_manager):"""Returns SplitGenerators."""my_urls = _URLdata_dir = dl_manager.download_and_extract(my_urls)data_dir = os.path.join(data_dir, "sofc-exp_textmining_resources-master/sofc-exp-corpus")metadata = pd.read_csv(os.path.join(data_dir, "SOFC-Exp-Metadata.csv"), sep="\t")text_base_path = os.path.join(data_dir, "texts")text_files_available = [os.path.split(i.rstrip(".txt"))[-1] for i in glob.glob(os.path.join(text_base_path, "*.txt"))]metadata = metadata[metadata["name"].map(lambda x: x in text_files_available)]names = {}splits = ["train", "test", "dev"]for split in splits:names[split] = metadata[metadata["set"] == split]["name"].tolist()return [datasets.SplitGenerator(name=datasets.Split.TRAIN,# These kwargs will be passed to _generate_examplesgen_kwargs={"names": names["train"],"data_dir": data_dir,"split": "train",},1 unmodified linedatasets.SplitGenerator(name=datasets.Split.TEST,# These kwargs will be passed to _generate_examplesgen_kwargs={"names": names["test"], "data_dir": data_dir, "split": "test"},),datasets.SplitGenerator(name=datasets.Split.VALIDATION,# These kwargs will be passed to _generate_examplesgen_kwargs={"names": names["dev"],"data_dir": data_dir,"split": "validation",},),]def _generate_examples(self, names, data_dir, split):"""Yields examples."""# The dataset consists of the original article text as well as annotationstextfile_base_path = os.path.join(data_dir, "texts")annotations_base_path = os.path.join(data_dir, "annotations")21 unmodified lines# For each text file, we'll load all of the# associated annotation filesfor id_, name in enumerate(sorted(names)):# Load the main source texttextfile_path = os.path.join(textfile_base_path, name + ".txt")text = open(textfile_path, encoding="utf-8").read()68 unmodified lines# Iterate through the spans dataspans = []for span in spans_raw:# Split out the elements in each tab-delimited line_, span_id, entity_label_or_exp, sentence_id, begin_char_offset, end_char_offset = span.split("\t")44 unmodified lines45464748495051180 unmodified lines2322332342352362372382392402412422432442451 unmodified line24724824925025125225325425525625725825926026126226326426526626726826927027127221 unmodified lines29429529629729829968 unmodified lines36836937037137237344 unmodified lines_LICENSE = ""_URL = "data.zip"class SOFCMaterialsArticles(datasets.GeneratorBasedBuilder):180 unmodified linesdef _split_generators(self, dl_manager):"""Returns SplitGenerators."""data_dir = dl_manager.download_and_extract(_URL)data_dir = os.path.join(data_dir, "sofc-exp-corpus")return [datasets.SplitGenerator(name=datasets.Split.TRAIN,# These kwargs will be passed to _generate_examplesgen_kwargs={"data_dir": data_dir,"split": "train",},1 unmodified linedatasets.SplitGenerator(name=datasets.Split.TEST,# These kwargs will be passed to _generate_examplesgen_kwargs={"data_dir": data_dir,"split": "test",},),datasets.SplitGenerator(name=datasets.Split.VALIDATION,# These kwargs will be passed to _generate_examplesgen_kwargs={"data_dir": data_dir,"split": "dev",},),]def _generate_examples(self, data_dir, split):"""Yields examples."""metadata = pd.read_csv(os.path.join(data_dir, "SOFC-Exp-Metadata.csv"), sep="\t")names = metadata[metadata["set"] == split]["name"].tolist()# The dataset consists of the original article text as well as annotationstextfile_base_path = os.path.join(data_dir, "texts")annotations_base_path = os.path.join(data_dir, "annotations")21 unmodified lines# For each text file, we'll load all of the# associated annotation filesfor id_, name in enumerate(sorted(names)):# Load the main source texttextfile_path = os.path.join(textfile_base_path, name + ".txt")text = open(textfile_path, encoding="utf-8").read()68 unmodified lines# Iterate through the spans dataspans = []for span in spans_raw:# Split out the elements in each tab-delimited line_, span_id, entity_label_or_exp, sentence_id, begin_char_offset, end_char_offset = span.split("\t")
data.zipAdded+3
sofc_materials_articles.py+12-28