add duconv dataset
Browse files
duconv.py
ADDED
|
@@ -0,0 +1,131 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# Copyright (c) 2022 PaddlePaddle Authors. All Rights Reserved.
|
| 2 |
+
#
|
| 3 |
+
# Licensed under the Apache License, Version 2.0 (the "License");
|
| 4 |
+
# you may not use this file except in compliance with the License.
|
| 5 |
+
# You may obtain a copy of the License at
|
| 6 |
+
#
|
| 7 |
+
# http://www.apache.org/licenses/LICENSE-2.0
|
| 8 |
+
#
|
| 9 |
+
# Unless required by applicable law or agreed to in writing, software
|
| 10 |
+
# distributed under the License is distributed on an "AS IS" BASIS,
|
| 11 |
+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
| 12 |
+
# See the License for the specific language governing permissions and
|
| 13 |
+
# limitations under the License.
|
| 14 |
+
|
| 15 |
+
import json
|
| 16 |
+
import os
|
| 17 |
+
|
| 18 |
+
import datasets
|
| 19 |
+
from datasets.tasks import QuestionAnsweringExtractive
|
| 20 |
+
|
| 21 |
+
logger = datasets.logging.get_logger(__name__)
|
| 22 |
+
|
| 23 |
+
_DESCRIPTION = """\
|
| 24 |
+
Duconv is a chinese convolution \
|
| 25 |
+
dataset, designed to evaluate the dialogue models.
|
| 26 |
+
"""
|
| 27 |
+
|
| 28 |
+
_URL = "https://bj.bcebos.com/paddlenlp/datasets/DuConv.zip"
|
| 29 |
+
|
| 30 |
+
|
| 31 |
+
class DuconvConfig(datasets.BuilderConfig):
|
| 32 |
+
"""BuilderConfig for Duconv."""
|
| 33 |
+
|
| 34 |
+
def __init__(self, **kwargs):
|
| 35 |
+
"""BuilderConfig for Duconv.
|
| 36 |
+
|
| 37 |
+
Args:
|
| 38 |
+
**kwargs: keyword arguments forwarded to super.
|
| 39 |
+
"""
|
| 40 |
+
super(DuconvConfig, self).__init__(**kwargs)
|
| 41 |
+
|
| 42 |
+
|
| 43 |
+
class Duconv(datasets.GeneratorBasedBuilder):
|
| 44 |
+
BUILDER_CONFIGS = [
|
| 45 |
+
DuconvConfig(
|
| 46 |
+
name="DuConv",
|
| 47 |
+
version=datasets.Version("1.0.0", ""),
|
| 48 |
+
description=_DESCRIPTION,
|
| 49 |
+
),
|
| 50 |
+
]
|
| 51 |
+
|
| 52 |
+
def _info(self):
|
| 53 |
+
return datasets.DatasetInfo(
|
| 54 |
+
description=_DESCRIPTION,
|
| 55 |
+
features=datasets.Features({
|
| 56 |
+
"id":
|
| 57 |
+
datasets.Value("string"),
|
| 58 |
+
"goal":
|
| 59 |
+
datasets.Sequence(datasets.Sequence(datasets.Value("string"))),
|
| 60 |
+
"knowledge":
|
| 61 |
+
datasets.Sequence(datasets.Sequence(datasets.Value("string"))),
|
| 62 |
+
"conversation":
|
| 63 |
+
datasets.Sequence(datasets.Value("string")),
|
| 64 |
+
"history":
|
| 65 |
+
datasets.Sequence(datasets.Value("string")),
|
| 66 |
+
"response":
|
| 67 |
+
datasets.Value("string"),
|
| 68 |
+
}),
|
| 69 |
+
# No default supervised_keys (as we have to pass both question
|
| 70 |
+
# and context as input).
|
| 71 |
+
supervised_keys=None,
|
| 72 |
+
homepage="https://arxiv.org/pdf/1906.05572.pdf",
|
| 73 |
+
)
|
| 74 |
+
|
| 75 |
+
def _split_generators(self, dl_manager):
|
| 76 |
+
dl_dir = dl_manager.download_and_extract(_URL)
|
| 77 |
+
|
| 78 |
+
return [
|
| 79 |
+
datasets.SplitGenerator(name="train",
|
| 80 |
+
gen_kwargs={
|
| 81 |
+
"filepath":
|
| 82 |
+
os.path.join(dl_dir, 'DuConv',
|
| 83 |
+
'train.txt'),
|
| 84 |
+
}),
|
| 85 |
+
datasets.SplitGenerator(name="dev",
|
| 86 |
+
gen_kwargs={
|
| 87 |
+
"filepath":
|
| 88 |
+
os.path.join(dl_dir, 'DuConv',
|
| 89 |
+
'dev.txt'),
|
| 90 |
+
}),
|
| 91 |
+
datasets.SplitGenerator(name="test_1",
|
| 92 |
+
gen_kwargs={
|
| 93 |
+
"filepath":
|
| 94 |
+
os.path.join(dl_dir, 'DuConv',
|
| 95 |
+
'test_1.txt'),
|
| 96 |
+
}),
|
| 97 |
+
datasets.SplitGenerator(name="test_2",
|
| 98 |
+
gen_kwargs={
|
| 99 |
+
"filepath":
|
| 100 |
+
os.path.join(dl_dir, 'DuConv',
|
| 101 |
+
'test_2.txt'),
|
| 102 |
+
}),
|
| 103 |
+
]
|
| 104 |
+
|
| 105 |
+
def _generate_examples(self, filepath):
|
| 106 |
+
"""This function returns the examples in the raw (text) form."""
|
| 107 |
+
logger.info("generating examples from = %s", filepath)
|
| 108 |
+
key = 0
|
| 109 |
+
with open(filepath, 'r', encoding="utf-8") as fin:
|
| 110 |
+
for line in fin:
|
| 111 |
+
duconv = json.loads(line)
|
| 112 |
+
|
| 113 |
+
goal = duconv["goal"] if "goal" in duconv.keys() else [[]]
|
| 114 |
+
knowledge = duconv["knowledge"] if "knowledge" in duconv.keys(
|
| 115 |
+
) else [[]]
|
| 116 |
+
conversation = duconv[
|
| 117 |
+
"conversation"] if "conversation" in duconv.keys() else []
|
| 118 |
+
history = duconv["history"] if "history" in duconv.keys(
|
| 119 |
+
) else []
|
| 120 |
+
response = duconv["response"] if "response" in duconv.keys(
|
| 121 |
+
) else ""
|
| 122 |
+
|
| 123 |
+
yield key, {
|
| 124 |
+
"id": str(key),
|
| 125 |
+
"goal": goal,
|
| 126 |
+
"knowledge": knowledge,
|
| 127 |
+
"conversation": conversation,
|
| 128 |
+
"history": history,
|
| 129 |
+
"response": response,
|
| 130 |
+
}
|
| 131 |
+
key += 1
|