sin2piusc commited on
Commit
4c1d0c4
1 Parent(s): 344e574

Create norm.py

Browse files
Files changed (1) hide show
  1. norm.py +17 -0
norm.py ADDED
@@ -0,0 +1,17 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import neologdn
2
+ import MeCab
3
+ import re
4
+ from transformers.models.whisper.english_normalizer import BasicTextNormalizer
5
+
6
+ wakati = MeCab.Tagger("-Owakati")
7
+ special_characters = '[\,\、\。\.\「\」\…\?\・\!\-\;\:\"\“\%\‘\”\�]'
8
+
9
+
10
+ def norm_everything(batch):
11
+ batch["sentence"] = neologdn.normalize(batch["sentence"]).strip()
12
+ batch["sentence"] = normalizer(batch["sentence"]).strip()
13
+ batch["sentence"] = wakati.parse(batch["sentence"]).strip()
14
+ batch["sentence"] = re.sub(special_characters,'', batch["sentence"]).strip()
15
+ return batch
16
+
17
+ ds = ds.map(norm_everything)