Datasets:
Tasks:
Question Answering
Modalities:
Text
Formats:
parquet
Languages:
Icelandic
Size:
10K - 100K
License:
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") | |