File size: 626 Bytes
248c176 |
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 |
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)
|