salinlahi / scripts /preprocess.py
krislette's picture
Sync from GitHub: bcc181ba0e1c11c139e53aa57e0fd9b6cfcf8f56
60d3f8f
Raw History Blame Contribute Delete
735 Bytes
"""
Rules that we have set for preprocessing Tagalog and Waray:
[1] Remove from dataset:
. (period)
, (comma)
! (exclamation)
? (question)
; (semicolon)
: (colon)
" (double quote)
– (en dash)
β€” (em dash)
( ) [ ] { } (paranthesis, brackets, curly braces)
[2] Keep on the dataset:
' (single quote)
’ (apostrophe)
- (hyphen)
"""
import re
def preprocess_text(text: str) -> str:
"""
Preprocess text to match training data rules.
Remove: . , ! ? ; : " – β€” ( ) [ ] { }
Keep: ' (apostrophe) - (hyphen)
"""
# Characters to remove
chars_to_remove = r"[\.\,\!\?\;\:\"\–\β€”\(\)\[\]\{\}]"
# Remove the specified characters
text = re.sub(chars_to_remove, "", text)
return text.strip()