Datasets:
Tasks:
Question Answering
Modalities:
Text
Formats:
parquet
Languages:
Danish
Size:
< 1K
Tags:
conversational
Commit
·
23efc67
1
Parent(s):
83b2aca
Create create.py
Browse files
create.py
ADDED
|
@@ -0,0 +1,72 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
from datasets import Dataset, load_dataset
|
| 2 |
+
|
| 3 |
+
ds: Dataset = load_dataset("DDSC/partial-danish-gigaword-no-twitter") # type: ignore
|
| 4 |
+
ds = ds["train"]
|
| 5 |
+
# filter to only include spontaneous speech
|
| 6 |
+
ds = ds.filter(lambda x: x["source"] == "spont", num_proc=6)
|
| 7 |
+
|
| 8 |
+
|
| 9 |
+
|
| 10 |
+
texts = ds["text"]
|
| 11 |
+
|
| 12 |
+
|
| 13 |
+
def remove_taler(text):
|
| 14 |
+
if text.startswith("Taler"):
|
| 15 |
+
text = text.split(":")[1:]
|
| 16 |
+
text = ":".join(text)
|
| 17 |
+
return text.strip()
|
| 18 |
+
|
| 19 |
+
|
| 20 |
+
qa_pairs = []
|
| 21 |
+
for text in texts:
|
| 22 |
+
lines = text.split("\n")
|
| 23 |
+
lines = [remove_taler(line) for line in lines]
|
| 24 |
+
questions = [
|
| 25 |
+
(i, text)
|
| 26 |
+
for i, text in enumerate(lines)
|
| 27 |
+
if len(text.split(" ")) > 7 and text.endswith("?")
|
| 28 |
+
]
|
| 29 |
+
|
| 30 |
+
qa_pairs_ = [{"question": lines[i], "answer": lines[i + 1]} for i, _ in questions]
|
| 31 |
+
qa_pairs += qa_pairs_
|
| 32 |
+
|
| 33 |
+
|
| 34 |
+
# filter qa pairs
|
| 35 |
+
def get_length_of_pair(qa: dict):
|
| 36 |
+
return len(qa["question"].split(" ")) + len(qa["answer"].split(" "))
|
| 37 |
+
|
| 38 |
+
|
| 39 |
+
def get_min_length_of_pair(qa: dict):
|
| 40 |
+
return min(len(qa["question"].split(" ")), len(qa["answer"].split(" ")))
|
| 41 |
+
|
| 42 |
+
|
| 43 |
+
qa_pairs = [
|
| 44 |
+
qa
|
| 45 |
+
for qa in qa_pairs
|
| 46 |
+
if get_length_of_pair(qa) < 20 and get_min_length_of_pair(qa) > 4
|
| 47 |
+
]
|
| 48 |
+
|
| 49 |
+
|
| 50 |
+
# create dataset
|
| 51 |
+
qa_ds = Dataset.from_list(qa_pairs)
|
| 52 |
+
|
| 53 |
+
# add readme
|
| 54 |
+
qa_ds.info.description = """# Spontanous speech QA
|
| 55 |
+
|
| 56 |
+
This dataset contains QA pairs from the spontaneous speech subsection of the Danish Gigaword.
|
| 57 |
+
The dataset is created from the [DDSC dataset](DDSC/partial-danish-gigaword-no-twitter) and
|
| 58 |
+
filtered to only include QA pairs where the question is less than 20 tokens and the answer is
|
| 59 |
+
at least 4 tokens long.
|
| 60 |
+
|
| 61 |
+
To find out more about the creation see the accompanying script.
|
| 62 |
+
"""
|
| 63 |
+
|
| 64 |
+
qa_ds.info.license = ds[0]["LICENSE"]
|
| 65 |
+
qa_ds.info.dataset_name = "Spontanous Speech QA"
|
| 66 |
+
|
| 67 |
+
|
| 68 |
+
# split dataset
|
| 69 |
+
qa_ds = qa_ds.train_test_split(test_size=0.2)
|
| 70 |
+
|
| 71 |
+
# upload dataset
|
| 72 |
+
qa_ds.push_to_hub("spontanous-speech-qa")
|