jgca_v2_50k_2 / norm.py
sin2piusc's picture
Create norm.py
4c1d0c4 verified
raw
history blame contribute delete
No virus
600 Bytes
import neologdn
import MeCab
import re
from transformers.models.whisper.english_normalizer import BasicTextNormalizer
wakati = MeCab.Tagger("-Owakati")
special_characters = '[\,\、\。\.\γ€Œ\」\…\?\・\!\-\;\:\"\β€œ\%\β€˜\”\οΏ½]'
def norm_everything(batch):
batch["sentence"] = neologdn.normalize(batch["sentence"]).strip()
batch["sentence"] = normalizer(batch["sentence"]).strip()
batch["sentence"] = wakati.parse(batch["sentence"]).strip()
batch["sentence"] = re.sub(special_characters,'', batch["sentence"]).strip()
return batch
ds = ds.map(norm_everything)