File size: 4,014 Bytes
15a35eb 8b6694e 15a35eb 8b6694e 15a35eb 8b6694e 15a35eb 8b6694e 15a35eb 8b6694e 15a35eb 8b6694e 15a35eb 8b6694e 15a35eb 8b6694e 15a35eb 8b6694e 15a35eb |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 |
import json
import pandas as pd
from typing import List
import datasets
_DESCRIPTION = """
RuSpellGold is a benchmark of 1711 sentence pairs
dedicated to a problem of automatic spelling correction in Russian language.
The dataset is gathered from five different domains including news, Russian classic literature,
social media texts, open web and strategic documents.
It has been passed through two-stage manual labeling process with native speakers as annotators
to correct spelling violation and preserve original style of text at the same time.
"""
_LICENSE = "apache-2.0"
class RuSpellGoldConfig(datasets.BuilderConfig):
"""BuilderConfig for RuSpellGold."""
def __init__(self, data_urls, features, **kwargs):
"""BuilderConfig for RuSpellGold.
Args:
features: *list[string]*, list of the features that will appear in the
feature dict. Should not include "label".
data_urls: *dict[string]*, urls to download the zip file from.
**kwargs: keyword arguments forwarded to super.
"""
super(RuSpellGoldConfig, self).__init__(version=datasets.Version("0.0.1"), **kwargs)
self.data_urls = data_urls
self.features = features
class RuSpellGold(datasets.GeneratorBasedBuilder):
"""RuFacts dataset."""
BUILDER_CONFIGS = [
RuSpellGoldConfig(
name="aranea",
data_urls={
"test": "data/aranea/split.json",
},
features=["source", "correction", "domain"],
),
RuSpellGoldConfig(
name="literature",
data_urls={
"test": "data/literature/split.json",
},
features=["source", "correction", "domain"],
),
RuSpellGoldConfig(
name="news",
data_urls={
"test": "data/news/split.json",
},
features=["source", "correction", "domain"],
),
RuSpellGoldConfig(
name="social_media",
data_urls={
"test": "data/social_media/split.json",
},
features=["source", "correction", "domain"],
),
RuSpellGoldConfig(
name="strategic_documents",
data_urls={
"test": "data/strategic_documents/split.json",
},
features=["source", "correction", "domain"],
),
RuSpellGoldConfig(
name="complete_test",
data_urls={
"test": "data/complete_test/test.json",
},
features=["source", "correction", "domain"],
),
]
def _info(self) -> datasets.DatasetInfo:
features = {
"source": datasets.Value("string"),
"correction": datasets.Value("string"),
"domain": datasets.Value("string"),
}
return datasets.DatasetInfo(
features=datasets.Features(features),
description=_DESCRIPTION,
license=_LICENSE,
)
def _split_generators(
self, dl_manager: datasets.DownloadManager
) -> List[datasets.SplitGenerator]:
urls_to_download = self.config.data_urls
downloaded_files = dl_manager.download_and_extract(urls_to_download)
return [
datasets.SplitGenerator(
name=datasets.Split.TEST,
gen_kwargs={
"data_file": downloaded_files["test"],
"split": datasets.Split.TEST,
},
)
]
def _generate_examples(self, data_file, split):
with open(data_file, encoding="utf-8") as f:
key = 0
for line in f:
row = json.loads(line)
example = {feature: row[feature] for feature in self.config.features}
yield key, example
key += 1
|