mc4_3.1.0_fi_cleaned / calculate_kenlm_perplexity.py
aapot
Add dataset creation scripts
248c176
import datasets
import kenlm
kenlm_model = kenlm.Model("kenlm_5gram_fi.bin")
def get_perplexity(example):
"""Get perplexity of text field."""
example["perplexity_kenlm"] = int(kenlm_model.perplexity(example["text"]))
return example
dataset = datasets.load_from_disk("/researchdisk/mc4_3.1.0_fi_cleaned")
# TRAIN SPLIT PERPLEXITY
dataset["train"] = dataset["train"].map(
get_perplexity, num_proc=64
)
# VALIDATION SPLIT PERPLEXITY
dataset["validation"] = dataset["validation"].map(
get_perplexity, num_proc=64
)
# SAVE DATASET
dataset.save_to_disk("/researchdisk/mc4_3.1.0_fi_cleaned", num_proc=32)