miracl-japanese-small-corpus / create_miracl_japanese_small.py
Makoto P. Kato
Initial commit
e43df1f
raw
history blame
994 Bytes
import pandas as pd
import json
from tqdm import tqdm
from datasets import load_dataset
DEV_QREL_FILEPATH = "./qrels.miracl-v1.0-ja-dev.tsv"
OUTPUT_FILEPATH = "./miracl-japanese-small-docs.jsonl"
def extract_doc_ids(filepath):
dev_qrel = pd.read_csv(filepath, delimiter='\t',
names=['query_id', 'ph', 'doc_pas_id', 'rel'])
doc_ids = set([int(dp_id.split('#')[0]) for dp_id in dev_qrel.doc_pas_id])
return doc_ids
if __name__ == '__main__':
dev_doc_ids = extract_doc_ids(DEV_QREL_FILEPATH)
doc_ids = dev_doc_ids
print("# of docids in dev", len(dev_doc_ids))
new_dataset = []
seen_doc_ids = set()
dataset = load_dataset("miracl/miracl-corpus", "ja")
for data in tqdm(dataset['train']):
docid = int(data["docid"].split("#")[0])
if docid in doc_ids:
new_dataset.append(data)
with open(OUTPUT_FILEPATH, 'w', encoding='utf-8') as f:
for data in new_dataset:
f.write(json.dumps(data) + '\n')