File size: 1,834 Bytes
365d2bf
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
from datasets import Dataset, DatasetDict, load_dataset, concatenate_datasets
import pandas as pd
import os


def prepare_nqii(path, split="train"):
    ds = load_dataset(path)
    ds = ds[split]

    # to dataframe
    df = pd.DataFrame(ds)
    df = df.drop(columns=["title"])

    df["start"] = df["answers"].apply(lambda x: x["answer_start"])
    df["answers"] = df["answers"].apply(lambda x: x["text"])

    # change type
    ds = Dataset.from_pandas(df)

    return ds


def prepare_ruquad(path):
    df = pd.read_json(path)
    
    # filter
    df = df[df["type"] == "ANSWERED_WITH_SPAN"]

    # drop index
    df = df.reset_index(drop=True)

    df = df.rename(columns={"question_id":"id", "paragraph": "context", "span":"answers"})
    df = df.drop(columns=[  "type", "answer_id", "article_id", "end", "source", "answer"])

    df["start"] = df["start"].astype(int)

    df["answers"] = df["answers"].apply(lambda x: [x])
    df["start"] = df["start"].apply(lambda x: [x])

    ds = Dataset.from_pandas(df)

    return ds


def download_ruquad():
    os.system("curl --remote-name-all https://repository.clarin.is/repository/xmlui/bitstream/handle/20.500.12537/310{/RUQuAD1.zip}")
    os.system("unzip RUQuAD1.zip")



if __name__ == "__main__":
    nqii_train = prepare_nqii("vesteinn/icelandic-qa-NQiI", split="train")
    ruquad_train = prepare_ruquad("train.json")
    train = concatenate_datasets([nqii_train, ruquad_train])

    val = prepare_nqii("vesteinn/icelandic-qa-NQiI", split="validation")

    nqi_test = prepare_nqii("vesteinn/icelandic-qa-NQiI", split="test")
    ruquad_test = prepare_ruquad("test.json")
    test = concatenate_datasets([nqi_test, ruquad_test])

    dataset = DatasetDict({"train": train, "validation": val, "test": test})
    print(dataset)

    dataset.push_to_hub("Sigurdur/nqii_ruqad")