| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| """Python build script for the ScandiWiki dataset.""" |
|
|
|
|
| import json |
| from pathlib import Path |
| from typing import List |
|
|
| from datasets import Version |
| from datasets.builder import BuilderConfig, GeneratorBasedBuilder |
| from datasets.download import DownloadManager |
| from datasets.features import Features, Value |
| from datasets.info import DatasetInfo |
| from datasets.splits import SplitGenerator |
|
|
| _DESCRIPTION = """ |
| ScandiWiki is a parsed and deduplicated version of the Danish, Norwegian Bokmål, |
| Norwegian Nynorsk, Swedish, Icelandic and Faroese Wikipedia corpora, as of January |
| 2023. |
| """ |
|
|
| _LICENSE = "CC BY-SA 4.0" |
| _BASE_URL = ( |
| "https://huggingface.co/datasets/alexandrainst/scandi-wiki/resolve/main/data" |
| ) |
|
|
| |
| |
| |
| |
| |
| |
| |
|
|
|
|
| class ScandiWiki(GeneratorBasedBuilder): |
| """Scandinavian part of Wikipedia.""" |
|
|
| VERSION = Version("1.0.1") |
|
|
| BUILDER_CONFIGS = [ |
| BuilderConfig( |
| name="da", |
| version=VERSION, |
| description="The deduplicated Danish part of Wikipedia.", |
| ), |
| BuilderConfig( |
| name="sv", |
| version=VERSION, |
| description="The deduplicated Swedish part of Wikipedia.", |
| ), |
| BuilderConfig( |
| name="nb", |
| version=VERSION, |
| description="The deduplicated Norwegian Bokmål part of Wikipedia.", |
| ), |
| BuilderConfig( |
| name="nn", |
| version=VERSION, |
| description="The deduplicated Norwegian Nynorsk part of Wikipedia.", |
| ), |
| BuilderConfig( |
| name="is", |
| version=VERSION, |
| description="The deduplicated Icelandic part of Wikipedia.", |
| ), |
| BuilderConfig( |
| name="fo", |
| version=VERSION, |
| description="The deduplicated Faroese part of Wikipedia.", |
| ), |
| ] |
|
|
| def _info(self) -> DatasetInfo: |
| features = Features( |
| { |
| "id": Value("string"), |
| "url": Value("string"), |
| "title": Value("string"), |
| "text": Value("string"), |
| } |
| ) |
| return DatasetInfo( |
| description=_DESCRIPTION, |
| features=features, |
| license=_LICENSE, |
| |
| |
| ) |
|
|
| def _split_generators(self, dl_manager: DownloadManager) -> List[SplitGenerator]: |
| url = f"{_BASE_URL}/{self.config.name}.jsonl" |
| downloaded_file = dl_manager.download_and_extract(url) |
| return [ |
| SplitGenerator( |
| name="train", |
| gen_kwargs=dict(filepath=downloaded_file), |
| ), |
| ] |
|
|
| def _generate_examples(self, filepath: str): |
| with Path(filepath).open(encoding="utf-8") as f: |
| for key, row in enumerate(f): |
| data = json.loads(row) |
| yield key, data |
|
|