Download scripts/push_dataset_to_hf.py from chcaa/dacy-data: direct link, hf CLI and curl.
- Browser
- Download file 1.06 kB
-
https://huggingface.co/datasets/chcaa/dacy-data/resolve/main/scripts/push_dataset_to_hf.py
- Command line
-
hf download hf://datasets/chcaa/dacy-data/scripts/push_dataset_to_hf.py
-
curl -L -o push_dataset_to_hf.py https://huggingface.co/datasets/chcaa/dacy-data/resolve/main/scripts/push_dataset_to_hf.py
1.06 kB
| from datasets import Dataset, DatasetDict | |
| import spacy | |
| from spacy.tokens import DocBin | |
| from pathlib import Path | |
| nlp = spacy.blank("da") | |
| corpus_path = Path("corpus/cdt_ddt") | |
| def docbin_to_rows(path): | |
| doc_bin = DocBin().from_disk(path) | |
| rows = [] | |
| for doc in doc_bin.get_docs(nlp.vocab): | |
| row = doc.to_json() | |
| row.pop("spans", None) # dropped the key variable dictionaries to replace with a list representing the clusters | |
| row["coref_clusters"] = [ | |
| [{"start": span.start_char, "end": span.end_char, "label": span.label_} | |
| for span in doc.spans[key]] | |
| for key in sorted(doc.spans.keys()) | |
| if key.startswith("coref_clusters_") | |
| ] | |
| rows.append(row) | |
| return rows | |
| dataset = DatasetDict({ | |
| "train": Dataset.from_list(docbin_to_rows(corpus_path/"train.spacy")), | |
| "dev": Dataset.from_list(docbin_to_rows(corpus_path/"dev.spacy")), | |
| "test": Dataset.from_list(docbin_to_rows(corpus_path/"test.spacy")), | |
| }) | |
| dataset.push_to_hub("johanamayer/cdt_ddt_union") |