mirror of
https://github.com/wassname/Castor.git
synced 2026-09-05 16:20:33 +08:00
30 lines
938 B
Python
30 lines
938 B
Python
import re
|
|
|
|
|
|
def clean_str(string):
|
|
"""
|
|
Tokenization/string cleaning for all datasets except for SST.
|
|
"""
|
|
string = re.sub(r"[^A-Za-z0-9(),!?\'\`]", " ", string)
|
|
string = re.sub(r"\'s", " \'s", string)
|
|
string = re.sub(r"\'ve", " \'ve", string)
|
|
string = re.sub(r"n\'t", " n\'t", string)
|
|
string = re.sub(r"\'re", " \'re", string)
|
|
string = re.sub(r"\'d", " \'d", string)
|
|
string = re.sub(r"\'ll", " \'ll", string)
|
|
string = re.sub(r",", " , ", string)
|
|
string = re.sub(r"!", " ! ", string)
|
|
string = re.sub(r"\(", " ( ", string)
|
|
string = re.sub(r"\)", " ) ", string)
|
|
string = re.sub(r"\?", " ? ", string)
|
|
string = re.sub(r"\s{2,}", " ", string)
|
|
return string.lower().strip().split()
|
|
|
|
|
|
def clean_str_sst(string):
|
|
"""
|
|
Tokenization/string cleaning for the SST dataset
|
|
"""
|
|
string = re.sub(r"[^A-Za-z0-9(),!?\'\`]", " ", string)
|
|
string = re.sub(r"\s{2,}", " ", string)
|
|
return string.lower().strip().split() |