Upload 2 files
Browse files
KB.py
ADDED
|
@@ -0,0 +1,103 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import json
|
| 2 |
+
import math
|
| 3 |
+
from typing import List
|
| 4 |
+
|
| 5 |
+
import datasets
|
| 6 |
+
|
| 7 |
+
|
| 8 |
+
logger = datasets.logging.get_logger(__name__)
|
| 9 |
+
|
| 10 |
+
|
| 11 |
+
_CITATION = ''
|
| 12 |
+
|
| 13 |
+
_DESCRIPTION = """\
|
| 14 |
+
Выдержки из руководства пользователя для генерации ответов по запросу пользователя.\
|
| 15 |
+
"""
|
| 16 |
+
_LICENSE = ''
|
| 17 |
+
|
| 18 |
+
_URL = "https://huggingface.co/datasets/SIA86/KB/blob/main/"
|
| 19 |
+
_URLS = {
|
| 20 |
+
"train": _URL + "kb.json",
|
| 21 |
+
}
|
| 22 |
+
|
| 23 |
+
class LFQAKBConfig(datasets.BuilderConfig):
|
| 24 |
+
"""BuilderConfig for LFQAKnowledgeBase"""
|
| 25 |
+
|
| 26 |
+
def __init__(
|
| 27 |
+
self, language="ru", snippets_length=50, snippets_overlap=25, **kwargs
|
| 28 |
+
):
|
| 29 |
+
"""BuilderConfig for WikiSnippets.
|
| 30 |
+
Args:
|
| 31 |
+
**kwargs: keyword arguments forwarded to super.
|
| 32 |
+
"""
|
| 33 |
+
super(LFQAKBConfig, self).__init__(**kwargs)
|
| 34 |
+
self.language = language
|
| 35 |
+
self.snippets_length = snippets_length
|
| 36 |
+
self.snippets_overlap = snippets_overlap
|
| 37 |
+
|
| 38 |
+
|
| 39 |
+
class WikiSnippets(datasets.GeneratorBasedBuilder):
|
| 40 |
+
|
| 41 |
+
BUILDER_CONFIGS = LFQAKBConfig(
|
| 42 |
+
name="LFQAKnowledgeBase",
|
| 43 |
+
version=datasets.Version("1.0.0"),
|
| 44 |
+
language="en",
|
| 45 |
+
snippets_length=50,
|
| 46 |
+
snippets_overlap=25,
|
| 47 |
+
)
|
| 48 |
+
|
| 49 |
+
test_dummy_data = False
|
| 50 |
+
|
| 51 |
+
def _info(self):
|
| 52 |
+
return datasets.DatasetInfo(
|
| 53 |
+
description=_DESCRIPTION,
|
| 54 |
+
features=datasets.Features(
|
| 55 |
+
{
|
| 56 |
+
"id": datasets.Value("int32g"),
|
| 57 |
+
"title": datasets.Value("string"),
|
| 58 |
+
"heading1": datasets.Value("string"),
|
| 59 |
+
"heading2": datasets.Value("string"),
|
| 60 |
+
"heading3": datasets.Value("string"),
|
| 61 |
+
"heading4": datasets.Value("string"),
|
| 62 |
+
"heading5": datasets.Value("string"),
|
| 63 |
+
"text": datasets.Value("string"),
|
| 64 |
+
|
| 65 |
+
}
|
| 66 |
+
),
|
| 67 |
+
supervised_keys=None,
|
| 68 |
+
citation=_CITATION,
|
| 69 |
+
)
|
| 70 |
+
|
| 71 |
+
def _split_generators(self, dl_manager: datasets.DownloadManager) -> List[datasets.SplitGenerator]:
|
| 72 |
+
urls_to_download = self._URLS
|
| 73 |
+
downloaded_files = dl_manager.download_and_extract(urls_to_download)
|
| 74 |
+
|
| 75 |
+
return [
|
| 76 |
+
datasets.SplitGenerator(name=datasets.Split.TRAIN, gen_kwargs={"filepath": downloaded_files}),
|
| 77 |
+
]
|
| 78 |
+
|
| 79 |
+
def _generate_examples(self, filepath):
|
| 80 |
+
"""This function returns the examples in the raw (text) form."""
|
| 81 |
+
logger.info("generating examples from = %s", filepath)
|
| 82 |
+
with open(filepath) as f:
|
| 83 |
+
lfqa = json.load(f)
|
| 84 |
+
for article in lfqa:
|
| 85 |
+
id_ = article['id']
|
| 86 |
+
title = article['title']
|
| 87 |
+
heading1 = article['heading1']
|
| 88 |
+
heading2 = article['heading2']
|
| 89 |
+
heading3 = article['heading3']
|
| 90 |
+
heading4 = article['heading4']
|
| 91 |
+
heading5 = article['heading5']
|
| 92 |
+
text = article['text']
|
| 93 |
+
# Features currently used are "context", "question", and "answers".
|
| 94 |
+
# Others are extracted here for the ease of future expansions.
|
| 95 |
+
yield id_, {
|
| 96 |
+
"title": title,
|
| 97 |
+
"heading1": heading1,
|
| 98 |
+
"heading2": heading2,
|
| 99 |
+
"heading3": heading3,
|
| 100 |
+
"heading4": heading4,
|
| 101 |
+
"heading5": heading5,
|
| 102 |
+
"text": text
|
| 103 |
+
}
|
kb.json
ADDED
|
The diff for this file is too large to render.
See raw diff
|
|
|